ichinoseki_Bteam_2019 / PID

Dependents:   MR_example 2019_AR_Itsuki

Revision:
7:6823018ff785
Parent:
6:925e92d4d4e8
--- a/PID_VEL.cpp	Sat Jul 20 13:26:09 2019 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,81 +0,0 @@
-#include "mbed.h"
-#include "PID_VEL.h"
-
-
-/*p,i,d:ゲイン設定 t:制御ループ時間  max:ourputの最大値*/
-PID_VEL::PID_VEL(float p, float i, float d, float t, float a_max, float max, Timer *T)
-{
-    kp = p; ki = i; kd = d; delta_t = t; acc_max_output = a_max; abs_max_output = max;
-    timer = T;
-    
-    integral = 0;
-    allowable_error = 0;
-}
-
-void PID_VEL::setParameter(float p, float i, float d, float t, float a_max, float max)
-{
-    kp = p; ki = i; kd = d; delta_t = t; acc_max_output = a_max; abs_max_output = max;
-    integral = 0;
-}
-
-/*計算のための割り込み開始*/
-void PID_VEL::start()
-{
-    pidTimer.attach(this, &PID_VEL::_compute, delta_t);
-}
-
-
-/*現在保持している計算データをリセット*/
-void PID_VEL::reset()
-{
-    integral = 0;
-    error = 0;
-    pre_error = 0;
-}
-
-/*一定周期で計算される*/
-void PID_VEL::_compute()
-{    
-    float proportion, differential;
-
-    error = *target - *sensor;
-    
-    proportion   = kp * error;
-    integral    += ki * error * delta_t;
-    differential = kd * (pre_error - error) / delta_t;
-    
-    _output += _gurd(proportion + integral + differential, acc_max_output);
-    if(_output > abs_max_output)
-        _output = _gurd(_output, abs_max_output);
-    else if(_output < 0)
-        _output = 0;
-    if(*sensor == 0 && *target == 0)
-        _output = integral = 0;
-    output = _output;
-    
-    if(abs(error) <= allowable_error)
-        timer->start();
-    else start_time = timer->read();
-    
-    last_target = *target;
-    pre_error = error;
-    pre_proportion = proportion;
-}
-
-float PID_VEL::_gurd(float val, float max_val)
-{
-    if(val > max_val)
-        return max_val;
-    else if(val < -max_val)
-        return -max_val;
-    else return val;
-}
-
-bool PID_VEL::isConvergence(double time_range)
-{
-    if(last_target != *target)
-        return 0; 
-    if(timer->read() - start_time > time_range)
-        return 1;
-    else return 0;
-}
\ No newline at end of file