P-controller geordend
Dependencies: Encoder HIDScope MODSERIAL mbed
Diff: main.cpp
- Revision:
- 13:eaaeb41e22d2
- Parent:
- 12:e125b9fa77b9
- Child:
- 14:5534b8282a06
--- a/main.cpp Thu Nov 02 18:18:44 2017 +0000 +++ b/main.cpp Thu Nov 02 20:16:38 2017 +0000 @@ -17,7 +17,7 @@ MODSERIAL pc(USBTX,USBRX); float PwmPeriod = 1.0/5000.0; //set up of PWM periode (5000 Hz, want 5000 periodes in 1 seconde) -const float Ts = 0.1; // tickettijd/ sample time +const float Ts = 0.002; // tickettijd/ sample time float e_prev = 0; float e_int = 0; @@ -75,15 +75,15 @@ float FeedBackControl2(float error2, float &e_prev2, float &e_int2) // schaalt de snelheid naar de snelheid zodat onze chip het begrijpt (is nog niet in werking) { - float kp2 = 0.1; // kind of scaled. + float kp2 = 0.001; // kind of scaled. float Proportional2= kp2*error2; - float kd2 = 0.04; // kind of scaled. + float kd2 = 0.001; // kind of scaled. float VelocityError2 = (error2 - e_prev2)/Ts; float Derivative2 = kd2*VelocityError2; e_prev2 = error2; - float ki2 = 0.05; // kind of scaled. + float ki2 = 0.0005; // kind of scaled. e_int2 = e_int2+Ts*error2; float Integrator2 = ki2*e_int2; @@ -166,6 +166,7 @@ float motorValue2 = FeedBackControl2(error2, e_prev2, e_int2); SetMotor2(motorValue2); //pc.printf("encoder 2 = %f\r\n",Huidigepositie2); + pc.printf("refP2 = %f, Huidigepositie2 = %f, error = %f, motorValue2 = %f \r\n", refP2, Huidigepositie2, error2, motorValue2); }