Return PID temp_dState update logic to 2.0.x behaviour #26926
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR alters the PID algorithm slightly so it matches the behaviour it had in version 2.0.x
A while back up updated my firmware to version 2.1.x and noticed that my printer was not smoothly heating to it's target temp. Instead there was a small dip just before reaching the target temp. It turned out that as soon as the temp entered the
PID_FUNCTIONAL_RANGE
the heater would immediately and completely shut off. Debugging the PID values withM303 D
I found that thedTerm
akawork_d
was going to around -5000 whereas in the 2.0.x version it would start off at about -10.Digging through the code I found that the logic of the PID code was slightly changed. In version 2.0.x the value of the
temp_dState
would be set to the current temperature of the heater every iteration of the algorithm, regardless of whether the current temperature was within the bounds ofPID_FUNCTIONAL_RANGE
. In version 2.1.x this value is only set when the temperature was within these bounds. The result of this is that on the first iteration where the current temperature lies within the functional range, the difference betweentemp_dState
andcurrent
is really large becausetemp_dState
is initialized to 0 on boot. (for example: when heating to 200C with a functional range of 10, this difference would be 190). This in turn causes thework_d = work_d + PID_K2 * (Kd * (temp_dState - current) - work_d);
formula to generate a rather large negative value (in my case around -5000). With the defaultPID_K1
smoothing factor of 0.95 it takes a little while for this large negative value to be corrected, which was the cause for the dip I experienced when heating.Now I am a programmer, but I know very little about c++ or PID. I simply looked at the differences between the 2 versions and restored the original behaviour. Since I'm experiencing better results with the old behaviour I'm looking at this as a "regression", but I have no idea if this change in behaviour was intentional or not. I'm curious to know 😄 .
For reference, this is de code from version 2.0.x I compared to:
Note how
temp_dState[ee] = temp_hotend[ee].celsius;
is called outside of the if, else-if, else branch.Benefits
Should result in more reliable PID heating? (it works on my machine 😆)
Configurations
I have no idea if this would help, but this is my current config:
Configuration.zip
Related Issues
Could not find any