Open
Conversation
Current approach (re-written to be more concise, although possibly less clear): I = I + deltaT * Ki * mean_error; I = (I>limImax) ? limImax : ((I<limImin) ? limiImin : I); /* Calculate out from P, I, and D, then clamp */ out = P + I + D; out = (out>limMax) ? limMax : ((out<limMin) ? limiMin : out); Example where this fails, or at least performs poorly: - Assume P = 90%; D = 0%; I = 20%; limImax=50%; limMax = 100%; /* I < limImax, so no anti-windup is in effect; however ... */ out = P + I + D; /* => 110%, i.e. out is over-saturated */ out - (out>limMax) ? limMax : ...; /* => 100%, out is clamped, but I is not */ New approach: I = I + deltaT * Ki * mean_error; /* Same */ /* Remove static limiting of I */ /* Same */ out = P + I + D; out = (out>limMax) ? limMax : ((out<limMin) ? limiMin : out); /* New - solve for I from [out=P+I+D] above */ I = out - (P + D); /* [I] will not change unless out is being clamped
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
[Just a suggestion]
Current approach (re-written to be more concise, although possibly less clear):
I = I + deltaT * Ki * mean_error;
I = (I>limImax) ? limImax : ((I<limImin) ? limiImin : I);
/* Calculate out from P, I, and D, then clamp */
out = P + I + D;
out = (out>limMax) ? limMax : ((out<limMin) ? limiMin : out);
Example where this fails, or at least performs poorly:
Assume
P = 90%; D = 0%; I = 20%; limImax=50%; limMax = 100%;
/* I < limImax, so no anti-windup is in effect; however ... */
out = P + I + D; /* => 110%, i.e. out is over-saturated /
out - (out>limMax) ? limMax : ...; / => 100%, out is clamped, but I is not */
New approach:
I = I + deltaT * Ki * mean_error; /* Same /
/ Remove static limiting of I */
/* Same */
out = P + I + D;
out = (out>limMax) ? limMax : ((out<limMin) ? limiMin : out);
/* New - solve for I from [out=P+I+D] above /
I = out - (P + D); / [I] will not change unless out is being clamped