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

When the tunings are changed, it might be good to reset the integrals. #125

Open
rtek1000 opened this issue Sep 26, 2022 · 9 comments
Open

Comments

@rtek1000
Copy link

Hello, when the tunings are changed, it might be good to reset the integrals.

Code:
https://github.com/br3ttb/Arduino-PID-Library/blob/master/examples/PID_AdaptiveTunings/PID_AdaptiveTunings.ino

    myPID.SetMode(MANUAL);
    Output = 0;
    myPID.SetMode(AUTOMATIC);

Ref.:
https://forum.arduino.cc/t/using-arduino-pid-library-reseting-integrals/296451

@mrx23dot
Copy link

mrx23dot commented Nov 2, 2022

will be taken care of in the next task cycle, no need to duplicate code.

@drf5n
Copy link

drf5n commented Feb 22, 2023

@rtek1000
Copy link
Author

In my case, resetting the integral helped a lot, it reduced the overshoot a lot.

@br3ttb
Copy link
Owner

br3ttb commented Feb 26, 2023 via email

@drf5n
Copy link

drf5n commented Feb 26, 2023

Is this issue about overshoot? Or is it about SetTunings? I can't imagine the use-case for making SetTunings non- bumpless. I often operate heaters with PV far from zero, and resetting the integral to zero in SetTuning() would induce a bump.

If overshoot, I could see doing an integral reset to zero when crossing into the proportional zone at (SP-PV)>=outMax/kP.

@rtek1000
Copy link
Author

I used two parameters and they are toggled when the input is close to the setpoint.

Below 2.5 degrees uses a softer parameter, above 2.5 degrees difference uses a more aggressive parameter.

I saw an additional function in another library, maybe it's related to this behavior.

AutoPID::setBangBang

Ref.: AutoPID

@drf5n
Copy link

drf5n commented Feb 26, 2023

Setting a high proportional constant (e.g. Kp=255, Kp=1e6...) makes the proportional band narrow, and then PID acts like bang-bang because either kPerror>outMax or kPerror<outMin.

Looks like AutoPID doesn't do anything at all to limit the integral:

https://github.com/r-downing/AutoPID/blob/fea6b99a4f05f2b53669d684fae6fe09b5391754/AutoPID.cpp#L43-L69

Maybe it behaves as a sort of conditional integration, where integration is depends on being within the band.

AutoPID does expose the integral, so a user could periodically check if it was wound up above outMax or outMax-error*Kp, etc., and reset it as desired.

@drf5n
Copy link

drf5n commented Mar 2, 2023

I was playing around with it and added a SetIntegral(double) and GetIntegral(double) in this sample at Wokwi:

https://wokwi.com/projects/358122536159671297

image

(If you play with it, be sure to toggle the SerialMonitor/SerialPlotter graph icon in the lower right corner.

I added a pull request: #132

@drf5n
Copy link

drf5n commented Mar 11, 2023

A smaller change to the library than #132 adding functions is to move the PID_v1.h:: outputSum variable from private up to public, which enables all sorts user-space tricks.

PR #133 -- Expose integral to enable user-space hacking:

It has a live example at https://wokwi.com/projects/358190033668210689

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

4 participants