Update PID_v1.cpp
I put the start sample time at is beginning not after the calculus. Taking account the calcul past time and other...
This commit is contained in:
parent
9b4ca0e5b6
commit
6cda038e59
@ -62,6 +62,8 @@ bool PID::Compute()
|
|||||||
unsigned long timeChange = (now - lastTime);
|
unsigned long timeChange = (now - lastTime);
|
||||||
if(timeChange>=SampleTime)
|
if(timeChange>=SampleTime)
|
||||||
{
|
{
|
||||||
|
// take the start sample time
|
||||||
|
lastTime = now;
|
||||||
/*Compute all the working error variables*/
|
/*Compute all the working error variables*/
|
||||||
double input = *myInput;
|
double input = *myInput;
|
||||||
double error = *mySetpoint - input;
|
double error = *mySetpoint - input;
|
||||||
@ -88,7 +90,7 @@ bool PID::Compute()
|
|||||||
|
|
||||||
/*Remember some variables for next time*/
|
/*Remember some variables for next time*/
|
||||||
lastInput = input;
|
lastInput = input;
|
||||||
lastTime = now;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else return false;
|
else return false;
|
||||||
|
Loading…
Reference in New Issue
Block a user