Tune INAV PID‐FF controller for fixedwing - iNavFlight/inav GitHub Wiki
Description of PID-FF controller:
When tuned correctly, the FF-gain should do most of the work of turning the airplane. Which leaves Proportional, Integral and Derivative to make up for slight target error and drift caused by turbulence.
- Manually tuning Rates and Feedforward - How it works
- General ACRO PID tuning
- Tuning ANGLE mode
- LEVEL controller
- Fixedwing I-term Lock
Tuning of the Rates and Feedforwards can be done more easily via AutoTune, provided it's performed correctly.
However, tuning can also be done manually as explained below.
Manually tuning Rates and Feedforward - How it works
While in the process of flying manually. It is beneficial at this time to run Servo Autotrim.
[!Tip] Ensure the control surface servo throws are set correctly before you tune the Rates and Feedforwards manually, or by the Autotune process.
Any adjustments made to the servo Mixer or Output travels after you have tuned the Rates and Feedforwards, will negatively effect performance. Requiring you to run the tuning process again.
-
Fly in
MANUAL
mode with themanual_roll_rate
,manual_pitch_rate
andmanual_yaw_rate
settings set to 100%.
Record DVR footage of the flight, and enable the blackbox to log flight data.
Perform hard rolls, hard loops and one 360° yaw turn. Apply full stick deflection for as long as possible throughout these maneuvers. -
To calculate an axis (approximate) rate from a DVR recording, you'll need to count the number of frames it took for your aircraft to do a complete maneuver (roll/flip/yaw turn), determined by the average FPS of the recording. Then use this formula :
360 / (number_of_frames / FPS)
.
You can take multiples samples and average them for better accuracy.
You can also use a Python script to help automate the process. -
Typical starting values for Rates, that are suitable for most airplanes are -
Roll = 300°/s
Pitch = 110°/s
Yaw = 60°/s -
Zero out P, I and D gains on the Roll, Pitch and Yaw controllers.
-
Set
tpa_rate = 0
-
Increase FF-gain until you get 90% of full servo throw when having sticks at full throw in
ACRO
mode, when compared toMANUAL
mode. -
This is so the FF-gain does most of the work turning the airplane, but leaving some for the P and I gain to work with.
-
For this step it's convenient to have the two modes
MANUAL
andACRO
available on a switch, so you can easily move between the two, and compare the throws. -
The 90% deflection value can also be calculated by dividing 13950 by the maximum rate for the axis. e.g. 360deg/s maximum roll
13950 / 360 = 38.75
FF. For 80% deflection, divide 12400 by the rate. -
Now set some P and I gain as a starting point.
fw_p_pitch = 7
fw_i_pitch = 10
fw_p_roll = 3
fw_i_roll = 15
fw_p_yaw = 10
fw_i_yaw = 5
General ACRO PID tuning
This topic includes some non conventional means of tuning. However, things don't always work as theory dictates for fixedwing operation when the system still has missing components. e.g. true air speed based PIDFF attenuation.
I-term:
If the airplane drifts slightly from center on an axis, once Autotune, AutoLevel and Servo_Autotrim are complete. Increasing the I-gain on that given axis, can reduce the effect.
After Feedforward, allowing I-gain to do more of the work than P-gain. Can actually make the Roll axis response smoother from an FPV perspective, than fighting a loosing battle, by applying too much P-gain, in hopes of removing roll axis wobbles.
Be cautious. Too much I-gain can also cause oscillation. Values should be limited to a maximum in the low twenties. Accounting for the use of pid_iterm_limit_percent and Fixedwing I-term Lock mentioned below.
P-term:
If you want more stabilization against hard buffeting from the wind, try increasing the P-gain. But only up to a point.
Too much P-gain can cause oscillations as the air-speed increases. This is when you want to apply some Fixedwing TPA.
P-term will never be able to fully correct for fixedwing roll axis instability at lower airspeeds, due to processing and SERVO reaction lag. And there won't be enough air flow over the surfaces to provide optimal control. It can often be a case of what you prefer on the Roll axis. i.e. Faster jittering from higher P-gain. Or Slower wallowing movements from higher I-gain.
D-term:
Once the P-gain it tuned to about 80% of its optimal, at a given air speed. Then start applying some D-gain in small amounts, to add axis damping.
After manually tuning your Rates and Gains. You can reduce them from their limit, to what suits your stick feel and flight requirements.
It's normal to see reduced servo throw's when reducing rates at this point. If you have full servo throw at this stages you would likely overshoot the target deg/s as well, leaving the P-term to do the rest.
Tuning ANGLE mode:
-
Auto Level Trim should be used for the purpose of tuning the flight inclination level of the wing, comparing to the Flight Controller boards mounting angle.
However it can also be fine tuned manually if desired. EnterANGLE
mode. And check if your aircraft fly's straight and level, without climbing or diving slightly. If it doesn't fly level, your FC is probably not mounted flat relative to the aircraft's Angle of Incidence when flying. You can adjust it with fw_level_pitch_trim.
Adjusting the board's alignment viaalign_board_roll
,align_board_pitch
can also work, but is not recommended. -
If the Roll/Pitch bank angles are too low for your taste, you can adjust them via the
max_angle_inclination_rll
andmax_angle_inclination_pit
. This will provide greater authority on both axis's, within the full stick deflection range.
If you want the same amount of bank angle in navigation modes, you will also need to increase their values vianav_fw_bank_angle
,nav_fw_climb_angle
,nav_fw_dive_angle
. However, keep in mindnav_fw_bank
angles can not be set greater thanmax_angle_inclination
.
LEVEL controller:
- If you're unhappy with the strength ANGLE based modes return back to level, after the stick is released. You can adjust the P-gain via
fw_p_level
. The default value of 20 is optimal. However reducing it can provide a smoother feel.
While increasing this value beyond 30 on a fixedwing; generally makes the corresponding axis more jittery when trying to maintain a level attitude in turbulent conditions. fw_i_level
works as a Low Pass Filter for the LEVEL controllers update rate. Any value greater than 5, is faster than most fixedwings can respond to attitude level correction. Reducing it in some cases, to 3 or 2, can help provide a smoother feel.fw_d_level
uses the present rate target and the calculated angle rate target. Which allows for transition between ANGLE (level) and ACRO (rate), to provide HORIZON mode.
When tuning this value. Increase or decrease the setting according to the stick position you want transition to occur. Generally it is better to have transition occur near full stick deflection. Meaning, it is your intent to perform an aerobatic maneuver.
Fixedwing I-term Lock:
Version 8.0 and later
This feature solves the problem of I-term accumulation and bounce-back on a Fixedwing platform, when the stick is quickly release back to center, and the airplane still has angular momentum on that axis.
When the pilot moves the sticks, the following happens:
-
P-term and D-term are attenuated with a bell curve. With no attenuation at stick-center, and full attenuation when
fw_iterm_lock_rate_threshold
is met. Its value is a percentage of the maximum axis rotation rate. -
When the rate error rises greater than the
fw_iterm_lock_engage_threshold
10% (default). And that error keeps climbing untilfw_iterm_lock_rate_threshold
reaches 40% (default). Then the I-term will become fully attenuated, until the Gyro rate error drops below thefw_iterm_lock_engage_threshold
again. Or thefw_iterm_lock_time_max_ms
expires. -
FF-term is never attenuated. As a result, the airplane feels fully stabilized near stick center, and performs like Manual mode when executing fast maneuvers.
The default settings work fine.
But if you require less attenuation at a higher rate of axis rotation; fw_iterm_lock_rate_threshold can be increased. For example, in the case of 3D airplanes that uses the I-term to help hold axis attitude.
Or on air frames that carry more axis angular momentum, like those with a very high rotation rate or higher wing mass, fw_iterm_lock_engage_threshold can be decreased, or you could add more time to fw_iterm_lock_time_max_ms.
Other tuning tips:
- Information on FW navigation tuning can be found here - Navigation PID tuning. This is the place to look if you encounter wandering left or right of the heading target. Or oscillations on the pitch axis while attempting to hold altitude.