-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
outputSum typed as int causing float rounding issues #27
Comments
Also, one other note, but don't the lines: Lines 69 to 70 in 11a10e1
reproduce the same functionality as the constrain method used in the next line?Line 71 in 11a10e1
|
Thanks for your comments. Yes, outputSum was intended to be float ... also outMin, outMax, and error. I'll change these to float and publish a new version ASAP. Regarding anti-windup, there is a subtle difference in the two methods ... the early anti-windup was derived from the discussion here. In a future version I may consider a feature to adjust the amount of anti-windup to apply. I read somewhere that a certain percentage will work well with many systems. For some systems, some windup can be tolerated and beneficial. |
Great - thanks maintaining this library! |
Are you referring to this comment?: |
Yes, that's it. |
I think what that comment is proposing is a bit different than your implementation. In the sample code from the comment: iTerm += ki * error;
…
output = pTerm + iTerm + dTerm;
if (output > maxLimit) iTerm -= output – maxLimit;
output = maxLimit; Here, iTerm accumulates over time. However in your code, the iTerm is reset (it does not itself accumulate), but instead is added to the outputSum which is accumulating. In the the comment code, they are doing the 'early' clamp on the Below, i've annotated your clamping code with example values in the comments. You can see that
if you wanted to clamp the integral value separately, I think you would need to accumulate the iTerm value at each |
Thanks for looking at this, much appreciated. Yes, I agree with your analysis. The way it is now, for the first iteration of compute, the outputSum consists of only the iTerm, then the early anti-windup progressively and quickly has less effect on subsequent iterations as the iTerm reaches zero and the outputSum accumulates based on all of the terms. For a future revision, I'll run some tests where the iTerm is accumulated separately and also test a variable anti-windup feature. Regarding the rounding issues, I'll get a new revision out this weekend ... it'll have an update to the analogWrite files, one of the examples and to the variables that need to be changed to float. |
Since outMin and outMax are now floats, please, change SetOutputLimits to accept floats as well. |
Done (QuickPID2.4.9) |
Published new version QuickPID 2.5.0 with an improved anti-windup feature. |
I've been having a lot of trouble with QuickPID after a recent update and finally was able to track down the source of the issue.
QuickPID/src/QuickPID.h
Line 155 in 11a10e1
outputSum
is set to typeint
. This causes the compute method to drop all the fractional values in the calculation:QuickPID/src/QuickPID.cpp
Lines 68 to 73 in 11a10e1
So any fine grain PID value tuning is mostly lost.
I believe this was intended to be of type
float
?The text was updated successfully, but these errors were encountered: