PID Kontrol atas, tanpa library. Baru P dan D, tapi D error
Dependencies: Motor mbed millis
Fork of Test_PID by
Diff: main.cpp
- Revision:
- 4:8e6dfc416ecf
- Parent:
- 3:e4cbba0706b0
diff -r e4cbba0706b0 -r 8e6dfc416ecf main.cpp --- a/main.cpp Tue Oct 18 12:28:57 2016 +0000 +++ b/main.cpp Thu Feb 09 14:34:10 2017 +0000 @@ -16,16 +16,16 @@ unsigned long int previousMillis = 0; //Variabel Motor - Motor motor1(PB_9, PC_5, PA_12); // pwm, fwd, rev + Motor motor1(PA_8, PC_2, PC_1); // pwm, fwd, rev // Variabel PID - int errorP, last_errorD; - float pwm, pwm_last; + int errorP = 0, last_errorD = 0; + float pwm = 0, pwm_last; float P, Kp; float D, Kd; // Variabel Sabeb - int desired_rpm = 100; + int desired_rpm = 50; // Test Variabel int selisiherror; @@ -33,17 +33,17 @@ // Main Program int main(void) { - DigitalIn encoder0PinA(PA_5); - DigitalIn encoder0PinB(PA_6); - Serial pc(USBTX,USBRX); - pc.baud(9600); + DigitalIn encoder0PinA(PB_14); + DigitalIn encoder0PinB(PB_13); + Serial pc(USBTX,USBRX); + pc.baud(9600); startMillis(); // Deklarasi awal PID last_errorD = 0; pwm_last = 0; - Kp = 0.00000007; - Kd = 0.000000007; + Kp = 0.000000033; //0.000000037 + Kd = 0.000000297; //0.000000270 while(1){ @@ -58,9 +58,11 @@ pwm = 1; } + motor1.speed(pwm); pwm_last = pwm; + //motor1.speed(0.8); unsigned long int currentMillis = millis(); // int counter; // counter=currentMillis/100; @@ -69,7 +71,7 @@ { previousMillis = currentMillis; rpm = encoder0Pos; - pc.printf ("pwm = %.5f | rpm = %.0f | P = %.10f | D = %.10f | errorP = %.d | last_errorD = %.d \n",pwm,rpm,P,D, errorP, last_errorD); + pc.printf ("pwm = %.5f | rpm = %.0f | P = %.10f | D = %.10f | errorP = %.d | last_errorD = %.d \n",pwm,(rpm),P,D, errorP, last_errorD); encoder0Pos = 0; last_errorD = errorP; @@ -86,7 +88,7 @@ } else { encoder0Pos++; } - //pc.printf ("%d \n",encoder0Pos); + //pc.printf ("%d \n",encoder0Pos); } encoder0PinALast = n; }