PID Attenuation and scaling - iNavFlight/inav GitHub Wiki
This topic covers methods used to dynamically adjust your models PID gains, to prevent control oscillations as the models airspeed changes throughout the flight.
Multiple methods are used to accomplish this. Depending on whether it's a multicopter or fixedwing platform.
-
Multicopter TPA - Throttle PID Attenuation
-
Fixedwing APA - AirSpeed PID Attenuation and boost (INAV 9.0)
-
Fixedwing TPA and Pitch Angle - Throttle and Pitch Angle PID Attenuation and boost (INAV 9.0)
-
Fixedwing TPA - Throttle PID Attenuation and boost (Pre INAV 9.0)
Multicopter TPA
Settings :
-
TPA_Rate - percentage of PID attenuation that will occur when the throttle is increased above the
TPA_breakpoint. -
TPA_Breakpoint - the throttle micro-second value in the curve at which
TPA_Ratewill begin to be applied. Below that point the PIDs are not attenuated at all.
How to use it?
- Firstly, set
TPA_Rate = 15as a starting point.
The PID's should be tuned in the throttle range your copter will comfortably cruise at - e.g. 1300 - 1600uS based on thrust to weight ratio and bank angle. - But once the throttle is moved higher than this point, you may start seeing oscillations. So begin increasing the
TPA_breakpointto a throttle value just prior to the onset of those oscillations. - Then slowly increase the
TPA_Ratevalue until the oscillations in the higher throttle range are gone.
It may require increasing even more on powerful freestyle or race quads.
Note - On reverse motor 3D installs, TPA is not recommended.
Example of multicopter TPA curve

[!Warning]
Fixedwing dynamic PIDFF adjustment is broken into multiple methods, based on changes made in INAV 9.0.
It is important to understand the operation of both methods. And also tune TPA and Pitch angle, due to it becoming a fall-back if the APA hardware source fails.
Fixedwing APA
This method uses the planes airspeed to determine the optimal dynamic PIDFF gain adjustments required.
INAV 9.0
Settings :
-
Fw_reference_airspeed- Is the Airspeed at which your PIDs, Rates and Feedforwards should be optimally tuned, to provide a strong stabilization response. -
apa_pow- Sets how aggressively the gains will be dynamically adjusted from the base PIDFF tune.
Increasing its value from the default of 120, will boost the gains more aggressively below thefw_reference_airspeed, and attenuate them more aggressively above thefw_reference_airspeed.
While decreasingapa_powwill make the gain adjustments less aggressive. Meaning the PIDFF gain boost will be weaker, as will its attenuation strength, leaving the based gain tune less altered by airspeed changes.
[!tip]
Settingapa_pow = 0will disable this function and revert to using the TPA and Pitch Angle method instead.
If either GNSS data or the Pitot sensor data becomes untrusted. It will also revert back to the TPA and Pitch Angle method.
FUNCTION :
This method uses airspeed data to dynamically adjusts the PIDFF gains.
Airspeed can be obtained from either a Pitot airspeed sensor. Or Virtual airspeed, derived from GNSS data requiring a 3D satellite fix..
As with the throttle TPA_rate setting, APA_pow also uses a similar scaling limit factor of [2x boost] 200% gain increase - [0.3 attenuation] 70% gain reduction.
How to use this?
-
If you have not done so; firstly tune your airplanes rates and Feedforwards with AutoTune, using the default PID gains. But if you already have a workable tune for your airplane, use that.
-
Enter the airspeed value your airplane will comfortably cruise at, into the
fw_reference_airspeedsetting.[cm/s] -
Start incrementally increasing your PID gains, while holding the approximate cruise airspeed you entered above. Tuning can be done easier via inflight tuning.
-
Once this is complete. You will notice that the stabilization automatically becomes tighter when the airspeed reduces below the
fw_reference_airspeed, and control surface oscillations are prevented as the airspeed increases above that point. -
However if you do encounter control surface oscillations at higher airspeeds, this is when you can increase the value of
apa_pow. It will allow the gains to become more aggressively attenuated at higher speeds to prevent this occurrence. Only make adjustments of no more than 10 at a time. -
Also keep in mind that control surface throws as well as higher airspeeds will influence the need to adjust
apa_pow. If you have larger control surface throws, it may also require increasing.
But if your airplane is very draggy and can't make it past 120km in a full throttle dive. You can reduceapa_powto provide a tighter stabilization response over the planes whole speed range. -
fw_tpa_time_constantis not used in airspeed based dynamic PID adjustment.
Fixedwing TPA and Pitch Angle
This method uses the throttle position, combine with the airplanes climb or dive angle, to determine the optimal dynamic PIDFF gain adjustments required.
INAV 9.0
Settings :
-
TPA_Rate- the amount of scaling apply to the PIDs. 200%TPA_Rateallows the base PID tune to be scaled by a factor of[2x boost]200% gain increase -[0.3 attenuation]70% gain reduction. -
TPA_breakpoint- is the point in the throttle curve when the base PID tune is not boosted or attenuated. This value should approximate the airplane's best cruise speed. -
tpa_pitch_compensation- is used to calculate the collective effect pitch will exert on-top of the raw throttle input, to reverse the way gains are dynamically adjusted. Put simply - Boost becomes Attenuation, and Attenuation becomes Boost under certain flight conditions.
The ideal value for this function is 8, which is the default.
DECREASING its value will provide a weaker gravity induced pitch angle influence over the raw throttle, and therefor the gains. While INCREASING it will provide a stronger pitch angle infulence over the raw throttle.
[!tip] Setting
tpa_pitch_compensation = 0allows it to work in way the old fixedwing TPA did. Which isn't really desirable.
fw_tpa_time_constant- is a smoothing and time delay constant, reflecting the non-instantaneous response of the airplane, based on relative drag, inertia and thrust. This filter works upon a throttle approximation or the forward speed, and pitch angle gravity induced speed changes. It allows gain changes to transition more smoothly.
FUNCTION :
The Stick or Nav throttle input is used collectively with the climb/dive angle, to more accurately attenuation or boost the gains if the airspeed source fails. Or if you choose not to fly with an airspeed source.
The attenuation/boost strength is determined by how high you set TPA_rate.
Because this method accounts for the pitch angle. It can override the conventional throttle based gain adjustments, according to the effect gravity has on the airplane in a climb or a dive. i.e. The airplane will either speed up in a fall, or slow down in a climb; which throttle position alone can not determine.
Example :
If your airplane is flying level at 80% throttle, the gains will have some attenuation applied to them at that airspeed to prevent control oscillations.
But if you then pull back on the elevator stick, so the airplane starts climbing at high angle. The vertical airspeed will generally start to wash-off on airplanes that aren't over powered. Leading to a transition from gain attenuation to gain boost. This will tighten the gains as the airplane slows closer to a stall, even when the throttle is higher.
The same applies if the airplane is placed in a steep downward dive. When using the old method, having the throttle low in this case would cause the gains to boost. But because this method knows the airplane is in a dive, it will disregard the direct raw throttle command, and start attenuating the gains to prevent oscillations, because the airplanes free-fall speed is increasing, irrespective of the throttle.
How to use this?
-
You should increase the
TPA_Ratefrom the default, to a conservative value of 40% when you're tuning the base gains. So it allows some dynamic PID adjustment to occur. Otherwise a tight base gain tune around the TPA_breakpoint will instantly cause oscillation if you increase the throttle/speed by too much. -
Tune your PIDs to the throttle range you intend to fly your airplane. nav_fw_cruise_thr is ideal. Set that value as the
TPA_breakpoint. e.g. 1400 - 1500uS -
If you haven't already tuned your airplane. Make sure you complete an AutoTune with the default PID gains. Otherwise you can use the tune you already have.
-
While inflight you can start increasing the P and D gains around the throttle value you have
TPA_breakpointset. -
Once you have the TPA_breakpoint throttle base PID gains tuned as tight as you are comfortable with. Push the throttle upwards toward full and let the speed increase. If oscillations start to occur. Incrementally increase the
TPA_rateuntil they are gone.
Now when your flying at lower throttle, your airplane should feel tighter in its stabilization response. And when flying at higher throttle (up to full throttle), the control surfaces should not oscillate. -
Due to drag also effecting how fast a given airplane will gain or lose speed.
fw_tpa_time_constantmay require adjustment to account for the time it takes for the speed to ramp up or ramp down, based on climb or dive pitch angle, or a fast throttle stick command. -
If your airplane has a high thrust to weight ratio and can climb at a high angle and at high speed. It can be beneficial to start incrementally decreasing
tpa_pitch_compensation. This will reduce the effect pitch angle has over raw throttle. Thus preventing the gains for being boosted excessively at higher climb speeds, preventing control surface oscillations.
The same will apply in a lower throttle dive, if you feel the gains are being attenuated too much. You can also incrementally reducetpa_pitch_compensation. I wouldn't recommend going lower than 3.
Fixedwing TPA
Pre INAV 9.0
Settings :
-
TPA_Rate- the amount of scaling apply to the PIDs. 100% TPA_Rate allows the base PID tune to be scaled by a limiting factor of[2x boost]200% -[0.5 attenuation]50%. -
TPA_breakpoint- is the point in the throttle curve when the base PID tune is not boosted or attenuated. -
fw_tpa_time_constant- is a smoothing and time delay constant, reflecting the non-instantaneous speed/throttle response of an airplane, based on drag and inertia.
FUNCTION :
The Throttle stick position is used to not only attenuate the PID gains in the higher throttle range, above the TPA_Breakpoint. But also boosts them in the lower throttle range, below the TPA_breakpoint, for tighter stabilization control when flying or gliding at lower speeds with minimal or no throttle.
How to use this?
-
Tune your PIDs to the throttle range you intend to fly your airplane. nav_fw_cruise_thr is ideal. Set that value as the
TPA_breakpoint. e.g. 1400 - 1480uS -
Once your P and D gains are tuned, and before you add any
TPA_Rate. You may notice when flying at lower throttle, your airplane handles more loosely. And when flying at higher throttle (up to full throttle) control surfaces may begin to oscillate.
You can now start increasing theTPA_Ratevalue until those oscillations are gone or minimal in the higher throttle/speed range. This will also translate to better handling at lower throttle/speeds, by boosting the PID gains.
[!NOTE] The above method had its limitations. It can not attenuate the PIDs at lower throttle values if the airplane is placed into a dive, causing the air-speed to increase. This could lead to control surface oscillations.