ichinoseki_Bteam_2019 / PID

Dependents:   MR_example 2019_AR_Itsuki

Revision:
3:6b4d461517fb
Parent:
2:493370c3e206
--- a/PID.cpp	Sun Aug 05 14:39:22 2018 +0000
+++ b/PID.cpp	Thu Aug 09 14:17:06 2018 +0000
@@ -45,7 +45,7 @@
 {    
     float proportion, differential;
     static float _output = 0;
-
+    
     error[0] = *target - *sensor;
 
     proportion    = kp * error[0];
@@ -68,6 +68,7 @@
     if(_abs(error[0]) <= allowable_error)
         timer->start();
     else start_time = timer->read();
+    pre_target = *target;
 }
 
 float PID::_gurd(float val, float abs_max)
@@ -87,7 +88,7 @@
 
 bool PID::isConvergence(float time_range)
 {    
-    if(timer->read() - start_time > time_range)
+    if(pre_target == *target && (timer->read() - start_time > time_range) )
         return 1;
     else return 0;
 }
\ No newline at end of file