Over the last month or so, I’ve dug into the pid calibrate and the pid control sections of the codebase. I’ve come up with some significant, but not blatantly obvious performance improvements. I can only test and validate so much myself, so I wanted to make it available to the community for additional testing and feedback.
pid calibrate
If you set the WRITE_FILE flag when running a tune, you can plot the output and get a good idea of the systems dynamics. The following two plots are of tuning runs on my hotend and bed. For the hotend the calibration temp was 220 and the bed was 40. I chose 40 for the bed, as it’s at the upper end of tpe temps, and is an extreme tuning case that will expose any issue with the tuning algorithm.
What you see above is the output of a standard relay test. If you would like a general overview of what the relay test does, you can read about it [here].(https://d1.amobbs.com/bbs_upload782111/files_36/ourdev_614499E39LAH.pdf).
Both graphs show two undesirable phenomena, bias and asymmetry.
Bias is most easily seen as the difference between the power on and off time. If the system was perfect, the amount of time the power was on would be equal to the amount of time it was off. Since most printers can’t remove heat from the hotend & bed as efficiently as they can add it, the system will never be perfect. Thus, the system will always have some amount of bias. however, a good calibration will minimize bias as much as possible.
Asymmetry is most easily seen as the difference in amplitude of the temperature waveform. If the amplitude of the peaks above and below the target temperature are different, then the system is asymmetric. The more asymmetric a system is the worse the output of the calibration run will be. Thankfully asymmetry, can be controlled by varying the maximum power used during the relay test.
This paper presents several methods that can be used to minimize asymmetry, and bias. I implemented the iterative “Peak Based Correction” method, as it works well with multiple types of systems.
The next two plots are from calibration runs done with the updated algorithm. As you can see, asymmetry have been removed, and bias has been significantly reduced.
comparison of calibration results
Bed:
previous:
pid_Kp=37.957
pid_Ki=0.146
pid_Kd=2469.585
updated:
pid_Kp=10.047
pid_Ki=0.052
pid_Kd=481.684
hotend:
previous:
pid_Kp=20.448
pid_Ki=0.940
pid_Kd=111.188
updated:
pid_Kp=15.647
pid_Ki=0.745
pid_Kd=82.144
The following 2 plots are 20 minute test runs using the old and new calibration parameters for my hotend. For this test the old controller is usesd so we have a like for like comparison. As you can see from plots there is less oscillation across the board.
The old calibration/tune overshoot by 3.58C and took 114.9 seconds to settle in at the target temperature. After reaching the target temperature maximum deviation was +0.51C and -0.46C
The new calibration/tune overshoot by 4.15C and took 127.5 seconds to settle in at the target temperature. After reaching the target temperature maximum deviation was +0.31C and -0.29C
The new calibration/tune overshooting more and taking longer to settle in, is because of a limitation of the controller (more on that later.) However, once it does settle in, it oscillates about the set point significantly less.
To visually show how much better the new calibration is, here is a plot that shows the summation of absolute variance from the target temperature over time.
In my next post (after dinner) I’ll discuss the pid controller.