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:
- 1:accc8b66773b
- Parent:
- 0:f439078cfdde
- Child:
- 2:89d69eae8917
--- a/main.cpp Wed Oct 12 10:56:42 2016 +0000 +++ b/main.cpp Sat Oct 15 15:26:00 2016 +0000 @@ -25,7 +25,7 @@ float D, Kd; // Variabel Sabeb - int desired_rpm = 450; + int desired_rpm = 150; // Test Variabel int selisiherror; @@ -43,7 +43,7 @@ last_errorD = 0; pwm_last = 0; Kp = 0.000000007; - Kd = 0.00007; + Kd = 0.000000000007; while(1){ @@ -67,10 +67,12 @@ if (currentMillis-previousMillis==500) { - 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); - encoder0Pos = 0; + 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); + encoder0Pos = 0; + + last_errorD = errorP; } else @@ -88,7 +90,5 @@ } encoder0PinALast = n; } - - last_errorD = errorP; } } \ No newline at end of file