Dlloydev / QuickPID

A fast PID controller with multiple options. Various Integral anti-windup, Proportional, Derivative and timer control modes.
MIT License
195 stars 50 forks source link

Add a simpler overload constructor and new adaptive control functions #38

Closed Dlloydev closed 2 years ago

Dlloydev commented 2 years ago

We already have SetTunings(Kp, Ki, Kd); for adaptive control, so a simpler overload constructor could be provided like this:

 QuickPID(*Input, *Output, *Setpoint);  // defaults are used for remaining parameters

then, for adaptive control:

// existing functions
SetTunings(Kp, Ki, Kd);          // p, i, d gains
SetMode(Mode);                   // Control::manual, Control::automatic, Control::timer
SetControllerDirection(Action);  // Action::direct, Action::reverse

// additional new functions
SetProportionalMode(pMode);      // pMode::pOnError, pMode::pOnMeas, pMode::pOnErrorMeas
SetDerivativeMode(dMode);        // dMode::dOnError, dMode::dOnMeas
SetAntiWindupMode(iAwMode);      // iAwMode::iAwCondition, iAwMode::iAwClamp, iAwMode::iAwOff

example in your main code:

myPID.SetProportionalMode(myPID.pMode::pOnMeas);       // set proportional on measurement mode
myPID.SetDerivativeMode(myPID.dMode::dOnError);        // set derivative on error mode
myPID.SetAntiWindupMode(myPID.iAwMode::iAwCondition);  // set conditional anti-windup mode
guilhermgonzaga commented 2 years ago

I'm willing to do that. Ok with you, @Dlloydev?

Dlloydev commented 2 years ago

Sure ... thank you!

guilhermgonzaga commented 2 years ago

We need to define a default set of gains. Since it's always so specific, I guess p=2 i=5 d=1, as in the examples, is as good as anything.

Any thoughts on this?

Dlloydev commented 2 years ago

I think they could all be zero as default, because these defaults are only for the unused parameters in the constructor and this would match the behavior of PID_v1.

EDIT: @guilhermgonzaga , no rush, the next few weeks will be quite busy (for everyone) ... I won't get a chance to work with this until sometime after the holidays. Also, it's OK if you decide back out for any reason. Thanks again for looking at this!