Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: MR_example 2019_AR_Itsuki
Diff: PID.cpp
- 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