Trouble tuning rate and attitude loops

Hi Fellow Ardupilot Users:

I’m new to this forum and have followed a number of the queries and guides pertaining to optimizing flight controls and behavior, but I haven’t been able to successfully apply these to my helicopter.

Although the system appears stable, I get occasional oscillation and poor disturbance rejection. There are times when the attitude desired and feedback are several degrees off (5-10deg), and the rate loops can be >20deg/s from where they need to be. It’s unclear what limitations come from the hardware (stiffness of the tail, damping of the head, dynamics in various flight modes, vibration) and what level of performance I can fundamentally achieve.

It would be really helpful if someone could review my Dataflash logs and provide insight into where the tuning can improve and some recommendations for tuning next steps.

I’ve highlighted some examples of how far off the command and response can be at the rate loops. To try and address these gaps, I’ve increased P/D gains at the ATC_RAT loops up to the point of instability, without success. I’ve tuned the corresponding filter to reduce vibration impact. I’ve tried to add integral gain and increased IMAX to see if I can counteract this offset with no success.

I’ve highlighted some examples of how the attitude controller also exhibits offsets. Sometimes it looks great, sometimes there are huge gaps. The stabilize proportional gain doesn’t seem to do much.

You can download the Dataflash log here.

Some basics for the configuration:
AP Copter 3.6.9
Running PX4
Dataflash log is 25MB, so link attached. Please let me know if there’s a better way to share.
Direct drive tail, SAB head with large meter long blades
(More details as requested)

Did you read and follow : ?

Please do.

@amilcarlucas those instructions apply to multicopters and I haven’t vetted them for helicopters. We have our own tuning instructions here

@zking786 could you post your parameter file please? I will not be able to look at your log files until Friday. But I could look over your parameter file and see if there’s anything that I notice that is not consistent for good tuning.

Attached param…Latest.param (14.8 KB)

Your description says that you have a direct drive tail. And by your settings I’m assuming that this is a motor that is mounted on your tail and it has a fixed pitch propeller attached to it.

Yeah I wouldn’t expect you to see a difference. The reason being is that the integrator is leaked off at speeds less than 1 m/s. In that case you have to use the ILMI parameter to retain integrator.

Please tell me what your col_max and col_MIN values are set to in degrees of collective pitch. I’m wondering why your IM_STAB_2 is 200 and IM_STAB_3 is 400.

Yes, exactly it is a prop attached to the tail

I see you have RSC mode 2 selected. Does your ESC have a governor function that you are using? If so, what is your rotor speed set for?

Rotor speed is 850RPM, governed on the ESC side.

IM_STAB parameters were setup to get the zero swash position to roughly align with the neutral stick mapping. Probably not perfect, but it was acceptable for flight. The mapping is roughly max collective at 9deg, min collective at -4deg and at zero swash we had a max cyclic of 5.3deg.

I believe you’ll want to have center collective stick be equal to whatever pitch is required to maintain a hover. In other words, it should not be zero collective. Otherwise you’ll have the heli jump on you when switching to any flight mode that uses the altitude hold settings.

@bnsgeyer can you elaborate on how this works? I’ve seen 5m/s as well. Appears the integral gain will only apply in cruise.

Two concerns (1) We didn’t see much of an effect in either cruise or hover, so why didn’t cruise address the offset, and (2) Do we need to increase ILMI to allow integral correction for hover and if so, to what extent?


@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