Skip to content
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

Resetting the error-sum on min/max-output can cause oscillations #7

Open
DanielWeigl opened this issue Oct 7, 2020 · 0 comments
Open

Comments

@DanielWeigl
Copy link

At line https://github.com/tekdemo/MiniPID-Java/blob/master/src/com/stormbots/MiniPID.java#L304 you reset the error sum, if the output reaches a limit - but if the output reached the limit because of the I-term going (correctly) towards the limit, then this causes oscillations.

It would (imo) be better to just keep the error sum as is (not resetting and not adding new error)

Example:
green is the I-term and yellow-dotted the output - which should be driven to its upper bound - but the I-term keeps resetting and thus oscilliating.

image

After the red line i made this code change:

        // Figure out what we're doing with the error.
        if (minOutput != maxOutput && !bounded(output, minOutput, maxOutput)) {
            // NOP
            // keep the error sum as is to ensures a smooth transition when the P term
            // decreases enough for the I term to start acting upon the controller
            // From that point the I term will build up as would be expected
        } else if (outputRampRate != 0 && !bounded(output, lastOutput - outputRampRate, lastOutput + outputRampRate)) {
            errorSum = error;
        } else if (maxIOutput != 0) {
            errorSum = constrain(errorSum + error, -maxError, maxError);
            // In addition to output limiting directly, we also want to prevent I term
            // buildup, so restrict the error directly
        } else {
            errorSum += error;
        }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant