ichinoseki_Bteam_2019 / PID

Dependents:   MR_example 2019_AR_Itsuki

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers PID.h Source File

PID.h

00001 #ifndef PID_H
00002 #define PID_H
00003 
00004 #include "mbed.h"
00005 
00006 class PID
00007 {
00008 public:
00009     PID(float p = 0, float i = 0, float d = 0, float t = 1, float max = 1.0, bool pid_mode = false, Timer *T = NULL);
00010     void setParameter(float p = 0, float i = 0, float d = 0, float t = 1, float max = 1.0);
00011     void start();
00012     void reset();
00013     bool isConvergence(float timer_range);
00014     
00015     float output; //計算された出力値が入る 
00016 
00017     float *sensor, *target; //センサーと目標値を示す変数のポインタ 外側から引っ張ってくる
00018     float allowable_error;
00019     
00020 private:
00021     Timer *timer;
00022     Ticker pidTimer;
00023     float kp, ki, kd, delta_t;
00024     float abs_max_output; //outputの100%を定義
00025     bool pid_mode;   //0:位置型, 1:速度型
00026     float integral;
00027     float error[3];   //現在の誤差, 前回の誤差, 前々回の誤差
00028     float last_target;
00029     double start_time;
00030     void _compute();
00031     float _gurd(float val);
00032 };
00033 #endif