Jun 28, 2013 PID tuning theory and configuration guide for MultiWii Now updated for multiwii 1.9 P is the dominant part of PID and gets you in the ballpark for good flight characteristics. Basic PID Tuning - on the ground Set PID to the designers default recommended settings Hold the MulitiRotor securely and safely in the air. This topic is about PID auto tuning algorithm that can tune your Quadcopter from PIDs ZERO as a start value. Introduction Adjusting PIDs is a problem for many of Quadcopter’ pilots, it would be nice to get your quadcopter to adjust PIDs for itself.
English • العربية • български • català • čeština • Deutsch • Ελληνικά • español • فارسی • français • hrvatski • magyar • italiano • română • 日本語 • 한국어 • lietuvių • Nederlands • norsk • polski • português • русский • Türkçe • українська • 中文(中国大陆) • 中文(台灣) • עברית • azərbaycanca • |
PID tuning refers to the parameters adjustment of a proportional-integral-derivative control algorithm used in most repraps for hot ends and heated beds.
PID needs to have a P, I and D value defined to control the nozzle temperature. If the temperature ramps up quickly and slows as it approaches the target temperature, or if it swings by a few degrees either side of the target temperature, then the values are incorrect.
To run PID Autotune in Marlin and other firmwares, run the following G-code with the nozzle cold:
This will heat the first nozzle (E0), and cycle around the target temperature 8 times (C8) at the given temperature (S200) and return values for P I and D. An example from http://www.soliwiki.com/PID_tuning is:
For Marlin, these values indicate the counts of the soft-PWM power control (0 to PID_MAX) for each element of the control equation. The softPWM value regulates the duty cycle of the f=(FCPU/16/64/256/2) control signal for the associated heater. The proportional (P) constant Kp is in counts/C, representing the change in the softPWM output per each degree of error. The integral (I) constant Ki in counts/(C*s) represents the change per each unit of time-integrated error. The derivative (D) constant Kd in counts/(C/s) represents the change in output expected due to the current rate of change of the temperature. In the above example, the autotune routine has determined that to control for a temperature of 200C, the soft PWM should be biased to 92 + 19.56*error + 0.71 * (sum of errors*time) -134.26 * dError/dT. The 'sum of errors*time' value is limited to the range +/-PID_INTEGRAL_DRIVE_MAX as set in Configuration.h. Commercial PID controllers typically use time-based parameters, Ti=Kp/Ki and Td=Kd/Kp, to specify the integral and derivative parameters. In the example above: Ti=19.56/0.71=27.54s, meaning an adjustment to compensate for integrated error over about 28 seconds; Td=134.26/19.56=6.86s, meaning an adjustment to compensate for the projected temperature about 7 seconds in the future.
The Kp, Ki, and Kd values can be entered with:
In the case of multiple extruders (E0, E1, E2) these PID values are shared between the extruders, although the extruders may be controlled separately. If the EEPROM is enabled, save with M500. If it is not enabled, save these settings in Configuration.h.
For the bed, use:
and save bed settings with:
For manual adjustments: Antares 64-bit mac torrent.
- if it overshoots a lot and oscillates, either the integral gain needs to be increased or all gains should be reduced
- Too much overshoot? Increase D, decrease P.
- Response too damped? Increase P.
- Ramps up quickly to a value below target temperature (0-160 fast) and then slows down as it approaches target (160-170 slow, 170-180 really slow, etc) temperature? Try increasing the I constant.
See also Wikipedia's PID_controller and Zeigler-Nichols tuning method. Marlin autotuning (2014-01-20, https://github.com/ErikZalm/Marlin/blob/Marlin_v1/Marlin/temperature.cpp#L250 ) uses the Ziegler-Nichols 'Classic' method, which first finds a gain which maximizes the oscillations around the setpoint, and uses the amplitude and period of these oscillations to set the proportional, integral, and derivative terms.
Saving PID settings
You will need to commit your changes to EEPROM or your configuration.h file for them to be permanent.
To save to EEPROM use:M500
Modifying Marlin Autotune parameters
The default Marlin M303 calculates a set of Ziegler-Nichols 'Classic' parameters based on the Ku (Ultimate Gain) and the Pu (Ultimate Period), where the Ku and Pu are determined by searching for a biased BANG-BANG oscillation around an average power level that produces oscillations centered on the setpoint. (See https://github.com/ErikZalm/Marlin/blob/Marlin_v1/Marlin/temperature.cpp#L238 )
You can transform these 'Classic' parameters into the Zeigler-Nichols 'Some Overshoot' set with:
Or the Z-N 'No Overshoot' set:
Note that the multipliers for the autotuning parameters each have only one significant digit (implying 10% maximum precision), and that the other schemes differ by factors of 2 or 3. PID autotuning and tuning isn't terribly precise, and changes in the parameters by factors of 5 to 50% are perfectly reasonable.
In Marlin, the parameters that control and limit the PID controller can have more significant effects than the popular PID parameters. For example, PID_MAX and PID_FUNCTIONAL_RANGE, and PID_INTEGRAL_DRIVE_MAX can each have dramatic, unexpected effects on PID behavior. For instance, a too-large PID_MAX on a high-power heater can make autotuning impossible; a too-small PID_FUNCTIONAL_RANGE can cause odd reset behavior; a too large PID_FUNCTIONAL_RANGE can guarantee overshoot; and a too-small PID_INTEGRAL_DRIVE_MAX can cause droop.
PID Tuning by Commercial PID
If you have access to a PID controller unit and a compatible thermal probe that fits down into your hotend, you can use them to tune your PID and calibrate your thermistor.
Connection of the output of the PID to your heater varies depending on your electronics. (I used a 1K2:4K7 voltage divider to drop the 22V output of the PID to 5V for my bread-boarded VNP4904)
After the PID is connected you can use it to measure the nozzle temperature and correlate it with the thermistor readings and resistances.
Conversion from the commercial PID values of kP in %fullscale, Ti in seconds, and Td in seconds is as follows:
As an example, a $30 MYPIN TD4-SNR 1/16 DIN PID temperature controller and $10 type-K probe can hold a particular Wildseyed hotend with a 6.8ohm resistor at 185.0C+/-0.1C using 12V with about a 43.7% duty cycle, or 0.437*12*12/6.8=9.25W. Invoking the autotuning on the controller produces these parameters: P=0.8%/C, I=27s, D=6.7s. Converting these to Marlin PID values:
Differences between the results can be caused by physical differences in the systems, (e.g: the thermocouple is closer to the heater than the thermistor,) or by different choices of autotuning parameters (e.g.: the MYPIN TD4 autotuning process is a proprietary black box, while Marlin uses Zeigler-Nichols 'Classic' method.)
The Temperature/resistance table below was developed by using the PID+thermocouple system to set temperatures on a sample hotend by controlling the heater while measuring the thermistor resistance. These values can be used with Nophead's http://hydraraptor.blogspot.com/2012/11/more-accurate-thermistor-tables.html or Marlin's https://github.com/ErikZalm/Marlin/blob/Marlin_v1/Marlin/createTemperatureLookupMarlin.py to create calibrated thermistor tables. The PID column collects the autotuning values produced by the PID controller for the indicated temperature. The kP,Ki,Kd lists the converted parameters.
Temp | DutyCycle | Thermistor R | Commercial PID | Kp,Ki,Kd |
---|---|---|---|---|
60.0 | 6.0 | 31630 | ||
100.0 | 15.7 | 10108 | 1.1%/C, 35.5s, 8.8s | 2.81, 0.08, 3.13 |
120.0 | 22.5 | 5802 | 1.0%/C, 32.0s, 8.0s | 2.55, 0.08, 3.14 |
135.0 | 26.5 | 3967 | ||
150.0 | 28.5 | 2840 | 1.2%/C, 29.0s, 7.2s | 3.06, 0.10, 2.35 |
170.0 | 34.0 | 1829 | ||
185.0 | 43.7 | 1347 | 0.8%/C, 27s, 6.7s | 2.04, 0.08, 3.28 |
190.0 | 45.9 | 1200 | 0.8%/C, 26s, 6.5s | 2.04, 0.08, 3.18 |
200.0 | 51.0 | 977 |
Retrieved from 'https://reprap.org/mediawiki/index.php?title=PID_Tuning&oldid=185897'
Every aspect of flight dynamics is controlled by the selected 'PID controller'. This is an algorithm which isresponsible for reacting to your stick inputs and keeping the craft stable in the air by using the gyroscopes and/oraccelerometers (depending on your flight mode).
The 'PIDs' are a set of tuning parameters which control the operation of the PID controller. The optimal PID settingsto use are different on every craft, so if you can't find someone with your exact setup who will share their settingswith you, some trial and error is required to find the best performing PID settings.
A video on how to recognise and correct different flight problems caused by PID settings is available here:
Basically, the goal of the PID controller is to bring the craft's rotation rate in all three axes to the rate thatyou're commanding with your sticks. An error is computed which is the difference between your target rotation rate andthe actual one measured by the gyroscopes, and the controller tries to bring this error to zero.
##PIDs
The P term controls the strength of the correction that is applied to bring the craft toward the target angle orrotation rate. If the P term is too low, the craft will be difficult to control as it won't respond quickly enough tokeep itself stable. If it is set too high, the craft will rapidly oscillate/shake as it continually overshoots itstarget.
The I term corrects small, long term errors. If it is set too low, the craft's attitude will slowly drift. If it isset too high, the craft will oscillate (but with slower oscillations than with P being set too high).
The D term attempts to increase system stability by monitoring the rate of change in the error. If the error is rapidly converging to zero, the D term causes the strength of the correction to be backed off in order to avoid overshooting the target.
##TPA and TPA Breakpoint
TPA stands for Throttle PID Attenuation and according to AlexYork.net:
'TPA basically allows an aggressively tuned multi-rotor (one that feels very locked in) to reduce its PID gains when throttle is applied beyond the TPA threshold/breakpoint in order to eliminate fast oscillations.'
Note that TPA is set via CLI or on the PID TUNING tab of the GUI. tpa_breakpoint is set via CLI
Also note that TPA and tpa_breakpoint may not be used in certain PID Controllers. Check the description on the individual controller.
TPA applies a PID value reduction in relation to full Throttle. It is used to apply dampening of PID values as full throttle is reached.
TPA = % of dampening that will occur at full throttle.
tpa_breakpoint = the point in the throttle curve at which TPA will begin to be applied.
An Example: With TPA = 50 (or .5 in the GUI) and tpa_breakpoint = 1500 (assumed throttle range 1000 - 2000)
- At 1500 on the throttle channel, the PIDs will begin to be dampened.
- At 3/4 throttle (1750), PIDs are reduced by approximately 25% (half way between 1500 and 2000 the dampening will be 50% of the total TPA value of 50% in this example)
- At full throttle (2000) the full amount of dampening set in TPA is applied. (50% reduction in this example)
- TPA can lead into increase of rotation rate when more throttle applied. You can get faster flips and rolls when more throttle applied due to coupling of PID's and rates. Only PID controllers 1 and 2 are using linear TPA implementation, where no rotation rates are affected when TPA is being used.
How and Why to use this?
If you are getting oscillations starting at say 3/4 throttle, set tpa breakpoint = 1750 or lower (remember, this is assuming your throttle range is 1000-2000), and then slowly increase TPA until your oscillations are gone. Usually, you will want tpa breakpoint to start a little sooner then when your oscillations start so you'll want to experiment with the values to reduce/remove the oscillations.
PID controllers
Cleanflight has 6 built-in PID controllers which each have different flight behavior. Each controller requiresdifferent PID settings for best performance, so if you tune your craft using one PID controller, those settings willlikely not work well on any of the other controllers.
You can change between PID controllers by running
set pid_controller=n
on the CLI tab of the CleanflightConfigurator, where n
is the number of the controller you want to use. Please read these notes first before trying oneout.PID controller 0, 'MultiWii' (default)
PID Controller 0 is the default controller in Cleanflight, and Cleanflight's default PID settings are tuned to bemiddle-of-the-road settings for this controller. It originates from the old MultiWii PID controller from MultiWii 2.2and earlier.
One of the quirks with this controller is that if you increase the P value for an axis, the maximum rotation rates forthat axis are lowered. Hence you need to crank up the pitch or roll rates if you have higher and higher P values.
In Horizon and Angle modes, this controller uses both the LEVEL 'P' and 'I' settings in order to tune theauto-leveling corrections in a similar way to the way that P and I settings are applied to roll and yaw axes in the acroflight modes. The LEVEL 'D' term is used as a limiter to constrain the maximum correction applied by the LEVEL 'P' term.
PID controller 1, 'Rewrite'
PID Controller 1 is a newer PID controller that is derived from the one in MultiWii 2.3 and later. It works better fromall accounts, and fixes some inherent problems in the way the old one worked. From reports, tuning is apparently easieron controller 1, and it tolerates a wider range of PID values well.
Unlike controller 0, controller 1 allows the user to manipulate PID values to tune reaction and stability withoutaffecting yaw, roll or pitch rotation rates (which are tuned by the dedicated roll & pitch and yaw ratesettings).
In Angle mode, this controller uses the LEVEL 'P' PID setting to decide how strong the auto-level correction shouldbe. Note that the default value for P_Level is 90. This is more than likely too high of a value for most, and will cause the model to be very unstable in Angle Mode, and could result in loss of control. It is recommended to change this value to 20 before using PID Controller 1 in Angle Mode.
In Horizon mode, this controller uses the LEVEL 'I' PID setting to decide how much auto-level correction should be applied. Level 'I' term: Strength of horizon auto-level. value of 0.030 in the configurator equals to 3.0 for Level P. Level 'D' term: Strength of horizon transition. 0 is more stick travel on level and 255 is more rate mode what means very narrow angle of leveling.
PID controller 2, 'LuxFloat'
PID Controller 2 is Lux's new floating point PID controller. Both controller 0 and 1 use integer arithmetic, which wasfaster in the days of the slower 8-bit MultiWii controllers, but is less precise.
This controller has code that attempts to compensate for variations in the looptime, which should mean that the PIDsdon't have to be retuned when the looptime setting changes.
There were initially some problems with horizon mode, and sluggishness in acro mode, that were recently fixed bynebbian in v1.6.0.
It is the first PID Controller designed for 32-bit processors and not derived from MultiWii.
The strength of the auto-leveling correction applied during Angle mode is set by the parameter 'level_angle' whichis labeled 'LEVEL Proportional' in the GUI. This can be used to tune the auto-leveling strength in Angle mode compared toHorizon mode. The default is 5.0.
The strength of the auto-leveling correction applied during Horizon mode is set by the parameter 'level_horizon' whichis labeled 'LEVEL Integral' in the GUI. The default is 3.0, which makes the Horizon mode apply weaker self-leveling thanthe Angle mode. Note: There is currently a bug in the Configurator which shows this parameter divided by 100 (so itshows as 0.03 rather than 3.0).
The transition between self-leveling and acro behavior in Horizon mode is controlled by the 'sensitivity_horizon'parameter which is labeled 'LEVEL Derivative' in the Cleanflight Configurator GUI. This sets the percentage of yourstick travel that should have self-leveling applied to it, so smaller values cause more of the stick area to fly usingonly the gyros. The default is 75%
For example, at a setting of '100' for 'sensitivity_horizon', 100% self-leveling strength will be applied at centerstick, 50% self-leveling will be applied at 50% stick, and no self-leveling will be applied at 100% stick. Ifsensitivity is decreased to 75, 100% self-leveling will be applied at center stick, 50% will be applied at 63%stick, and no self-leveling will be applied at 75% stick and onwards.
PID controller 3, 'MultiWii23' (default for the ALIENWIIF1 and ALIENWIIF3 targets)
PID Controller 3 is an direct port of the PID controller from MultiWii 2.3 and later.
The algorithm is handling roll and pitch differently to yaw. Users with problems on yaw authority should try this one.
For the ALIENWII32 targets the gyroscale is removed for even more yaw authority. This will provide best performance on very small multicopters with brushed motors.
PID controller 4, 'MultiWiiHybrid'
PID Controller 4 is an hybrid version of two MultiWii PID controllers. Roll and pitch is using the MultiWii 2.2 algorithm and yaw is using the 2.3 algorithm.
This PID controller was initialy implemented for testing purposes but is also performing quite well.
For the ALIENWII32 targets the gyroscale is removed for more yaw authority. This will provide best performance on very small multicopters with brushed motors.
Multiwii Auto Pid Tuning Parts
PID controller 5, 'Harakiri'
PID Controller 5 is an port of the PID controller from the Harakiri firmware.
The algorithm is leveraging more floating point math. This PID controller also compensates for different looptimes on roll and pitch. It likely don't need retuning of the PID values when looptime is changing. There are two additional settings which are configurable via the CLI in Harakiri:
The PID controller is flight tested and running well with the default PID settings. If you want do acrobatics start slowly.
Multiwii Auto Pid Tuning Tool
Yaw authority is also quite good.
RC rate, Pitch and Roll Rates (P/R rate before they were separated), and Yaw rate
RC Rate
An overall multiplier on the RC stick inputs for pitch, rol;, and yaw.
On PID Controllers 0, and 3-5 can be used to set the 'feel' around center stick for small control movements. (RC Expo also affects this).For PID Controllers 1 and 2, this basically sets the baseline stick sensitivity
Pitch and Roll rates
In PID Controllers 0 and 3-5, the affect of the PID error terms for P and D are gradually lessened as the control sticks are moved away from center, ie 0.3 rate gives a 30% reduction of those terms at full throw, effectively making the stabilizing effect of the PID controller less at stick extremes. This results in faster rotation rates. So for these controllers, you can set center stick sensitivity to control movement with RC rate above, and yet have much faster rotation rates at stick extremes.
For PID Controllers 1 and 2, this is an multiplier on overall stick sensitivity, like RC rate, but for roll and pitch independently. Stablility (to outside factors like turbulence) is not reduced at stick extremes. A zero value is no increase in stick sensitivity over that set by RC rate above. Higher values increases stick sensitivity across the entire stick movement range.
Yaw Rate
In PID Controllers 0 and 5, it acts as a PID reduction as explained above. In PID Controllers 1-4, it acts as a stick sensitivity multiplier, as explained above.