update Compute() so it computes on the first call
This commit is contained in:
parent
9b4ca0e5b6
commit
cccbc9af30
@ -57,10 +57,12 @@ PID::PID(double* Input, double* Output, double* Setpoint,
|
|||||||
**********************************************************************************/
|
**********************************************************************************/
|
||||||
bool PID::Compute()
|
bool PID::Compute()
|
||||||
{
|
{
|
||||||
|
static bool first = true;
|
||||||
|
|
||||||
if(!inAuto) return false;
|
if(!inAuto) return false;
|
||||||
unsigned long now = millis();
|
unsigned long now = millis();
|
||||||
unsigned long timeChange = (now - lastTime);
|
unsigned long timeChange = (now - lastTime);
|
||||||
if(timeChange>=SampleTime)
|
if(first || (timeChange>=SampleTime))
|
||||||
{
|
{
|
||||||
/*Compute all the working error variables*/
|
/*Compute all the working error variables*/
|
||||||
double input = *myInput;
|
double input = *myInput;
|
||||||
@ -89,6 +91,7 @@ bool PID::Compute()
|
|||||||
/*Remember some variables for next time*/
|
/*Remember some variables for next time*/
|
||||||
lastInput = input;
|
lastInput = input;
|
||||||
lastTime = now;
|
lastTime = now;
|
||||||
|
first = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else return false;
|
else return false;
|
||||||
|
Loading…
Reference in New Issue
Block a user