Regler von Kellep15

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers PID_Cntrl.cpp Source File

PID_Cntrl.cpp

00001 /*
00002     PID-T1 Controller class
00003 
00004                       1           s
00005       G(s) = Kp + Ki --- + Kd ---------
00006                       s       T_f*s + p
00007 
00008     Eigther reseting the Nucleo via the black button or save a new software on 
00009     the Nucleo sets the analog output to zero. Zero is equal to -4 Ampere!!!
00010     Therefor: NEVER !!! reset or save a new software while the VC is powered on
00011     (the green button on the VC is glowing green)                      
00012 
00013 */
00014 
00015 #include "PID_Cntrl.h"
00016 using namespace std;
00017 
00018 PID_Cntrl::PID_Cntrl(float Kp, float Ki, float Kd, float Tf, float Ts, float yMin, float yMax)
00019 {
00020     // link member variables
00021     this->Kp = Kp;
00022     this->Ki = Ki;
00023     this->Tf = Tf;
00024     this->Ts = Ts;
00025     this->yMin = yMin;
00026     this->yMax = yMax;
00027     
00028     reset(0.0f);
00029 }
00030 
00031 PID_Cntrl::~PID_Cntrl() {}
00032 
00033 void PID_Cntrl::reset(float initValue)
00034 {
00035 
00036     // implement controller reset
00037     e_old = 0.0;
00038     y_Dold = 0.0;
00039     y_I = initValue; 
00040 }
00041 
00042 float PID_Cntrl::update(float e)
00043 {
00044 
00045     // controller update function 
00046     
00047     // calculate uI
00048     y_I = y_I + Ki*Ts*e; 
00049     
00050     // saturate uI, uMin <= uI <= uMax (anti-windup for the integrator part)
00051     if(y_I > yMax)
00052         y_I = yMax;
00053     else if(y_I < yMin)
00054         y_I = yMin; 
00055 
00056     // calculate uD
00057     y_Dold = (1.0f - Ts/Tf)*y_Dold + Kd / Tf * (e-e_old);
00058     
00059     float y = Kp * e + y_I + y_Dold;
00060     
00061     // update signal storage
00062     e_old = e; 
00063     
00064     
00065     // calculate u
00066     // ???
00067     
00068     // saturate u, uMin <= u <= uMax
00069     if(y > yMax)
00070         y = yMax;
00071     else if(y < yMin)
00072         y = yMin; 
00073     
00074     // update signal storage
00075     // ???
00076 
00077     return y;
00078 }
00079