Servers by jDrones

Trouble tuning rate and attitude loops

@zking786 Chris has this correct. Center collective stick should be hover collective. Everything he said is correct

Have you read thru the heli tuning wiki I referenced above. It explains how the ILMI works. If not, please read and see what questions you have after that. Typically I recommend 0.08 for ILMI in pitch and roll. It equates to approximately 5 deg of attitude error.

Edit: @zking786 unfortunately I don’t have time until Friday to give you detailed advice about your settings. There are a lot of thing that I see in your param file that I would not consider to be consistent with good tuning. The one thing I noticed immediately is that your ATC_RAT_RLL_I and ATC_RAT_PIT_I are too smalll. They should be at least 0.1. That is why you were seeing the attitudes not matching desired in forward flight.

@Chris_Khosravi we can tweak IM_STAB parameters, but we hover at ~2deg, so it’s not usually a huge adjustment.

@bnsgeyer I went through the guide in more detail. There are a few differences in how I’ve approached tuning…

  1. VFF levels were picked as initial starting points, as they looked alright, and then after PID tuning, changes were explored and they resulted in worse tracking performance, so they were left at initial levels.

  2. FILT settings were changed with an initial PID tune to clean up the amplitude of rotor vibration. Angular rate for was as large as 10deg/s in the rate loops, so applying these filters to 6Hz helped substantially attenuate head vibration and increase PID gains. The guide doesn’t describe a methodology for this, but it seemed sane in looking at logs. FILT of 20 is suggested, but our head speed is substantially lower than normal and we have flight modes that are a bit lower. How should this be used in relation to the INS_NOTCH filter? The goal is to attenuate head/blade frequencies and avoid any resonances.

  3. PD gains were tuned in the rate loops first by increasing P gains until oscillation, then reducing by about 25%. D gains were increased to oscillation and then decremented by about 25%. P gains were increased further and then decreased by about 25%. This is a little different in methodology from what is recommended. Do you think it’s resulted in values that are too high and if so is it unstable?

  4. Integral gains were tuned in <5m/s forward flight with IMLI of 0. The guide refers to 5m/s @bnsgeyer is this the case or 1m/s for leakage? I think when this was non-zero we have had an issue with the heli flipping in transition from motion to stop. How can we avoid crashing if we use a non-zero value?

  5. Stabilize proportional gains were tuned after the rate loops were tuned in acro, but it’s unclear how these will be different from integrated output of the rate loops. Why are we not having an effect when we change these parameters?

First here is a setting that should be set
Did you intentionally set this to 1. I don’t trust that this feature works properly. I was just wondering. This could have affected your integrator

We found that 0.15 was a good starting point for VFF. I’m a little surprised that you have this at 0.4. But I will look at your responses to see if this looks ok.

Yes. I saw the vibration in your rate responses that you posted. It actually looks like the 2/rev. My recommendation is that you use the notch filter to get rid of the 2/rev. Then back off your filter settings to 10hz. We can see what your 1/rev looks like. Typically I notch the 1/rev and use the low pass filters to attenuate the 2/rev.

Your method is fine. You just want to be certain your feedback oscillations are not there. I will look at this when I view your log. I am surprised at how high you were able to get your P gains. Just looking at the graphs you posted, it does apear that you have about a 3hz feedback oscillation in your attitude traces. I would probably suggest you back off P and D gains until that goes away.

sorry I may have the speed in which it switches wrong. But I think a lot of the issues you are having with the I gain are caused by the ATC_PIRO_COMP being set to 1 and your I gains being so low. I am not sure what your concern is with transitions from motion to stop and the possibility of crashing. The I gain helps hold attitude. The reason we leak it is to keep it from building up on the ground and the possibility that the autopilot driving could drive the rotor into the ground. So the ILMI retains that amount of integrator and leaks off everything above that to limit it in low speed and while on the ground.

We can talk more about this after we get the I gain take care of.
I will look at you logs when I get home today. For future logs, either set the LOG_BITMASK to 131071 or be sure you have fast attitude logging selected.

well here is what I would propose.
first and foremost

Next lets rework your vibration reduction approach
refresh your parameters
Set the following
restart your flight controller(cycle power)

So, I am very surprised at the magnitude for roll gains. VFF = 0.4, P=0.15. These are way higher than anything I have seen. Is there anything special that you have done in your mechanical set up that could explain these high gains?
I would suggest cutting everything back as I am uncertain of the effect that ATC_PIRO_COMP could have on these responses. Here is what I would like you to set.


If you are uncomfortable with roll VFF being that low then use a value you are comfortable with.

With your first flight, lets just make sure that we have attenuated the 2/rev sufficiently and be sure that the 1/rev has not come back. If the 1/rev becomes more prevalent then take your FILT values back down the 6 hz.

Once you are happy with that, then give me a flight in stabilize with some slow inputs to a roll angle and pitch angle and then some fast (step) inputs to a roll angle and pitch angle. the roll and pitch attitudes don’t need to be any larger than 20 deg.

I guess one more thing. You have very low ATC_ACCEL_P_MAX and ATC_ACCEL_R_MAX. this is understandable for the size of your vehicle but we may want to try and tune at slightly larger values and then we can always lower these after we have tuned the vehicle. these set you desired accelerations and feel. Why did you choose to make them so low? Was this a pilot preference or concern with the safety of the vehicle? Based on the accel setting then I would also suggest you increase the ATC_INPUT_TC. this is the time constant of the acceleration reaching steady state (jerk response). This is too small based on your accel settings. I would suggest 0.2 to 0.25. One thing to also note is this only affects stabilize mode and not acro. Since all of the higher augmented modes (loiter, althold, …) and auto mode use stabilize then it will affect them as well.

So your min collective is -4 deg and your max collective is +9 deg. Your hover collecitve is about 2 deg. So your hover collective is about half way between min and max. There for your IM_STAB_2 should be 400 and your IM_STAB_3 should be 600. In stabilize you should be holding about half collective stick with IM_STAB set up this way. that is what you want in order to switch between stabilize and other altitude hold modes. it should even provide a seamless transition between stabilize and acro. I would think in your current configuration you are adding collective when going from acro to stabilize.

Testing it and will give you feedback later today. To answer some of your questions:

  1. ATC_ACCEL MAX settings were put there to prevent rollover that occurred a while back. Increased them a bit and we can see if there’s an issue.
  2. VFF settings were tuned for pilot stick feel. Perhaps we shouldn’t have done that. Reverted to levels suggested.

Some questions I have about the parameters:

  1. Why do we not increase the bandwidth on our INS notch filter to encompass the head frequency (1/rev)? Is there a reason this applies to the blade frequency (2/rev) and that we use the rate filters to knock out the larger head frequency content?
  2. What does pirouetting compensation achieve? Why disable it?
  3. Any reason why we’re not touching the yaw loops?

Felt like it was sloppy in flight with the proposed gains and the attitude feedback vs command doesn’t look great… @bnsgeyer what do you recommend we change parameters to? How does this one look in comparison?

Attaching the parameter and binary files… TuningIteration1.param (14.8 KB)

Dataflash log here

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


  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.

Servers by jDrones