br3ttb / Arduino-PID-AutoTune-Library

420 stars 225 forks source link

How can a library work? #23

Open neoblack2 opened 4 years ago

neoblack2 commented 4 years ago

We need to strive for setpoint. And in the code at the start of tuning, this is what input was like that - it will be instead of setpoint. And all the time it will float near input.

int PID_ATune::Runtime() { justevaled=false; if(peakCount>9 && running) { running = false; FinishUp(); return 1; } unsigned long now = millis();

if((now-lastTime)<sampleTime) return false;
lastTime = now;
double refVal = *input; --------------------------------------------------------------?
justevaled=true;
if(!running)    ------------------------------------------------ first start
{ //initialize working variables the first time around
    peakType = 0;
    peakCount=0;
    justchanged=false;
    absMax=refVal;
    absMin=refVal;
    setpoint = refVal; ----------------------------------first start setpoint = input ?
    running = true;
    outputStart = *output;
    *output = outputStart+oStep;
}
else
{
    if(refVal>absMax)absMax=refVal;
    if(refVal<absMin)absMin=refVal;
}

if(refVal>setpoint+noiseBand) output = outputStart-oStep; -------------------? input and input ? else if (refVal<setpoint-noiseBand) output = outputStart+oStep; ----------- ? input and input ?

"corrected" output float near input? or maybe near setpoint ???????????

rtek1000 commented 2 years ago

http://brettbeauregard.com/blog/2012/01/arduino-pid-autotune-library/