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: Tourobo2022_TBCMotorDriver
Diff: Pid.cpp
- Revision:
- 4:3c2651359136
- Parent:
- 2:7fede27af6ca
- Child:
- 5:a3aa705d9023
--- a/Pid.cpp Tue Sep 10 13:55:06 2019 +0000
+++ b/Pid.cpp Sat Jan 11 12:47:02 2020 +0000
@@ -6,9 +6,16 @@
KD = Kd;
MODE = PidMode;
PERIOD = period;
+ upperLimit = 1.0f;
+ fallLimit = 1.0f;
//pid.attach(this,&Pid::calculate,period);
}
+void Pid::setupLimit(float UpperLimit,float FallLimit) {
+ upperLimit = UpperLimit;
+ fallLimit = FallLimit;
+}
+
void Pid::calculate(float targetValue,float nowValue,bool enableErrorIntegration) {
switch(MODE) {
case 0:
@@ -35,10 +42,10 @@
break;
}
- if(duty > 1.0f) {
- duty = 1.0f;
- } else if (duty < -1.0f) {
- duty = -1.0f;
+ if(duty > upperLimit) {
+ duty = upperLimit;
+ } else if (duty < fallLimit) {
+ duty = fallLimit;
}
};