![](/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:
- 62:6c566e6f9664
- Parent:
- 60:20945383ad1b
- Child:
- 81:71e7e98deb2c
--- a/PID/PID.cpp Tue Oct 13 18:28:39 2015 +0200 +++ b/PID/PID.cpp Wed Oct 14 13:52:16 2015 +0200 @@ -8,7 +8,7 @@ //t.start(); // start the timer -PID::PID(float* Input, float* Output, float* Setpoint, float Kp, float Ki, float Kd){ +PID::PID(double* Input, double* Output, double* Setpoint, double Kp, double Ki, double Kd){ myOutput = Output; myInput = Input; mySetpoint = Setpoint; @@ -31,7 +31,7 @@ // calculate using sample time frequency (regular intervals) // no more need to modify derivative/int sicne sample time is constant // if(timeChange <=SampleTime){ - float input = *myInput; + double input = *myInput; error = *mySetpoint - input; // get error for proportional ITerm += (ki*error); // Error for integral (with ki included) // check for integrator windup @@ -41,7 +41,7 @@ // (could still be tuned for derivative kick) // compute PID output - float output = kp * error + ITerm + kd * dErr; + double output = kp * error + ITerm + kd * dErr; // make sure output is allso within min/max if(output> outMax) output=outMax; else if(output<outMin) output=outMin; @@ -53,7 +53,7 @@ // else return false; } -void PID::SetTunings(float Kp, float Ki, float Kd) +void PID::SetTunings(double Kp, double Ki, double Kd) { kp = Kp; ki = Ki * SampleTime; // change PID parameters according to sample time @@ -61,17 +61,17 @@ } -void PID::SetSampleTime(float NewSampleTime){ +void PID::SetSampleTime(double NewSampleTime){ if (NewSampleTime > 0 ){ // change ratios for parameters for better computation in compute() - float ratio = NewSampleTime/SampleTime; + double ratio = NewSampleTime/SampleTime; ki *= ratio; kd /= ratio; SampleTime = NewSampleTime; } } -void PID::SetOutputLimits(float min, float max){ +void PID::SetOutputLimits(double min, double max){ if (min > max) return; outMin = min; outMax = max; @@ -102,14 +102,14 @@ else if(ITerm<outMin) ITerm=outMin; } -float PID::getKp(){ +double PID::getKp(){ return kp; } -float PID::getKi(){ +double PID::getKi(){ return ki/SampleTime; } -float PID::getKd(){ +double PID::getKd(){ return kd*SampleTime; } \ No newline at end of file