-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Expose integral for user-space anti-windup access #132
base: master
Are you sure you want to change the base?
Conversation
Here's a sample user-space anti-windup scheme on that example:
And a simulation using it: |
I encourage you to use Serial.print to output the Setpoint,Input,Output,
and GetIntegral() over time. what you see might surprise you. Because of the
way that the integral is calculated
<http://brettbeauregard.com/blog/2011/04/improving-the-beginner%E2%80%99s-pid-tuning-changes/>,
outputSum isn't some abstract number as it might be in a different
algorithm, where it's held and constantly multiplied by Ki. Instead, it's
going to be on the same scale as the Output. if you have
SetOutputLimits(0,255), not only is the output going to stay within 0-255,
so is outputSum.
This difference in how integral is calculated makes many of the published
windup limiting methods either unnecessary or not-applicable. Windup, in
the traditional sense
<http://brettbeauregard.com/blog/2011/04/improving-the-beginner%e2%80%99s-pid-reset-windup/>,
means that the integral has continued to grow despite no longer having an
impact on the output (which is limited.) This algorithm doesn't do that.
In the hobby space, perhaps because some poorly-written versions DO wind
up, windup seems to have become shorthand for "the output isn't doing what
I want it to do". That's a legitimate issue. Often-times it can be
corrected by tuning, but tuning well can be really hard. (There's a reason
the company I work for makes good money selling tuning software!) In a
hobby situation, where you have access to the code, it's just easier (and
relatively harmless) to just hack the output into submission.
When it comes to this library, however, I just can't rationalize rolling
in changes like this. 1) There's already a way to "pick up and move" the
output to where it needs to be (mode=manual,change output, mode=auto) 2) I
worked hard to make this library easy to use/implement. Every additional
setting/function makes it more complex, so the value-add needs to match.
That being said, I LOVE LOVE LOVE that the people that want to just hack in
their change are free to do so. Just because I'm precious about this
doesn't mean that the hackers of the world need to suffer!
…On Thu, Mar 2, 2023 at 4:42 PM drf5n ***@***.***> wrote:
Here's a sample user-space anti-windup scheme on that example:
// user-space anti-windup method:
if((myPID.Get(Kp) * (Setpoint-Input) + myPID.GetIntegral())>255){
myPID.SetIntegral(0); // PD only below proportional zone
}
—
Reply to this email directly, view it on GitHub
<#132 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AACYX4VSIW4CCO4LWGJFJODW2EH5JANCNFSM6AAAAAAVN4PYSI>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
--
Brett
|
Thanks. How about just adding a GetIntegral() ? I love the way your code does the integration into the output units into outputSum. That simplifies so many things. Other code that doesn't maintain the integral state variable in output units makes it much harder to tune their workarounds with things like SetIntegralLimits (would one update integral limits if you change Ki. What I really like about this change compared to many of the other suggestions is that it doesn't change or complicate the PID::Compute() loop. Reading your note I see that my
But Example code using this user space
|
I proposed a simpler change at #133 It exposes already-existing private functions Initialize() and outputSum at zero cost, and would make this PR redundant. |
This simulation enables exactly that by adding GetIntegral() to its copy of the PID_v1 code (Otherwise, the integral is inaccessible.): https://wokwi.com/projects/358190033668210689 There's a slide-pot to vary the setpoint, and the button kicks the integral with the user-space MANUAL-change-AUTOMATIC trick. What has been surprising to me is how different PID_v1 behaves compared to simple commercial PIDs and how different the tuning might need to be. How does a cheap Amazon PID controller still differ from PID_v1? |
This code adds
See https://wokwi.com/projects/358122536159671297 for a live simulation on Wokwi
These two functions provide access to the integrator to enable user-space monitoring and anti-windup schemes.
In response to Issue #125