Go to the documentation of this file.00001 #ifndef PID_H_INCLUDED
00002 #define PID_H_INCLUDED
00003
00004 class PID
00005 {
00006 public:
00007 PID()
00008 {
00009 m_iAcc = 0;
00010 m_last = 0;
00011 }
00012
00013 void ResetIntegral()
00014 {
00015 m_iAcc = 0;
00016 }
00017
00018 float Apply(const float command, const float actual)
00019 {
00020
00021 float err = command - actual;
00022 float diff = (err - m_last);
00023 m_last = err;
00024 m_iAcc += err * i;
00025 if (fabs(m_iAcc) > iLim)
00026 {
00027 if (m_iAcc >0)
00028 {
00029 m_iAcc = iLim;
00030 }
00031 else
00032 {
00033 m_iAcc = -iLim;
00034 }
00035 }
00036 return ((err * p) + (diff * d) + m_iAcc);
00037
00038 }
00039
00040 ParameterF p;
00041 ParameterF i;
00042 ParameterF d;
00043 ParameterF iLim;
00044
00045 private:
00046 float m_last;
00047 float m_iAcc;
00048 };
00049
00050
00051 #endif //#ifndef PID_H_INCLUDED
00052