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.
Diff: PID.cpp
- Revision:
- 2:0413525bbb2e
- Parent:
- 1:e2fb92398c1f
diff -r e2fb92398c1f -r 0413525bbb2e PID.cpp
--- a/PID.cpp Wed Dec 30 17:30:24 2020 +0000
+++ b/PID.cpp Sun Jan 17 02:06:07 2021 +0000
@@ -20,12 +20,19 @@
dt /= pow(10.0, 6.0);
val = target_val - val;
- integral_val += (last_val * val) / 2 * dt;
- float d_val = (val - last_val) / dt;
- last_time = now_time;
- last_val = val;
- return _p * val+ _i * integral_val + _d * d_val;
+//// normal PID
+// integral_val += (last_val * val) / 2 * dt;
+// float d_val = (val - last_val) / dt;
+// last_time = now_time;
+// last_val = val;
+// return _p * val+ _i * integral_val + _d * d_val;
+
+//// original
+ if(abs(integral_val) < 50 || integral_val * val < 0) {
+ integral_val += val * _p;
+ }
+ return integral_val;
};
void PID::set_target(float val) {