for control a pololu motor with bd65496muv motor driver

Dependencies:   QEI

Files at this revision

API Documentation at this revision

Comitter:
jkoba0512
Date:
Mon Jul 01 04:14:20 2019 +0000
Parent:
2:cc875033357d
Commit message:
Fix process for pushing 'd' key (forgot 'break') and how to call callbackControlPeriod()

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Thu May 23 00:39:11 2019 +0000
+++ b/main.cpp	Mon Jul 01 04:14:20 2019 +0000
@@ -179,6 +179,7 @@
                 break;
             case 'd':
                 motor0.setDesEncPulseRate(motor0.getDesEncPulseRate() - 10);
+                break;
             case 'v':
                 motor1.switchControllerEnable(true);
                 break;
@@ -193,6 +194,7 @@
                 break;
             case 'h':
                 motor1.setDesEncPulseRate(motor1.getDesEncPulseRate() - 10);
+                break;
         }
     }
 }
@@ -219,13 +221,15 @@
 // callback per control period
 // update motor voltage
 // update enc_pulse_ratge
-void callbackControlPeriod() {
+void callbackControlPeriod0() {
     motor0.updateEncPulseRate();
-    motor1.updateEncPulseRate();
     motor0.applyInputVoltage();
+    motor0.updateInputVoltage();
+}
+
+void callbackControlPeriod1() {
+    motor1.updateEncPulseRate();
     motor1.applyInputVoltage();
-    
-    motor0.updateInputVoltage();
     motor1.updateInputVoltage();
 }
 
@@ -234,8 +238,8 @@
     pc.baud(9600);
     
     // event queue
-    queue.call_every(motor0.getControlPeriod(), &callbackControlPeriod);
-    queue.call_every(motor1.getControlPeriod(), &callbackControlPeriod);
+    queue.call_every(motor0.getControlPeriod(), &callbackControlPeriod0);
+    queue.call_every(motor1.getControlPeriod(), &callbackControlPeriod1);
     queue.call_every(100, &key_input_pc);
     queue.call_every(100, &enc_output_pc);
     queue.dispatch();