Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed-rtos mbed-src pixylib
PeriodicPI.cpp
- Committer:
- balsamfir
- Date:
- 2016-03-25
- Revision:
- 6:52686c25e4af
- Parent:
- 5:f655435d0782
- Child:
- 7:5ef312aa2678
File content as of revision 6:52686c25e4af:
#include "PeriodicPI.h"
PeriodicPI::PeriodicPI(float periodSec, float kP, float kI)
{
this->kP = kP;
this->kI = kI;
this->periodSec = periodSec;
}
float PeriodicPI::Run(float error, float bound)
{
// Avoid integrator wind up
if((output >= bound)||(output <= -bound));
else {
integral = integral + error * periodSec;
}
output = kI * (integral) + kP * error ;
// Limit output to bounds
if (output > bound) {
output = bound;
} else if (output < -bound) {
output = -bound;
}
return output;
}
float PeriodicPI::GetIntegral()
{
return integral;
}
float PeriodicPI::GetOutput()
{
return output;
}
