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/PID.cpp
- Revision:
- 4:4060309b9cc0
- Parent:
- 3:27407c4984cf
- Child:
- 5:7b02775787a9
--- a/PID/PID.cpp Thu Feb 13 16:07:07 2014 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,56 +0,0 @@
-#include "mbed.h"
-#include "SerialLcd.h"
-#include "PID.h"
-
-PID::PID()
-{
- interval = 0.05;
- differential_limit = 200;
- pid_limit = 300;
- kp = 0.5;
- ki = 0.5;
- kd = 0.2;
- integral = 0;
- old = 0;
-}
-
-void PID::init(float KP,float KI,float KD,float PID_LIM,float DIFFERENTIAL_LIM)
-{
-// interval = INTERVAL;
- pid_limit = PID_LIM;
- differential_limit = DIFFERENTIAL_LIM;
- kp = KP;
- ki = KI;
- kd = KD;
- integral = 0;
- old = 0;
-}
-
-float PID::calc(float value,float target,float interval)
-{
- float differential;
- cur = value - target;
-// if ( (old >= 0 && cur <= 0) || (old <= 0 && cur >= 0) || fabsf(cur) < 1 )
-// integral = 0;
- integral += ( cur + old ) * interval * 0.5f;
-// if ( integral < -differential_limit ) integral = -differential_limit;
-// if ( integral > integral_limit ) integral = integral_limit;
- differential = ( kd * ( cur - old ) / interval );
- if ( differential < -differential_limit ) differential = -differential_limit;
- if ( differential > differential_limit ) differential = differential_limit;
- float pid = ( kp * cur ) + ( ki * integral ) + differential;
- if ( pid < -pid_limit ) pid = -pid_limit;
- if ( pid > pid_limit ) pid = pid_limit;
- old = cur;
- return pid;
-}
-
-void PID::reset()
-{
- integral = 0;
- old = 0;
-}
-;
-
-
-