Tess Groeneveld
/
PIDregelaargroep7
Version 1: the PID controller not implemented yet
main.cpp@0:9a990e099b26, 2013-10-30 (annotated)
- Committer:
- Tess
- Date:
- Wed Oct 30 15:01:15 2013 +0000
- Revision:
- 0:9a990e099b26
Version 1; the PID controller not implemented yet
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Tess | 0:9a990e099b26 | 1 | #include "mbed.h" |
Tess | 0:9a990e099b26 | 2 | //const float dt = 0.02; |
Tess | 0:9a990e099b26 | 3 | |
Tess | 0:9a990e099b26 | 4 | const float dt = 0.02; |
Tess | 0:9a990e099b26 | 5 | float Kp = 0.125; |
Tess | 0:9a990e099b26 | 6 | float Ki = 0.844; |
Tess | 0:9a990e099b26 | 7 | float Kd = 0.00679; |
Tess | 0:9a990e099b26 | 8 | float error_t0 = 0; |
Tess | 0:9a990e099b26 | 9 | float error_t_1; |
Tess | 0:9a990e099b26 | 10 | float P_regelaar; |
Tess | 0:9a990e099b26 | 11 | float I_regelaar; |
Tess | 0:9a990e099b26 | 12 | float D_regelaar; |
Tess | 0:9a990e099b26 | 13 | float integral_i; |
Tess | 0:9a990e099b26 | 14 | float integral_0 = 0; |
Tess | 0:9a990e099b26 | 15 | |
Tess | 0:9a990e099b26 | 16 | // setpoint is gewilde waarde |
Tess | 0:9a990e099b26 | 17 | // motorA.getPosition() is gemeten waarde |
Tess | 0:9a990e099b26 | 18 | |
Tess | 0:9a990e099b26 | 19 | do{ |
Tess | 0:9a990e099b26 | 20 | wait(dt) |
Tess | 0:9a990e099b26 | 21 | error_ti = setpointA - motorA.getPosition(); |
Tess | 0:9a990e099b26 | 22 | P_regelaar = Kp * error_ti |
Tess | 0:9a990e099b26 | 23 | D_regelaar = Kd * ((error_ti - error_t0) / dt); |
Tess | 0:9a990e099b26 | 24 | integral_i = integral_0 + (error_ti * dt); |
Tess | 0:9a990e099b26 | 25 | I_regelaar = Ki * integral_i; |
Tess | 0:9a990e099b26 | 26 | integral_0 = integral_i; |
Tess | 0:9a990e099b26 | 27 | error_t0 = error_ti; |
Tess | 0:9a990e099b26 | 28 | } |
Tess | 0:9a990e099b26 | 29 | |
Tess | 0:9a990e099b26 | 30 | output_regelaar = P_regelaar + I_regelaar + D_regelaar; |
Tess | 0:9a990e099b26 | 31 | |
Tess | 0:9a990e099b26 | 32 | |
Tess | 0:9a990e099b26 | 33 | |
Tess | 0:9a990e099b26 | 34 |