Trouble tuning rate and attitude loops

I would need to understand why you had the roll over but generally I wouldn’t say that you would lower this parameter to protect against roll over. Now I think I see why you had large VFF values. Due to the ATC_ACCEL_MAX being so low, you tried to compenstate with large VFF. The ATC_ACCEL_MAX and ATC_INPUT_TC should be set so as to fit the aircraft response you like to see. You can even use the ATC_RATE_MAX parameters as well to provide the feel you like. So these parameters provide the desired response that you see in the log. The PID and VFF parameters are used to make the aircraft actual response match the desired.

So the notch should not be made too wide. only use it to cover one harmonic. You might get some unexpected oscillations. I chose the 2/rev because it was showing through even with the low pass filter down to 6hz. I would leave the notch at the 2/rev and lower the low pass filter down to 6 hz again since the 1/rev is showing through in the response. it isn’t terrible but you can see it in the roll axis.

I don’t know but I do know that it affects the I term and causes problems with the tune of the helicopter. So please keep it disabled.

Not particularly. We can look at yaw as well. why did you lower ATC_ANG_Y_P to 2? I guess I would recommend putting it back to 4.5 and lower your ATC_RAT_YAW_P to 0.2. then raise ATC_RAT_YAW_P until you see oscillations and then cut the gain in half. We can look at the response after that.

Now about your current data you provided. I want you to increase your VFF for both pitch and roll axes. You want to look at your PIDP and PIDR messages and for each axis look at the FF and P signals. PIDP is the pitch axis and PIDR is the roll axis. During the input you want to see the P signal go initially in the direction of the FF signal but then reverse and go in the opposite direction just as the FF peaks. As shown below.

Thanks for your quick response @bnsgeyer!

I’m looking at these logs of mine and it seems like I don’t get the P signal to reverse as FF peaks. Assuming I’m looking for this in both stabilize and acro modes?

Not sure I understand why we’re doing this. Shouldn’t we try to minimize the feed-forward and increase our P/D gains for roll and pitch? How do these fit in, relative to the VFF parameters in the optimization - perhaps this incremental shift is a first step before we optimize P/D gains?

You can see below that mine doesn’t look like this at all (most recent settings you had proposed):

And then my original settings, where VFF was much higher:

Separately, you mentioned ATC_INPUT_TC and the ATC_ACCEL_MAX parameters originally being too low. Do you think it’s worth raising them further or revisit after we fix the VFF ones? Would be helpful to understand the sequence.

Lastly, your comment on the filters makes a lot of sense. Should I try reducing from 10Hz to 8Hz or directly jumping down to 6Hz? Won’t this add latency?

Thanks so much for your help!

Yes you can look for this with the aircraft in.either flight mode. In either mode, the rate controller is trying to match the actual to the desired rate response. The flight mode dictates how the desired response behaves (attitude command or rate command).

Unfortunately we are not able to tune heli’s the way it is typically done with most PID controllers. The rotor is not well damped for our RC helicopters and you encounter feedback instabilities before you can get enough P gain to get adequate control. So VFF (feedforward) is used to try and match the requested rate as close as possible and then the PID controller is used to match it exactly. So it helps with gust rejection. If you are familiar with control architectures, it is like a model following architecture.

Yes we want to get the VFF gain set properly before further optimizing the P and D gains. So after you get the VFF set then you can optimize the P and D gains. However you were using 25% reduction in gain once you saw the feedback instability. I would suggest you go 50%. Unless you reduce 25% and check your response to ensure you don’t have the instability anymore. We can’t have it still lingering around.

Again you want to set the ACCEL_MAX for pilot preference for aircraft response. 40000 still seems a little low. Plus we want to tune for a little higher desired response even though it may feel fast to the pilot. Once it is tuned, we can alway slow the desired response for pilot preference and still leave the PIDs alone.
I have changed the tuning process slightly from what is in the heli tuning guide. Haven’t had a chance to revisit that.

Up to you. I agree that filters will add latency but I have found that it doesn’t start impact the pilot handling until you get below 5Hz. So you can reduce to 8 and see how it does. The 1/rev is really not that bad but you might be able to clean it up a little more.

This is super helpful, thanks @bnsgeyer! Will be testing the updated ATC_RAT filters for pitch and roll to get rid of the rotor frequency, since the blade (2/rev) one is knocked out. One observation - it seems like these oscillations are absent from the pitch rate loop and very evident in the roll one. Why do you think this would be the case? I would think they have similar inertia about the rotor, if anything more inertia in the roll axis. Is it worth considering different ATC_RAT filter levels for the two axes?

Wouldn’t 10Hz filters substantially kill the head frequency? Is the RATE.R signal the post ATC_RATE filter? Is there a way to plot the raw signal, INS notch filtered one, and then ATC_RATE filtered one to see this attenuation?

In conjunction with tuning the filters, I’ll be increasing the feedforward gains as you’ve recommended to a point that gives the actual an ability to match the desired and mildly overshoot, allowing our PID controller to handle the last bit + any disturbance rejection. This may bring me to roughly where I started (~0.4), do we think it’ll perform better? I’m just wondering if there’s a way to approach this in a more classical PID way. If our filters were dialed in and we didn’t see much of the head/blade, would we be able to instead increase our P/D gains and reduce FF? I think this is something along the lines of what you were recommending in another thread that touched on VFF tuning. Could our airframe just have too much vibe and how much is too much vibe?

Separately, I wanted your take on what to do about yaw control. We haven’t changed any parameters from the original set (ATC_RAT filters are at 15Hz and gains where we left them), but we do see 7-8Hz oscillation especially when we cruise. Since it’s a direct-drive tail, it won’t be as directly affected by the head, so do we need to play around with the VFF here or just the ATC_RAT filter?


You can see no feed-forward here and we’re maxing out an integral limit and have some level of integral output even in hover, despite ILMI = 0. Not sure how to fix all of this…

So the conventional helicopter has 7-8 times lower inertia in the roll axis and so the imbalance in the rotor will be seen in the fixed frame on the roll axis before you see it on the pitch axis. So I suppose you could set the filters separately since it is only affecting the roll axis.

No. when the 1/rev is only 14hz, there is not enough attenuation at 14 hz with a 10 hz low pass filter.

Good question. I am not sure it is however you can look at the PIDR.P signal and that still shows the 1/rev dominating the P contribution as well as the D contribution. These definitely include the filtered signal in it.

You probably would not be able to increase the P/D gains enough to be able to have enough P/D gain to remove the VFF. Again the idea behind the control architecture is to use the VFF to closely approximate the control needed to achieve the requested rate. When I wrote the response in that post, I was still not as familiar with how to tune helicopters with this control system. There was only one helicopter that I was able to tune without using VFF. It required a very stiff rotor where I was able to push the rotor flap regressive mode up above 5 hz and used a notch filter to remove the feedback instability.

I don’t have much experience tuning DDFP tails. Since there is no concern with feedback instabilities preventing you from getting enough control on the tail, try to use classical PID tuning to tune the tail. If you are seeing oscillations at any speed, you want to lower your P and D gains. You can try to use the filter but I don’t think it will have a significant effect.

What do you make of the yaw PID tuning? It looks like this is a feedback instability around 7Hz. Are there rotor/tail modes that we would have to filter out on a tail or do you think I just need to reduce the gains? If so, won’t I lose tracking performance? Notice how in several of these regions of the plot, we have much more derivative output than proportional and substantially greater integral output. Shouldn’t this not look like that?


Are the graphs shown in the previous post from the last flight you posted? Or have you flown and modified the yaw like I suggested?

In my opinion, you definitely need to reduce your yaw gains by at least 50%. You also need to raise the ATC_ANG_YAW_P back to 4.5. Be careful though because raising this parameter effectively increases feedback gains. That is why I suggested you lower the P and D gains before raising this gain. This parameter will provide more immediate feedback to keep the actual yaw tracking the desired.

Nope - that was from earlier.

Tomorrow I’ll try:

  1. Double VFF for R/P to 0.30
  2. Reduce ATC filters from 10Hz to 7Hz for R/P, also dropped Y to 10Hz (will try separately reducing R further if necessary to remove head 1/rev)
  3. Dropped ATC_RATE Y P/D gains by about half
  4. Increased ATC_ANG_YAW_P back to 4.5

Will try to get the inversion in RATE.P to align with the peak of FF and increase accordingly. If I can get it, I’ll tune the P and D gains a bit.

Attached is the param file I’ll try.TuningIteration2.param (14.9 KB)

I don’t recommend just jumping to these VFF settings in one step. You could try 0.2 but I even think that is a big step increase. Why not try 0.18 and then 0.2. Pull the logs and look at the responses.

I would just be careful and be prepared to land if you see the yaw axis oscillating a lot. If it does then drop the RAT_YAW_P gain down to 0.2 and try again.

Lots of progress tuning the inner loops and some plots to share from the evolution to the last configuration, which still needs work.

Key improvements:

  • VFF was increased in small increments from 0.2 upwards to 0.35 before we got some instability with pitch. Roll seemed stable at these levels.
  • ATC filters were dropped to 7Hz resulting in huge reduction of rotor vibration at 1/rev, but it is still present. We can try chopping further if we think it’ll help.
  • ATC yaw rate loop gains dropped by about half and ANG_YAW_P increased from 2 back to 4.5
  • Integral output in the rate loops seemed to be on the order of the feedforward output and like they may be getting in the way of tuning, so reduced to 0.01. We may need to address this in a different way…

Test1 (reproduce previous test):

Tuning2 (ATC_ACCEL upped from 40000 to 50000, VFF upped from 0.15 to 0.20)


Tuning3 (VFF upped from 0.20 to 0.25)


Tuning4 (VFF upped from 0.20 to 0.35)



I think we see the inversion in the P before the FF reaches a zero crossing, but I tried to increase it further and got more oscillation. Rates follow desired closer as well, with the exception of some weird peaks and offsets.

Tuning5 to Tuning9 were us increasing VFF up to 0.55 and playing around with removing the integral gain, lots of instability. Attempting to get the outputs to add up to desired resulted in feedforward oscillation. Feel free to check out the logs, but these were less interesting.

Tuning10 (VFF back at 0.35 but integral gains for pitch and roll backed down from 0.1 to 0.01 and proportional gains increased from 0.03 to 0.07, a level we used to fly before this tuning)


Some instability and oscillation noted especially in pitch, so runs 11 through 13 endeavored to reduce P gain and VFF as necessary to get stability.

Tuning11 (VFF for pitch only reduced to 0.30, P gain at 0.07 still)

Tuning12 (VFF for pitch still at 0.30, P gain reduced to 0.05)


You can see the feedback or feedforward oscillation still evident. Not sure which one…

Tuning13 (VFF increased to 0.35, P gain reduced further to 0.03)



Oscillation looks to be gone but there may be some small remnants?
Rate loops look much better, but still some offsets to deal with


Attitude loops still seem like they can use some work

Questions:

  1. Do you think we successfully complete the VFF tuning? Is the last test the closest to optimized?
  2. Is it ok that we don’t quite get to the des level in our PID output plots with the sum of p,i,d,ff?
  3. How do we improve inner rate loops further to get rid of offsets and fix any sporadic peaks?
  4. Which parameters do we tweak to get the attitude loops dialed in or are we not yet ready for that? Any other next steps?

Dataflash logs and parameter files for everything here. This is a lot to go through, so I’ve tried to make it easy with relevant plots. Thank you for all your help @bnsgeyer!

That’s not the goal.

Feedback loops cause the instability

Ok. From what you have showed me, I think a VFF gain for pitch and roll of 0.35 is good. I think your ATC_RAT_PIT_P should stay at 0.03.

I would suggest now trying to raise the pitch D gain and the roll P and D gains to see if you can get them any higher.

As for the I gain, that is what will remove the bias between the desired and actual attitudes. So put that at 0.1 for now. We can revisit that later.

Finish your tuning of the P and D gains I have specified above. And then let’s look at the attitudes.

@zking786 Any updates? I think you are close to being complete with the attitude controller tuning. the next step would be to increase ANG_P values to drive the actual closer to the desired. I normally recommend increasing the pitch and roll ANG_P by 0.5 from 4.5 to 6 maximum.

Then your ready to start doing ALTHOLD and LOITER.

@bnsgeyer per our conversation I’ve tuned the P/D gains for pitch and roll, then done the ANG_P gains by increasing them to the point of instability and halving them. This allowed me to increase rate proportional loop gains from 0.03 to 0.04, derivative gains up to 0.01 (pitch) and 0.004 (roll), and then stabilize angle gains from 4.5 to 6 (pitch) and 5.5 (roll). It feels great, but there are some issues with the integral gain and our ability to get the attitude to align, particularly in pitch and especially in high-speed cruise. I’ll share plots from before / after applying the suggested I gain / after P/D tuning without the integral,… then list out questions/concerns…

Tuning15 (VFF of 0.35 and P of 0.03 for both with 0.001 derivative gain or less) - Before:

Notice it seems like the magnitude of the rate output in pitch may be exceeding the desired. Perhaps VFF is too high? This isn’t the case in roll, where they’re more closely matched, though offset.

You can see the impact to the attitude, which often exhibits a persistent offset.

Tuning16 (ILMI of 0.08 and I of 0.1 for pitch and roll)



Notice rate loops no longer following the shape of desired in both pitch and roll. Although there’s some attitude correction, it’s slow and the rate loops no longer match the same way as before. Some further attitude tracking errors encountered in transitions from cruise/forward flight as well.

The attitude error is better closed in adding the integral gain, however it takes ~5s. Then, once the integral gain is wound up sufficiently and the offset is corrected, it leaks at some rate. Want to understand this better. Depending on how this happens, it can compromise how we handle gusts and other transient disturbances. This is a concern because you can see how large the I output is relative to P.

Tuning21 (restored low 0.0001 I gains and tuned P (0.04 for pitch and roll) and D gains (0.01 for pitch and 0.004 for roll with oscillation at roughly 2x these levels).



Notice offsets are still present and similarly shaped rate curves once we’ve backed off I again and increased our other gains. More derivative response than proportional in various stages, but definitely stable.Not sure if this is a good thing for heli flight dynamics.



Notice that although attitude in roll looks decent, but pitch attitude offsets look bad, possibly worse than before P/D gain tuning when we also had no integral gain.

Tuning22 (increased ANG_P gains from 4.5 to 6 (pitch) and 5.5 (roll), which was half of the point they oscillated at)



You can see this didn’t really help much, if anything maybe worse. Would have expected it to behave like the integral gain on our attitude loops in correcting offsets by increasing desired rate.

You can also see that the attitude offset gets worse when we speed up or slow down in cruise.

From this tuning there are a few open questions:

  1. Why do the pitch loops look worse than the roll ones, possibly even outputting larger rates than the desired levels? Do we need to reduce pitch VFF?
  2. Given these plots, how do we properly set the I gain? We’ve tried reducing it, reducing ILMI, and setting it around 20% of the VFF gains, but does it actually need to be higher to respond more quickly?
  3. Why is adding integral gain ruining how the desired and rate outputs track - they no longer feature the same shape the moment we get I gains above 0.05. Will it be possible to get nicely following rate curves that also align without an offset? Is this possible on a traditional heli of this topology?
  4. Is it possible to configure how the integral accumulator leaks, once we reach the target, so that we don’t wash out our disturbance handling capability?
  5. Are we properly tuning the ANG_P gains and shouldn’t they help clean up these attitude offsets?

Dataflash logs and parameter files uploaded here.