Basic DC motor control test, rpm feedback by simple impulse signal, PID speed control.

Dependencies:   FastPWM mbed FastIO MODSERIAL

Files at this revision

API Documentation at this revision

Comitter:
dzoni
Date:
Wed Apr 04 05:58:25 2018 +0000
Parent:
10:c28d133a1408
Commit message:
After functionality test on actual HW. Fine tunning of PID controller parameters required. Functionality OK. Controller slow on start from zero speed.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r c28d133a1408 -r 4747badb2448 main.cpp
--- a/main.cpp	Tue Apr 03 12:49:11 2018 +0000
+++ b/main.cpp	Wed Apr 04 05:58:25 2018 +0000
@@ -63,7 +63,7 @@
 DigitalOut myled(LED1);
 
 // Controllers
-PID pid_RPM_Right_motor(1.0f, 0.0f, 0.0f, (((float)periodPWMWrite)/1000000.0f));
+PID pid_RPM_Right_motor(0.00175f, 0.00200f, 0.000f, (((float)periodPWMWrite)/1000000.0f));
 
 // LOCAL FUNCTION DECLARATIONS
 // Task worker functions
@@ -122,23 +122,24 @@
     pcLink.baud(115200);
     pcLink.format(8, SerialBase::None, 1);
     
-    mypwm.period_us(2000);
-    mypwm.write(0.5);
+    mypwm.period_us(3500);
+    mypwm.write(0.0);
   
     myTimer.start();
     
     //Analog input from 0.0 to 100.0 impulses per measurement period
-    pid_RPM_Right_motor.setInputLimits(0.0f, 100.0f);
+    pid_RPM_Right_motor.setInputLimits(16.0f, 35.0f);
     
     //Pwm output from 0.0 to 1.0
-    pid_RPM_Right_motor.setOutputLimits(0.0f, 1.0f);
+    pid_RPM_Right_motor.setOutputLimits(0.05f, 1.0f);
     
     //If there's a bias.
     pid_RPM_Right_motor.setBias(0.0f);
     pid_RPM_Right_motor.setMode(AUTO_MODE);
     
     //We want the process variable to be 0.0 RPM
-    pid_RPM_Right_motor.setSetPoint(0.0f);
+    fRPMSetpoint = 16.0f;
+    pid_RPM_Right_motor.setSetPoint(fRPMSetpoint);
 }
 
 // Task worker functions definitions
@@ -190,7 +191,7 @@
 
     mypwm.write(fPwmDuty);
 
-    pcLink.printf("PWM: %.2f %%\tIMP: %u imp.\tSET: %.2f imp.\t\r", mypwm.read() * 100, uiImpSens, fRPMSetpoint);
+    pcLink.printf("PWM: %.2f %%\tIMP: %.2f imp.\tSET: %.2f imp.\t\r", mypwm.read() * 100, (float)uiImpSens, fRPMSetpoint);
 
 //    pcLink.printf("\r\nPWM: %.2f %%     \r\n", mypwm.read() * 100);
 }
@@ -203,10 +204,10 @@
  */
 void tskRPMSetpoint(void)
 {
-    fRPMSetpoint += 10.0f;
-    if (100.0f < fRPMSetpoint)
+    fRPMSetpoint += 2.0f;
+    if (35.0f < fRPMSetpoint)
     {
-        fRPMSetpoint = 0.0f;
+        fRPMSetpoint = 16.0f;
     }
 
     pid_RPM_Right_motor.setSetPoint(fRPMSetpoint);