rllib  1
Public Types | Public Member Functions | Public Attributes | List of all members
rlController Class Reference

#include <rlcontroller.h>

Inheritance diagram for rlController:
Inheritance graph
[legend]
Collaboration diagram for rlController:
Collaboration graph
[legend]

Public Types

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
}
 

Public Member Functions

 rlController (double(*_getMeasurement)(), void(_writeOutput)(double output))
 
 ~rlController ()
 
void start ()
 
void stop ()
 
void setReference (double _reference)
 
void setP (double _T, double _Kp)
 
void setI (double _T, double _T1)
 
void setD_T1 (double _T, double _TD, double _Td)
 
void setPI (double _T, double _Kp, double _Tn)
 
void setPD_T1 (double _T, double _Kp, double _TvP, double _Td)
 
void setPID_T1 (double _T, double _Kpp, double _TnP, double _TvP, double _Td)
 
void setPI_SUM (double _T, double _Kp, double _Tn)
 
void setPD_T1_SUM (double _T, double _Kp, double _Tv, double _Td)
 
void setPID_T1_SUM (double _T, double _Kp, double _Tn, double _Tv, double _Td)
 
void setLimits (double _yk_min, double _yk_max)
 
void resetLimits ()
 
- Public Member Functions inherited from rlThread
 rlThread (int max_semphore=1000)
 
virtual ~rlThread ()
 
int create (void *(*func)(void *), void *argument)
 
int trylock ()
 
int lock ()
 
int unlock ()
 
int waitSemaphore ()
 
int incrementSemaphore ()
 
int join (void **status)
 
int cancel ()
 
void threadExit (void *status)
 

Public Attributes

double Kp
 
double Kpp
 
double T
 
double T1
 
double Td
 
double TD
 
double Tn
 
double TnP
 
double TvP
 
double Tv
 
double reference
 
int type
 
int running
 
double d0
 
double d1
 
double d2
 
double dD
 
double c1
 
double c2
 
double cD
 
double yk
 
double yk_1
 
double yk_2
 
double ek
 
double ek_1
 
double ek_2
 
double y1k
 
double y1k_1
 
double ydk
 
double ydk_1
 
int dt
 
double(* getMeasurement )()
 
void(* writeOutput )(double output)
 
int sleepLocally
 
double measurement
 
double yk_min
 
double yk_max
 
int limited
 
- Public Attributes inherited from rlThread
pthread_t tid
 
pthread_attr_t attr
 
pthread_mutex_t mutex
 
WSEMAPHORE semaphore
 

Detailed Description

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

Definition at line 27 of file rlcontroller.h.

Member Enumeration Documentation

◆ ControllerType

Enumerator
D_T1 
PI 
PD_T1 
PID_T1 
PI_SUM 
PD_T1_SUM 
PID_T1_SUM 

Definition at line 30 of file rlcontroller.h.

Constructor & Destructor Documentation

◆ rlController()

rlController::rlController ( double(*)()  _getMeasurement,
void(_writeOutput)(double output)   
)

Definition at line 79 of file rlcontroller.cpp.

80  :rlThread()
81 {
82  type = -1;
83  running = 0;
84  getMeasurement = _getMeasurement;
85  writeOutput = _writeOutput;
86  ydk_1 = 0.0f;
87  ydk = 0.0f;
88  y1k_1 = 0.0f;
89  y1k = 0.0f;
90  yk_2 = 0.0f;
91  yk_1 = 0.0f;
92  yk = 0.0f;
93  ek_2 = 0.0f;
94  ek_1 = 0.0f;
95  ek = 0.0f;
96  limited = 0;
97  yk_min = -999999;
98  yk_max = 999999;
99  reference = measurement = 0.0;
100  sleepLocally = 1;
101 }
void(* writeOutput)(double output)
Definition: rlcontroller.h:140
double measurement
Definition: rlcontroller.h:154
double(* getMeasurement)()
Definition: rlcontroller.h:136
rlThread(int max_semphore=1000)
Definition: rlthread.cpp:18
double reference
Definition: rlcontroller.h:123

◆ ~rlController()

rlController::~rlController ( )

Definition at line 103 of file rlcontroller.cpp.

104 {
105  stop();
106 }

Member Function Documentation

◆ resetLimits()

void rlController::resetLimits ( )
Reset limits for the controller output

Definition at line 271 of file rlcontroller.cpp.

272 {
273  rlThread::lock();
274  yk_min = -999999;
275  yk_max = 999999;
276  limited = 0;
278 }
int unlock()
Definition: rlthread.cpp:52
int lock()
Definition: rlthread.cpp:47

◆ setD_T1()

void rlController::setD_T1 ( double  _T,
double  _TD,
double  _Td 
)
                            TD * s
Transfer function: Gr(s) = ---------
                           1 + Td*s
T = cycle time in seconds

Definition at line 159 of file rlcontroller.cpp.

160 {
161  rlThread::lock();
162  type = D_T1;
163  T = _T;
164  TD = _TD;
165  Td = _Td;
166  dt = (int) (1000.0 * T);
167  d0 = TD / (Td + T/2.0);
168  d1 = -TD / (Td + T/2.0);
169  c1 = (Td-T/2.0)/(Td+T/2.0);
171 }
int unlock()
Definition: rlthread.cpp:52
int lock()
Definition: rlthread.cpp:47

◆ setI()

void rlController::setI ( double  _T,
double  _T1 
)
                             1
Transfer function: Gr(s) = ------
                           T1 * s
T = cycle time in seconds

Definition at line 146 of file rlcontroller.cpp.

147 {
148  rlThread::lock();
149  type = I;
150  T = _T;
151  T1 = _T1;
152  dt = (int) (1000.0 * T);
153  d0 = T/(2.0*T1);
154  d1 = T/(2.0*T1);
155  c1 = 1.0;
157 }
int unlock()
Definition: rlthread.cpp:52
int lock()
Definition: rlthread.cpp:47

◆ setLimits()

void rlController::setLimits ( double  _yk_min,
double  _yk_max 
)
Set limits for the controller output

Definition at line 262 of file rlcontroller.cpp.

263 {
264  rlThread::lock();
265  yk_min = _yk_min;
266  yk_max = _yk_max;
267  limited = 1;
269 }
int unlock()
Definition: rlthread.cpp:52
int lock()
Definition: rlthread.cpp:47

◆ setP()

void rlController::setP ( double  _T,
double  _Kp 
)
Transfer function: Gr(s) = Kp

Definition at line 135 of file rlcontroller.cpp.

136 {
137  rlThread::lock();
138  type = P;
139  T = _T;
140  Kp = _Kp;
141  dt = (int) (1000.0 * T);
142  d0 = Kp;
144 }
int unlock()
Definition: rlthread.cpp:52
int lock()
Definition: rlthread.cpp:47

◆ setPD_T1()

void rlController::setPD_T1 ( double  _T,
double  _Kp,
double  _TvP,
double  _Td 
)
                                1 + TvP*s
Transfer function: Gr(s) = Kp * ---------
                                1 + Td*s
T = cycle time in seconds

Definition at line 187 of file rlcontroller.cpp.

188 {
189  rlThread::lock();
190  type = PD_T1;
191  T = _T;
192  Kp = _Kp;
193  TvP = _TvP;
194  Td = _Td;
195  dt = (int) (1000.0 * T);
196  d0 = Kp * (TvP+T/2.0) / (Td + T/2.0);
197  d1 = -Kp * (TvP - T/2.0) / (Td + T/2.0);
198  c1 = (Td - T/2.0)/(Td + T/2.0);
200 }
int unlock()
Definition: rlthread.cpp:52
int lock()
Definition: rlthread.cpp:47

◆ setPD_T1_SUM()

void rlController::setPD_T1_SUM ( double  _T,
double  _Kp,
double  _Tv,
double  _Td 
)
                                        Tv*s
Transfer function: Gr(s) = Kp * ( 1 + -------- )
                                      1 + Td*s
T = cycle time in seconds

Definition at line 232 of file rlcontroller.cpp.

233 {
234  rlThread::lock();
235  type = PD_T1_SUM;
236  T = _T;
237  Kp = _Kp;
238  Tv = _Tv;
239  Td = _Td;
240  dt = (int) (1000.0 * T);
241  dD = Kp * (Tv/(Td+T/2.0));
242  cD = (Td-T/2.0)/(Td+T/2.0);
244 }
int unlock()
Definition: rlthread.cpp:52
int lock()
Definition: rlthread.cpp:47

◆ setPI()

void rlController::setPI ( double  _T,
double  _Kp,
double  _Tn 
)
                                1 + Tn*s
Transfer function: Gr(s) = Kp * --------
                                 Tn*s
T = cycle time in seconds

Definition at line 173 of file rlcontroller.cpp.

174 {
175  rlThread::lock();
176  type = PI;
177  T = _T;
178  Kp = _Kp;
179  Tn = _Tn;
180  dt = (int) (1000.0 * T);
181  d0 = Kp * (Tn+T/2.0) / Tn;
182  d1 = -Kp * (Tn - T/2.0) / Tn;
183  c1 = 1.0;
185 }
int unlock()
Definition: rlthread.cpp:52
int lock()
Definition: rlthread.cpp:47

◆ setPI_SUM()

void rlController::setPI_SUM ( double  _T,
double  _Kp,
double  _Tn 
)
                                       1
Transfer function: Gr(s) = Kp * ( 1 + ---- )
                                      Tn*s
T = cycle time in seconds

Definition at line 220 of file rlcontroller.cpp.

221 {
222  rlThread::lock();
223  type = PI_SUM;
224  T = _T;
225  Kp = _Kp;
226  Tn = _Tn;
227  dt = (int) (1000.0 * T);
228  d1 = Kp * (T/2.0)/Tn;
230 }
int unlock()
Definition: rlthread.cpp:52
int lock()
Definition: rlthread.cpp:47

◆ setPID_T1()

void rlController::setPID_T1 ( double  _T,
double  _Kpp,
double  _TnP,
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

Definition at line 202 of file rlcontroller.cpp.

203 {
204  rlThread::lock();
205  type = PID_T1;
206  T = _T;
207  Kpp = _Kpp;
208  TnP = _TnP;
209  TvP = _TvP;
210  Td = _Td;
211  dt = (int) (1000.0 * T);
212  d0 = Kpp * ((TnP+T/2.0) / TnP) * ((TvP+T/2.0))/(Td+T/2.0);
213  d1 = -2.0*Kpp * (TnP*TvP - (T/2.0)*(T/2.0)) / (TnP*(Td+T/2.0));
214  d2 = Kpp*((TnP-T/2.0)/TnP)*((TvP-T/2.0)/(Td+T/2.0));
215  c1 = 2*Td/(Td+T/2.0);
216  c2 = -(Td-T/2.0)/(Td+T/2.0);
218 }
int unlock()
Definition: rlthread.cpp:52
int lock()
Definition: rlthread.cpp:47

◆ setPID_T1_SUM()

void rlController::setPID_T1_SUM ( double  _T,
double  _Kp,
double  _Tn,
double  _Tv,
double  _Td 
)
                                       1       Tv*s
Transfer function: Gr(s) = Kp * ( 1 + ---- + -------- )
                                      Tn*s   1 + Td*s
T = cycle time in seconds

Definition at line 246 of file rlcontroller.cpp.

247 {
248  rlThread::lock();
249  type = PID_T1_SUM;
250  T = _T;
251  Kp = _Kp;
252  Tn = _Tn;
253  Tv = _Tv;
254  Td = _Td;
255  dt = (int) (1000.0 * T);
256  d1 = Kp*T/(2.0*Tn);
257  dD = Kp * (Tv/(Td+T/2.0));
258  cD = (Td-T/2.0)/(Td+T/2.0);
260 }
int unlock()
Definition: rlthread.cpp:52
int lock()
Definition: rlthread.cpp:47

◆ setReference()

void rlController::setReference ( double  _reference)
Set the reference value for the controller

Definition at line 130 of file rlcontroller.cpp.

131 {
132  reference = _reference;
133 }
double reference
Definition: rlcontroller.h:123

◆ start()

void rlController::start ( )

Definition at line 108 of file rlcontroller.cpp.

109 {
110  running = 1;
111  ydk_1 = 0.0f;
112  ydk = 0.0f;
113  y1k_1 = 0.0f;
114  y1k = 0.0f;
115  yk_2 = 0.0f;
116  yk_1 = 0.0f;
117  yk = 0.0f;
118  ek_2 = 0.0f;
119  ek_1 = 0.0f;
120  ek = 0.0f;
122 }
int create(void *(*func)(void *), void *argument)
Definition: rlthread.cpp:35
static void * control(void *arg)

◆ stop()

void rlController::stop ( )

Definition at line 124 of file rlcontroller.cpp.

125 {
127  running = 0;
128 }
int cancel()
Definition: rlthread.cpp:78

Member Data Documentation

◆ c1

double rlController::c1

Definition at line 127 of file rlcontroller.h.

◆ c2

double rlController::c2

Definition at line 127 of file rlcontroller.h.

◆ cD

double rlController::cD

Definition at line 127 of file rlcontroller.h.

◆ d0

double rlController::d0

Definition at line 126 of file rlcontroller.h.

◆ d1

double rlController::d1

Definition at line 126 of file rlcontroller.h.

◆ d2

double rlController::d2

Definition at line 126 of file rlcontroller.h.

◆ dD

double rlController::dD

Definition at line 126 of file rlcontroller.h.

◆ dt

int rlController::dt

Definition at line 131 of file rlcontroller.h.

◆ ek

double rlController::ek

Definition at line 129 of file rlcontroller.h.

◆ ek_1

double rlController::ek_1

Definition at line 129 of file rlcontroller.h.

◆ ek_2

double rlController::ek_2

Definition at line 129 of file rlcontroller.h.

◆ getMeasurement

double(* rlController::getMeasurement) ()
You have to supply this function for getting the measurement

Definition at line 136 of file rlcontroller.h.

◆ Kp

double rlController::Kp
Don't set the controller parameters directly
Use the set methods, because they will also set the coefficients
Controller parameters are for reading only

Definition at line 123 of file rlcontroller.h.

◆ Kpp

double rlController::Kpp

Definition at line 123 of file rlcontroller.h.

◆ limited

int rlController::limited

Definition at line 160 of file rlcontroller.h.

◆ measurement

double rlController::measurement
last measurement 

Definition at line 154 of file rlcontroller.h.

◆ reference

double rlController::reference

Definition at line 123 of file rlcontroller.h.

◆ running

int rlController::running

Definition at line 125 of file rlcontroller.h.

◆ sleepLocally

int rlController::sleepLocally
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

Definition at line 150 of file rlcontroller.h.

◆ T

double rlController::T

Definition at line 123 of file rlcontroller.h.

◆ T1

double rlController::T1

Definition at line 123 of file rlcontroller.h.

◆ Td

double rlController::Td

Definition at line 123 of file rlcontroller.h.

◆ TD

double rlController::TD

Definition at line 123 of file rlcontroller.h.

◆ Tn

double rlController::Tn

Definition at line 123 of file rlcontroller.h.

◆ TnP

double rlController::TnP

Definition at line 123 of file rlcontroller.h.

◆ Tv

double rlController::Tv

Definition at line 123 of file rlcontroller.h.

◆ TvP

double rlController::TvP

Definition at line 123 of file rlcontroller.h.

◆ type

int rlController::type

Definition at line 124 of file rlcontroller.h.

◆ writeOutput

void(* rlController::writeOutput) (double output)
You have to supply this function for writing the output

Definition at line 140 of file rlcontroller.h.

◆ y1k

double rlController::y1k

Definition at line 130 of file rlcontroller.h.

◆ y1k_1

double rlController::y1k_1

Definition at line 130 of file rlcontroller.h.

◆ ydk

double rlController::ydk

Definition at line 130 of file rlcontroller.h.

◆ ydk_1

double rlController::ydk_1

Definition at line 130 of file rlcontroller.h.

◆ yk

double rlController::yk

Definition at line 128 of file rlcontroller.h.

◆ yk_1

double rlController::yk_1

Definition at line 128 of file rlcontroller.h.

◆ yk_2

double rlController::yk_2

Definition at line 128 of file rlcontroller.h.

◆ yk_max

double rlController::yk_max

Definition at line 159 of file rlcontroller.h.

◆ yk_min

double rlController::yk_min
limits 

Definition at line 158 of file rlcontroller.h.


The documentation for this class was generated from the following files: