PID Tuning

From RepRap
Revision as of 01:00, 22 January 2014 by DaveX (talk | contribs) (Add a PID autotune example and interpret the units of the PID terms.)
Jump to: navigation, search

PID tuning refers to a proportional-integral-derivative control algorithm used in some 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 firmares, run the following gcode with the nozzle cold:

 M303 S200 C8

This will heat the nozzle, and cycle around the target temperature 8 times (C8) at the given temperature (S200) and return 3 values for P I and D. An example from http://www.soliwiki.com/PID_tuning is:

bias: 92 d: 92 min: 196.56 max: 203.75
Ku: 32.59 Tu: 54.92
Clasic PID
Kp: 19.56
Ki: 0.71
Kd: 134.26
PID Autotune finished ! Place the Kp, Ki and Kd constants in the configuration.h

For Marlin, these values indicate the counts of the soft-PWM heater control (0 to 255) for each element of the control equation. 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.

These values can be entered with:

 M301 P1 I2 D3 

If the EEPROM is enabled, save with M500. If it is not enabled, save these settings in Configuration.h.

For the bed, use:

 Bed: M303 E-1 S60 C8 

and save bed settings with:

 M304 P1 I2 D3 

For manual adjustments:

  • 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.


A good article on PID tuning is here

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.