yotaro morizumi / Mbed 2 deprecated zoomy_customLibrary

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers pid.cpp Source File

pid.cpp

00001 #include<pid.hpp>
00002 
00003 Pid::Pid(double get_Kp,double get_Ki,double get_Kd,int plumi){
00004     setGain(get_Kp,get_Ki,get_Kd);
00005     e_o = 0;
00006     e_c = 0;
00007     plusminus=plumi;
00008 }
00009 
00010 double Pid::returnVal(double get_target,double input_val,double time){
00011     target = get_target;
00012     e_c = target - input_val;
00013     Give_P = Kp * e_c;
00014     Give_I=Ki*((e_o+e_c)/2.0/time);
00015     Give_D=Kd*(e_c-e_o)*time;
00016     e_o = e_c;
00017     Operation_amount = plusminus * Operation_amount + Give_P+Give_I-Give_D;
00018     if(Operation_amount > max_val){
00019         Operation_amount = max_val;
00020     }else if(Operation_amount < minimum_val){
00021         Operation_amount = minimum_val;
00022     }
00023     if(target == input_val){
00024         Operation_amount = 0;
00025     }
00026     return Operation_amount;
00027 }
00028 
00029 void Pid::setGain(double get_Kp,double get_Ki,double get_Kd){
00030     Kp = get_Kp;
00031     Ki = get_Ki;
00032     Kd = get_Kd;
00033 }
00034 
00035 void Pid::setMax(double get_max,double get_min){
00036     max_val = get_max;
00037     minimum_val = get_min;    
00038 }
00039 
00040 void Pid::reset(){
00041     Give_P = 0;
00042     Give_I = 0;
00043     Give_D = 0;
00044     e_o = 0;
00045     e_c = 0;    
00046 }