This commit is contained in:
tlatorre-uchicago 2021-01-19 11:50:52 -06:00 committed by GitHub
commit 3585644c77
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -57,10 +57,12 @@ PID::PID(double* Input, double* Output, double* Setpoint,
**********************************************************************************/
bool PID::Compute()
{
static bool first = true;
if(!inAuto) return false;
unsigned long now = millis();
unsigned long timeChange = (now - lastTime);
if(timeChange>=SampleTime)
if(first || (timeChange>=SampleTime))
{
/*Compute all the working error variables*/
double input = *myInput;
@ -89,6 +91,7 @@ bool PID::Compute()
/*Remember some variables for next time*/
lastInput = input;
lastTime = now;
first = false;
return true;
}
else return false;