This commit is contained in:
Frank Paynter 2021-05-15 15:32:36 -04:00 committed by GitHub
commit 01cdd6434c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View File

@ -130,6 +130,8 @@ void PID::SetTunings(double Kp, double Ki, double Kd){
/* SetSampleTime(...) *********************************************************
* sets the period, in Milliseconds, at which the calculation is performed
* 15 May 2021 gfp - a value of zero will force Compute() to generate a new output every time it is called
* but avoids the 'divide-by-zero' problem
******************************************************************************/
void PID::SetSampleTime(int NewSampleTime)
{
@ -139,7 +141,11 @@ void PID::SetSampleTime(int NewSampleTime)
/ (double)SampleTime;
ki *= ratio;
kd /= ratio;
SampleTime = (unsigned long)NewSampleTime;
//SampleTime = (unsigned long)NewSampleTime;
}
else if (NewSampleTime == 0)
{
SampleTime = (unsigned long)NewSampleTime;
}
}

View File

@ -9,3 +9,7 @@
http://brettbeauregard.com/blog/2011/04/improving-the-beginners-pid-introduction/
- For function documentation see: http://playground.arduino.cc/Code/PIDLibrary
- To synchronize PID::Compute with an external timing source such as a TIMER ISR,
call SetSampleTime() with an argument of zero. This will force Compute to generate a
new output value each time it is called.