/*************************************************************************** rlcontroller.h - description ------------------- begin : Wed Jun 16 2004 copyright : (C) 2004 by R. Lehrig email : lehrig@t-online.de ***************************************************************************/ /*************************************************************************** * * * This library is free software; you can redistribute it and/or modify * * it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE as * * published by the Free Software Foundation * * * ***************************************************************************/ #ifndef _RL_CONTROLLER_H_ #define _RL_CONTROLLER_H_ #include "rldefine.h" #include "rlthread.h" /*!
class for closed loop control
According to: F. Doerrscheid/W. Latzel, Grundlagen der Regelungstechnik, B.G. Teubner Stuttgart
Page 436-437, Regelalgorithmen mit der Trapezregel
*/ class rlController : public rlThread { public: enum ControllerType { P = 1, I = 2, D_T1 = 3, PI = 4, PD_T1 = 5, PID_T1 = 6, PI_SUM = 7, PD_T1_SUM = 8, PID_T1_SUM = 9 }; rlController(double (*_getMeasurement)() ,void (_writeOutput)(double output)); ~rlController(); void start(); void stop(); /*!
  Set the reference value for the controller
  
*/ void setReference (double _reference); /*!
  Transfer function: Gr(s) = Kp
  
*/ void setP (double _T, double _Kp); /*!
                               1
  Transfer function: Gr(s) = ------
                             T1 * s
  T = cycle time in seconds
  
*/ void setI (double _T, double _T1); /*!
                              TD * s
  Transfer function: Gr(s) = ---------
                             1 + Td*s
  T = cycle time in seconds
  
*/ void setD_T1 (double _T, double _TD, double _Td); /*!
                                  1 + Tn*s
  Transfer function: Gr(s) = Kp * --------
                                   Tn*s
  T = cycle time in seconds
  
*/ void setPI (double _T, double _Kp, double _Tn); /*!
                                  1 + TvP*s
  Transfer function: Gr(s) = Kp * ---------
                                  1 + Td*s
  T = cycle time in seconds
  
*/ void setPD_T1 (double _T, double _Kp, double _TvP, double _Td); /*!
                                   1 + TnP*s   1 + TvP*s
  Transfer function: Gr(s) = Kpp * --------- * ---------
                                     TnP*s     1 + Td*s
  T = cycle time in seconds
  
*/ void setPID_T1 (double _T, double _Kpp, double _TnP, double _TvP, double _Td); /*!
                                         1
  Transfer function: Gr(s) = Kp * ( 1 + ---- )
                                        Tn*s
  T = cycle time in seconds
  
*/ void setPI_SUM (double _T, double _Kp, double _Tn); /*!
                                          Tv*s
  Transfer function: Gr(s) = Kp * ( 1 + -------- )
                                        1 + Td*s
  T = cycle time in seconds
  
*/ void setPD_T1_SUM (double _T, double _Kp, double _Tv, double _Td); /*!
                                         1       Tv*s
  Transfer function: Gr(s) = Kp * ( 1 + ---- + -------- )
                                        Tn*s   1 + Td*s
  T = cycle time in seconds
  
*/ void setPID_T1_SUM (double _T, double _Kp, double _Tn, double _Tv, double _Td); /*!
  Set limits for the controller output
  
*/ void setLimits(double _yk_min, double _yk_max); /*!
  Reset limits for the controller output
  
*/ void resetLimits(); /*!
  Don't set the controller parameters directly
  Use the set methods, because they will also set the coefficients
  Controller parameters are for reading only
  
*/ double Kp,Kpp,T,T1,Td,TD,Tn,TnP,TvP,Tv,reference; int type; int running; double d0,d1,d2,dD; double c1,c2,cD; double yk,yk_1,yk_2; double ek,ek_1,ek_2; double y1k,y1k_1,ydk,ydk_1; int dt; // callbacks /*!
  You have to supply this function for getting the measurement
  
*/ double (*getMeasurement)(); /*!
  You have to supply this function for writing the output
  
*/ void (*writeOutput)(double output); /*!
  Default sleepLocally = 1
  But:
  Sleeping locally might me inaccurate.
  It might be better to have a central timer and wait for it in
  double (*_getMeasurement)();
  T = cycle time in seconds
  
*/ int sleepLocally; /*!
  last measurement 
  
*/ double measurement; /*!
  limits 
  
*/ double yk_min; double yk_max; int limited; }; #endif