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:
- 1:e2fb92398c1f
- Parent:
- 0:4b3a2875ad1d
- Child:
- 2:0413525bbb2e
--- a/PID.cpp Wed Dec 30 16:08:25 2020 +0000
+++ b/PID.cpp Wed Dec 30 17:30:24 2020 +0000
@@ -19,9 +19,11 @@
float dt = now_time - last_time;
dt /= pow(10.0, 6.0);
- val = val - target_val;
+ 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;
};