gpa in double prescision

Dependencies:   mbed

PI_Cntrl.cpp

Committer:
pmic
Date:
23 months ago
Revision:
7:b3c5116e9fab
Parent:
0:15be70d21d7c
Child:
12:e54941459353

File content as of revision 7:b3c5116e9fab:

#include "PI_Cntrl.h"

using namespace std;

PI_Cntrl::PI_Cntrl(float Kp_, float Tn_){
    Kp = Kp_;
    Tn = Tn_;
    i_part_old = 0;
    del = 0;
    out_max =1e10;
    out_min=-1e10;
    }

PI_Cntrl::PI_Cntrl(float Kp_, float Tn_,float ma){
    Kp = Kp_;
    Tn = Tn_;
    i_part_old = 0;
    del = 0;
    out_max = ma;
    out_min = -ma;
    }

PI_Cntrl::~PI_Cntrl() {} 
    
void PI_Cntrl::reset(float initValue) {
    i_part_old = initValue;
    del = 0;
}

float PI_Cntrl::doStep(float error){
    float kpe = Kp * error;
    float i_part = Ts/Tn*(kpe-1.0f*del) + i_part_old; // I with windup subtraction
    i_part_old = i_part; 
    float y_out_temp = (kpe + i_part);                   // unconstrained output
    float y_out;
    // -------- limit output --------
    if(y_out_temp > out_max)
        y_out = out_max;
    else if(y_out_temp < out_min)
        y_out = out_min;
    else
        y_out = y_out_temp;
    // -------- Anti-Windup -------- 
    del = (y_out_temp - y_out);
    // -------- Timeshift --------
    
    return y_out;
    }