![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
sampleProgram
Dependencies: QEI accelerator bit_test cyclic_io cyclic_var cylinder event_var limit mbed mecanum motor_drive pid pid_encoder rs422_put sbdbt servo
Fork of 17robo_fuzi by
Diff: pid.h
- Revision:
- 7:c4ae1d001d09
- Parent:
- 0:bf96e953cdb8
--- a/pid.h Fri Jun 30 05:52:04 2017 +0000 +++ b/pid.h Sat Jul 01 10:12:46 2017 +0000 @@ -28,37 +28,4 @@ float kp, ki, kd, old, now, p, i, d, result; -}; - -class Speed_pid { -public : - void setup(float Kp, float Ki, float Kd) { - kp = Kp; - ki = Ki; - kd = Kd; - } - - void cal(float target, float nowval, float dt) { - e2 = e1; - e1 = e; - e = nowval - target; - p = e - e1; - i = e*dt; - d = (e-2*e1+e2)/dt; - result = result + (kp*p+ki*i+kd*d); - if (result > 1.0f) { - result = 1.0f; - } else if (result < -1.0f) { - result = -1.0f; - } - } - - float duty() { - return result; - } - -private : - float kp, ki, kd, - e, e1, e2, - p, i, d, result; }; \ No newline at end of file