![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
control for robotic arm that can play chess using a granular gripper
Dependencies: Encoder mbed HIDScope Servo MODSERIAL
Fork of chessRobot by
Diff: PID/PID.cpp
- Revision:
- 55:ee5257fb73df
- Parent:
- 54:c14c3bc48b8a
- Child:
- 57:43f707648f2b
--- a/PID/PID.cpp Fri Oct 09 12:08:35 2015 +0000 +++ b/PID/PID.cpp Fri Oct 09 12:59:00 2015 +0000 @@ -41,7 +41,7 @@ // (could still be tuned for derivative kick) // compute PID output - float output = Kp * error + Ki * errSum + Kd * dErr; + float output = kp * error + ki * errSum + kd * dErr; // make sure output is allso within min/max if(output> outMax) output=outMax; else if(output<outMin) output=outMin; @@ -55,9 +55,9 @@ void PID::SetTunings(float Kp, float Ki, float Kd) { - Kp = Kp; - Ki = Ki * SampleTime; // change PID parameters according to sample time - Kd = Kd / SampleTime; + kp = Kp; + ki = Ki * SampleTime; // change PID parameters according to sample time + kd = Kd / SampleTime; } @@ -65,8 +65,8 @@ if (NewSampleTime > 0 ){ // change ratios for parameters for better computation in compute() float ratio = NewSampleTime/SampleTime; - Ki *= ratio; - Kd /= ratio; + ki *= ratio; + kd /= ratio; SampleTime = NewSampleTime; } } @@ -80,8 +80,8 @@ if(*myOutput > outMax) *myOutput = outMax; else if(*myOutput < outMin) *myOutput = outMin; - if(errSum> outMax) errSum= outMax; - else if(errSum< outMin) errSum= outMin; + if(errSum > outMax) errSum= outMax; + else if(errSum < outMin) errSum= outMin; } } @@ -89,7 +89,7 @@ // Turn PID on(AUTOMATIC) or off(MANUAL) bool newAuto = (Mode == AUTOMATIC); if(newAuto && !inAuto){ - Initialize(); // avoid bump because of stored values + PID::Initialize(); // avoid bump because of stored values } inAuto = newAuto; } @@ -100,4 +100,9 @@ lastErr = 0; if(errSum> outMax) errSum=outMax; else if(errSum<outMin) errSum=outMin; -} \ No newline at end of file +} + +float PID::getOutput(){ + return output; + } + \ No newline at end of file