PID Autotune

Roxy

New Member
#2
Marlin has a PID Autotune function for the extruders and the bed. It has nothing to do with the slicer you are using.

The auto tune feature heats up the specified bed or nozzle and watches the temperature curve as it does so... From this information it is able to deduce the 'correct' PID (Proportional, Integral, Differential) constants such that the PID algorithm will very quickly correct errors with very minimal overshoot.

You can use the M303 command to obtain the PID constants for the bed or nozzle. You can either rebuild the firmware with these constants as the default or you can use the M301 command to set them and then save them in the EEPROM .


/**
* M303: PID relay autotune
*
* S<temperature> sets the target temperature. (default 150C)
* E<extruder> (-1 for the bed) (default 0)
* C<cycles>
* U<bool> with a non-zero value will apply the result to current settings
*/
inline void gcode_M303() {
#if HAS_PID_HEATING
int e = code_seen('E') ? code_value_int() : 0;
int c = code_seen('C') ? code_value_int() : 5;
bool u = code_seen('U') && code_value_bool();

float temp = code_seen('S') ? code_value_temp_abs() : (e < 0 ? 70.0 : 150.0);

if (e >= 0 && e < HOTENDS)
target_extruder = e;

KEEPALIVE_STATE(NOT_BUSY); // don't send "busy: processing" messages during autotune output

thermalManager.PID_autotune(temp, e, c, u);

KEEPALIVE_STATE(IN_HANDLER);
#else
SERIAL_ERROR_START;
SERIAL_ERRORLNPGM(MSG_ERR_M303_DISABLED);
#endif
}