Pixhawk Auto Tune Pid
The tuning of one axis might impact the other axis, nevertheless it is best to tune one axis after the other. Accordingly, the first step in tuning a brand new gimbal is to disable all motors except of the pitch motor, and find the proper tuning parameters for it. Then the roll motor is enabled and the corresponding PID parameters are tuned. You can use PID Tuner with a plant represented by a numeric LTI model such as a transfer function (tf) or state-space (ss) model.If you have Simulink ® Control Design™ software, you can use PID Tuner to tune a PID Controller or PID Controller (2DOF) block in a Simulink model. If you have System Identification Toolbox™ software, you can use the app to estimate a plant from measured.
AutoTune attempts to automatically tune the Stabilize P, Rate P and D, and maximum rotational accelerations to provide the highest response without significant overshoot. Copter needs to be “basically” flyable in AltHold mode before attempting to use AutoTune as the feature needs to be able to “twitch” the copter in the roll and pitch axis.
Autotune only works in HORIZON or ANGLE mode, before using auto-tune it’s best you setup so there is as little drift as possible. Autotuning is best on a full battery in good flying conditions, i.e. No or minimal wind. Autotune does not support pidcontroller 2 or higher (pidcontroller 0 is the Cleanflight default, pidcontroller 1 will work. May 05, 2017 I tried Auto Tune twice, and in both occasions the aircraft (one with an APM 2.6 and the other with a Pixhawk) actually flew worse than they did with the default PID settings. Unlike Auto Tune, Auto Trim and In Flight Tuning give you immediate feed back as to how the aircraft will actually fly. Sep 10, 2014 In this seventh video in the APM series we look at the two functions that will automatically setup your trims and PID settings for you on the APM 2.5/2.6.
Note
Position Hold during AutoTune is available in Copter 3.5 (and higher).
Setup before flying¶
- Set up one flight mode switch position to be AltHold.
- Set an Auxiliary Function Switchto Autotune to allow you to turn the auto tuning on/off with the aswitch.
- Remove the camera gimbal or any other parts of the frame that could wobble in flight
- Select which combination of axis (roll, pitch, yaw) you wish to tune using the AUTOTUNE_AXES parameter
- Set the autotune’s aggressiveness using the AUTOTUNE_AGGR parameter (0.1=agressive, 0.075=medium, 0.050=weak), normally start with the default 0.1.
- For large copters (with props at least 13inch or 33cm diameter) set the Rate Roll and Pitch filters to 10hz, these are: ATC_RAT_RLL_FLTT , ATC_RAT_RLL_FLTD , ATC_RAT_PIT_FLTT , ATC_RAT_PIT_FLTD , (in Copter-3.4 they are ATC_RAT_RLL_FILT and ATC_RAT_PIT_FILT)
- It is recommended to enable battery voltage scaling of PID gains
How to invoke AutoTune¶
Wait for a calm day and go to a large open area.
Ensure the ch7 or ch8 switch is in the LOW position.
Take off and put the copter into AltHold mode at a comfortablealtitude.
Face the vehicle so that it will twitch at 90degrees from the direction the wind is blowing (i.e. if tuning Roll first, point the vehicle into the wind)
Set the ch7/ch8 switch to the HIGH position to engage auto tuning:
- You will see it twitch about 20 degrees left and right for a fewminutes, then it will repeat forward and back.
- Use the roll and pitch stick at any time to reposition the copterif it drifts away (it will use the original PID gains duringrepositioning and between tests). When you release the sticks itwill continue auto tuning where it left off.
- Move the ch7/ch8 switch into the LOW position at any time toabandon the autotuning and return to the origin PIDs.
- Make sure that you do not have any trim set on your transmitter orthe autotune may not get the signal that the sticks are centered.
When the tune completes the copter will change back to the originalPID gains.
Put the ch7/ch8 switch into the LOW position then back to the HIGHposition to test the tuned PID gains.
Put the ch7/ch8 switch into the LOW position to fly using theoriginal PID gains.
If you are happy with the autotuned PID gains, leave the ch7/ch8switch in the HIGH position, land and disarm to save the PIDspermanently.
If you DO NOT like the new PIDS, switch ch7/ch8 LOW to return to theoriginal PIDs. The gains will not be saved when you disarm.
If you find after performing an AutoTune that the vehicle feels overly twitchy when flying Stabilize, AltHold or PosHold (but ok in moreautonomous modes like Loiter, RTL, Auto) try increasing the ATC_INPUT_TC parameter to 0.25. This smooths out the pilot’s input.Alternatively try reducing the AUTOTUNE_AGGR parameter (it should always be in the range 0.05 to 0.10) and try again.
If the vehicle feels sloppy after the AutoTune, try increasing the AUTOTUNE_AGGR parameter as high as 0.10 and attempt the autotune again.
Invoke AutoTune with Position Hold¶
In Copter-3.5 (and higher) AutoTune performs a weak position hold if invoked from Loiter or PosHold flight modes (as opposed to AltHold).
- The vehicle will gently lean (up to 10 degrees) towards a “target point” which is initially set to the vehicle’s location at the moment AutoTune was invoked.
- The pilot can reposition the vehicle using the roll, pitch, yaw or throttle sticks. The target position will be reset to the vehicle’s location at the moment the pilot releases the roll and pitch sticks.
- In order to twitch perpendicular to the wind direction, the vehicle may suddenly rotate in either direction up to 90 degrees as it drifts 5m (or more) from the target location.
- If there is little or no wind, the vehicle’s gentle position control may mean it moves back and forth, ping ponging around the target point changing yaw each time it strays more than 5m from the target. In these cases it may be more comfortable to revert the simpler AltHold based AutoTune.
Additional Notes¶
In Copter-3.3 (and higher) AutoTune can be setup as a flight-mode. Switching into or out of the AutoTune flight mode responds in the same way as raising or lowering a ch7/ch8 aux switch high assigned the AutoTune function.
AUTOTUNE_AXES allows control of which axis are to be tuned. This is useful if the vehicle’s battery life is not long enough to complete all 3-axis). “1” = tune roll, “2” = tune pitch, “4” = tune yaw. Add these numbers together to tune multiple axis in a single session (i.e. “7” = tune all axis)
AUTOTUNE_AGGR : Should be in the range of 0.05 to 0.10. Higher values will produce a more aggressive tune but sometimes results in gains that are too high. More specifically this parameter controls the threshold for D-term bounce back and P-term overshoot. This affects the tuning noise immunity (a higher value is more tolerant to flex in the frame or other disturbances that could trick the tuning algorithm). High values also leads to a tune that rejects external disturbances better. Lower values result in a tune that is more responsive to pilot input.
The full list of parameters that may be updated by AutoTune
- Roll angular P gain ATC_ANG_RLL_P
- Roll rate P, I and D gains ATC_RAT_RLL_P, ATC_RAT_RLL_I, ATC_RAT_RLL_D
- Roll max acceleration ATC_ACCEL_R_MAX
- Pitch angular P gain ATC_ANG_PIT_P
- Pitch rate P, I and D gains ATC_RAT_PIT_P, ATC_RAT_PIT_I, ATC_RAT_PIT_D
- Pitch max acceleration ATC_ACCEL_P_MAX
- Yaw angular P gain ATC_ANG_YAW_P
- Yaw rate P, I gain ATC_RAT_YAW_P, ATC_RAT_YAW_I, ATC_RAT_YAW_D
- Yaw rate filter ATC_RAT_YAW_FLTT , ATC_RAT_YAW_FLTE (in AC3.6: ATC_RAT_YAW_FLT)
- Yaw max acceleration ATC_ACCEL_Y_MAX
- Roll and pitch axis rate feed-forward is enabled (ATC_RATE_FF_ENAB)
After you have a good tune, you may wish to increase ATC_THR_MIX_MAX to 0.9 (default is 0.5) to increase prioritization of attitude control over throttle. This can reduce the pitch overshoot sometimes seen (especially on copters with large propellers) in AltHold if the vehicle suddenly slows after performing fast forward flight. In this situation wind catches under the propellers providing lift but also disturbs the vehicle’s attitude leading to a conflict between throttle and attitude control. The danger in increasing this parameter’s value is that if the rate gains are later raised so high that the vehicle oscillates badly it may be difficult for the vehicle to descend (because it will prioritize trying to correct the attitude oscillations and never reduce throttle sufficiently).
AutoTune can request very large and fast changes in outputs to the motors which can cause ESC sync issues especially when using SimonK firmware and/or low KV motors (under 500KV). See this video showing a test which recreates a sync problem.
AutoTune is sometimes unable to find a good tune for frames with very soft vibration dampening of the autopilot or very flexible arms.
For best results the copter shouldn’t be allowed to build up too much horizontal speed. This can be prevented by applying a quick correction between tests (twitches) to stop the vehicle from flying too fast.
Be advised that AutoTune will engage from Stabilize, so don’t accidentally flip your AutoTune switch until you are in AltHold and ready to begin the procedure.
Common Problems¶
- If the vehicle will not start tuning (i.e. it won’t twitch) even though it is in AutoTune mode then the problem is likely that the roll, pitch, yaw or throttle sticks are not exactly in the middle. It may help to increase the deadzone on the RC input by increasing RC1_DZ, RC2_DZ, RC3_DZ and RC4_DZ to 50 (or higher).
- If the AutoTune produces an overly twitchy vehicle try reducing the AUTOTUNE_AGGR parameter (should never be below 0.05) and perform the AutoTune again.
- If the AutoTune produces a sloppy vehicle, try increasing the AUTOTUNE_AGGR parameter (should never be above 0.1) and perform the AutoTune again.
Tip
When reporting issues with AutoTune please include a description of your frame and a dataflash log of the flight.
Dataflash logging¶
ATUN (auto tune overview) and ATDE (auto tune details) messages arewritten to the dataflash logs. Some details of the contents of thosemessages can be found on the Downloading and Analyzing Data Logs in Mission Planner wiki page.
This tutorial explains how to tune the PID loops on PX4 for all multicopter setups (Quads, Hexa, Octo etc).
Generally if you're using a supported specific configuration (e.g. using an airframe in QGroundControl > Airframe) the default tuning should be sufficient to fly the vehicle safely.To get the very best performance it is usually good to tune a new vehicle. For example, different ESCs or motors require different tuning gains for optimal flight.
This guide is for advanced users. Un- or partially- tuned vehicles are likely to be unstable, and easy to crash.Make sure to have a Kill-switch assigned.
Introduction
PX4 uses Proportional, Integral, Derivative (PID) controllers, which are the most widespread control technique.
The controllers are layered, which means a higher-level controller passes itsresults to a lower-level controller. The lowest-level controller is the the ratecontroller, then there is the attitude contoller, and then the velocity& position controller.The PID tuning needs to be done in the same order, starting with the ratecontroller, as it will affect all other controllers.
Preconditions
- You have selected the closest matching default airframe configuration for your vehicle. This should give you a vehicle that already flies.
- You should have done an ESC calibration.
PWM_MIN is set correctly. It needs to be set low, but such that the motors never stop when the vehicle is armed.
This can be tested in Acro mode or in Manual/Stabilized mode:
- Remove propellers
- Arm the vehicle and lower the throttle to the minimum
- Tilt the vehicle to all directions, about 60 degrees
- Check that no motors turn off
- Optionally enable the high-rate logging profile with the SDLOG_PROFILE parameter so you can use the log to evaluate the rate and attitude tracking performance (the option can be disabled afterwards).
Always disable MC_AIRMODE when tuning a vehicle.
Tuning Steps
For safety reasons, the default gains are set to low values.
You must increase the gains before you can expect good control responses.
Pixhawk Auto Tune Pid 1
Here are some general points to follow when tuning:
- All gains should be increased very slowly as large gains may cause dangerous oscillations! Typically increase gains by 20-30% per iteration, reducing to 5-10% for final fine tuning.
- Land before changing a parameter. Slowly increase the throttle and check for oscillations.
- Tune the vehicle around the hovering thrust point, and use the thrust curve parameter or TPA to account for thrust non-linearities or high-thrust oscillations.
Rate Controller
The rate controller is the inner-most loop with three independent PID controllers to control the body rates:
- Roll rate control (MC_ROLLRATE_P, MC_ROLLRATE_I, MC_ROLLRATE_D)
- Pitch rate control (MC_PITCHRATE_P, MC_PITCHRATE_I, MC_PITCHRATE_D)
- Yaw rate control (MC_YAWRATE_P, MC_YAWRATE_I, MC_YAWRATE_D)
A well-tuned rate controller is very important as it affects all flight modes. A badly tuned rate controller will be visible in Position mode, for example, as 'twitches' (the vehicle will not hold perfectly still in the air).
The rate controller can be tuned in Acro mode or Manual/Stabilized mode:
- Acro mode is preferred, but is harder to fly. If you choose this mode, disable all stick expo:
MC_ACRO_EXPO
= 0,MC_ACRO_EXPO_Y
= 0,MC_ACRO_SUPEXPO
= 0,MC_ACRO_SUPEXPOY
= 0MC_ACRO_P_MAX
= 200,MC_ACRO_R_MAX
= 200MC_ACRO_Y_MAX
= 100
- Manual/Stabilized mode is simpler to fly, but it is also more difficult to see if the attitude or the rate controller needs more tuning.
In case your vehicle does not fly at all:
- If you notice strong oscillations when first trying to takeoff (to the point where it does not fly), decrease all P and D gains until it takes off.
- If on the other hand you hardly get any reaction at all to your RC commands, increase the P gains.
The actual tuning is roughly the same in Manual mode or Acro mode:You iteratively tune the P and D gains for roll and pitch, and then the I gain.Initially you can use the same values for roll and pitch, and once you have good values, you can fine-tune them by looking at roll and pitch response separately (if your vehicle is symmetric, this is not needed).For yaw it is very similar, except that D can be left at 0.
P Gain
The P (proportional) gain is used to minimize the tracking error. It is responsible for a quick response and thus should be set as high as possible, but without introducing oscillations.
- If the P gain is too high: you will see high-frequency oscillations.
- If the P gain is too low:
- the vehicle will react slowly to input changes.
- In Acro mode the vehicle will drift, and you will constantly need to correct to keep it level.
D Gain
The D (derivative) gain is used for dampening. It is required but should be set only as high as needed to avoid overshoots.
- If the D gain is too high: the motors become twitchy (and maybe hot), because the D term amplifies noise.
- If the D gain is too low: you see overshoots after a step-input.
I Gain
The I (integral) gain keeps a memory of the error. The I term increases when the desired rate is not reached over some time. It is important (especially when flying Acro mode), but it should not be set too high.
- If the I gain is too high: you will see slow oscillations.
- If the I gain is too low: this is best tested in Acro mode, by tilting the vehicle to one side about 45 degrees, and keeping it like that. It should keep the same angle. If it drifts back, increase the I gain. A low I gain is also visible in a log, when there is an offset between the desired and the actual rate over a longer time.
Typical values are between 0.3 and 0.5, and the pitch gain usually needs to be a bit higher.
Testing Procedure
To test the current gains, provide a fast step-input when hovering and observe how the vehicle reacts. It should immediately follow the command, and neither oscillate, nor overshoot (it feels 'locked-in').
You can create a step-input for example for roll, by quickly pushing the roll stick to one side, and then let it go back quickly (be aware that the stick will oscillate too if you just let go of it, because it is spring-loaded — a well-tuned vehicle will follow these oscillations).
A well-tuned vehicle in Acro mode will not tilt randomly towards one side,but keeps the attitude for tens of seconds even without any corrections.
Logs
Looking at a log helps to evaluate tracking performance as well. Here is an example for good roll and yaw rate tracking:
And here is a good example for the roll rate tracking with several flips, which create an extreme step-input. You can see that the vehicle overshoots only by a very small amount:
Attitude Controller
This controls the orientation and outputs desired body rates with the following tuning parameters:
- Roll control (MC_ROLL_P)
- Pitch control (MC_PITCH_P
- Yaw control (MC_YAW_P)
The attitude controller is much easier to tune. In fact, most of the time the defaults do not need to be changed at all.
To tune the attitude controller, fly in Manual/Stabilized mode and increase the P gains gradually. If you start to see oscillations or overshoots, the gains are too high.
The following parameters can also be adjusted. These determine the maximum rotation rates around all three axes:
- Maximum roll rate (MC_ROLLRATE_MAX)
- Maximum pitch rate (MC_PITCHRATE_MAX
- Maximum yaw rate (MC_YAWRATE_MAX)
Thrust Curve / Throttle PID Attenuation (TPA)
The tuning above optimises performance around the hover throttle. But it can be that you start to see oscillations when going towards full throttle.
There are two ways to counteract that:
Adjust the thrust curve with the THR_MDL_FAC parameter (preferred method).The thrust to PWM mapping is linear by default — setting
THR_MDL_FAC
to 1 makes it quadratic. Values in between use a linear interpolation of the two.Typical values are between 0.3 and 0.5.You can start off with 0.3 and then increase it by 0.1 at a time. If it is too high, you will start to notice oscillations at lower throttle values.The rate controller must be re-tuned if you change this parameter.
Enable Throttle PID Attenuation (TPA), which is used to linearly reduce thePID gains when the throttle isabove a threshold (breakpoint,
MC_TPA_BREAK_*
parameters). The attenuation rate is controlled viaMC_TPA_RATE_*
parameters. TPA should generally not be needed, but it can beused in addition to the thrust curve parameter. The following illustrationshows the thrust in relationship to the attenuated PID values:
Airmode & Mixer Saturation
The rate controller outputs torque commands for all three axis (roll, pitch and yaw) and a scalar thrust value, which need to be converted into individual motor thrust commands. This step is called mixing.
It can happen that one of the motor commands becomes negative, for example for a low thrust and large roll command (and similarly it can go above 100%). This is a mixer saturation. It is physically impossible for the vehicle to execute these commands (except for reversible motors). PX4 has two modes to resolve this:
- Either by reducing the commanded torque for roll such that none of the motor commands isbelow zero (Airmode disabled). In the extreme case where the commanded thrustis zero, it means that no attitude correction is possible anymore, which iswhy a minimum thrust is always required for this mode.
Or by increasing (boosting) the commanded thrust, such that none of the motorcommands is negative (Airmode enabled). This has the big advantage that theattitude/rates can be tracked correctly even at low or zero throttle. Itgenerally improves the flight performance.
However it increases the total thrust which can lead to situations where thevehicle continues to ascend even though the throttle is reduced to zero. For awell-tuned, correctly functioning vehicle it is not the case, but for exampleit can happen when the vehicle strongly oscillates due to too high P tuninggains.
Both modes are shown below with a 2D illustration for two motors and a torquecommand for roll r. On the left motorr is added to the commanded thrust, while onthe right motor it is substracted from it.The motor thrusts are in green.With Airmode enabled, the commanded thrust is increased byb. When it is disabled,r is reduced.
Xfer serum latest version crack. It is very plain and straightforward and effortless to use.
If mixing becomes saturated towards the upper bound the commanded thrust is reduced to ensure that no motor is commanded to deliver more than 100% thrust. This behaviour is similar to the Airmode logic, and is applied whether Airmode is enabled or disabled.
Pixhawk Auto Tune Pid Chart
Once your vehicle flies well you can enable Airmode via the MC_AIRMODE parameter.