Redeem is quickly becoming the standard in 3D printer firmwares with self documenting G-codes and pre-processing path planner. Up until recently, two fairly standard features have had somewhat sub-par performance: PID auto-tune and automatic bed calibration. A recent poll on the Thing-printer G+ page revealed that these two things were on the top of list of things to improve, so in this article and the next, the new improvements will be documented.
When work started on the PID auto tune code, a few bugs and issues were discovered. Here is a quick rundown of the most important changes.
- Non standard implementation of the PID algorithm.
- Got rid of the 'derivative kick'
- Implemented Steinhart-Hart algorithm
- Decimal numbers on temperature
- Current set point reported.
- Implemented M301
The old implementation had something akin to a mix between the standard and the ideal form. The PID algorithm is quite robust to tuning errors, so it was still possible to tune it well with the old implementation, but the current implementation is now a clean standard form implementation, which is what is most used in the industry. That makes it easy to test out new auto tuning calculations, if one was so inclined. Here is the standard formula for reference, taken from Wikipedia:
Due to this switch, some parameters in the config files have changed:
"pid_p_E" changes to "pid_Kp_E"
"pid_i_E" changes to "pid_Ti_E"
"pid_d_E" changes to "pid_Td_E"
Furthermore, some nice improvements to the code were added, like decimal temperature reporting and set point reporting. Mainly these improvements were for debugging during testing, but they are nice to have either way.
A big change for anyone doing configuration of their printer is the change from table based lookup of temperature to using the Steinhart-Hart algorithm for calculating temperature. This should add accuracy to the temperature and also simplify adding new sensors, since it is no longer necessary to generate a lookup table with a script.
As a result of this, some other important settings have been changed in the config files.
"temp_chart_E" changes to "sensor_E"
All the config changes are present in the new default.cfg file. If one of the old style configs are found in either printer.cfg or local.cfg, a warning will be given during startup. Please check the log after upgrading.
Documentation of new M303 interface
The G-code M303 has a slightly updated interface compared to the previous versions. Btw, if at any time you need the most up to date documentation for a G-code in Redeem, simply write add a question mark after the G-code, for example: "M303?"
Send: M303? Recv: PID Tuning refers to a control algorithm used in some repraps to tune heating behavior for hot ends and heated beds. This command generates Proportional (Kp), Integral (Ki), and Derivative (Kd) values for the hotend or bed (E-1). Send the appropriate code and wait for the output to update the firmware. E overrides the extruder. Use E-1 for heated bed. Recv: Default is the 'E' extruder with index 0. Recv: S overrides the temperature to calibrate for. Default is 200. Recv: C overrides the number of cycles to run, default is 4 Recv: P (0,1) Enable pre-calibration. Useful for systems with very high power Recv: Q Tuning algorithm. 0 = Tyreus-Luyben, 1 = Zieger-Nichols classic
Improvements over other implementations
When doing experiments with the new auto tune routine, much advice and inspiration was drawn from the works of Ryan Carlyle, an eager Replicape user and RepRap contributor. One thing in particular he recommended was to add a pre-calibration routine, to figure out the rise time and fall time for the temperature of the hot end. This in turn can be used as a better starting point for the actual calibration cycles by estimating the rise and fall times ahead. A positive side-effect of the pre-calibration is that the amount of over-shoot typically experienced in a naïve bang-bang auto tune cycle diminishes. This can prevent filament from charcoaling due to excess temperatures.
The experiment did work, and can be tested out with the P-parameter added to M303. However, the formula relies on Newton's law of cooling which breaks in the face of forced convection (IE a fan blowing on or near the hot end). Thus to get good results, make sure you disable the automatic cold end fan that most hot ends use.
The result of the experimental tuning method can be seen in the header image. The important part is the pre-calibrate routine, something along the lines of:
- Heat with 25% power to determine the maximum heat-up rate and dead-time.
- Heat with full power until calibration temp is reached, minus the dead time.
- Wait until peak temp is reached, then record the slope of the falling temperature graph a number of times.
- Calculate the relationship between the heat-up rise time and the cool-down time to get a starting point for calibration.
The routine in the header image goes on to try and set the steady state temperature using the calculated values before calibrating with a bang-bang type calibration and the finally testing the resulting values.
The new algorithm also allows for specifying which type of tuning parameters are used. Right now, only Tyreus-Luyben and Zieger-Nichols classic are implemented, but other values are easily added, and pull requests are welcome!