- This code combines steering and driving in one ticker - Fault check is in a ticker instead of while loop

Dependencies:   mbed MMA8451Q

Revision:
6:d2bd68ba99c9
Parent:
5:636c3fe18aa8
Child:
8:e4a147850ba4
--- a/driving.h	Mon Oct 25 02:14:11 2021 +0000
+++ b/driving.h	Mon Oct 25 03:15:51 2021 +0000
@@ -16,6 +16,7 @@
 #define fullBatScalar 0.5873f
 #define speedSensorScalar 2.5f
 #define battDividerScalar 4.0;
+
 PwmOut motorLeft(PTB1); 
 PwmOut motorRight(PTB2);
 AnalogIn pot1(PTB0);
@@ -60,7 +61,12 @@
 
 volatile bool motor_enabled = true;
 void PI(void) { //motor PI interrupt
-if(motor_enabled == true) {
+
+    if(motor_enabled == true) {
+            setpointLeft = 0.0;
+            setpointRight = 0.0;
+    }
+    
             //--- Calculate Error ---
             errorLeft = setpointLeft - (speedLeftVolt / 3.3f); //error and setpoint is defined as a percentage, from 0 to 1
             errorRight = setpointRight - (speedRightVolt / 3.3f);
@@ -159,13 +165,6 @@
             //--- set motors to calculated output ---    
             motorLeft.write(dutyCycleLeft);
             motorRight.write(dutyCycleRight);
-            }
-    else if(motor_enabled == false) {
-            // Does duty cycle zero turn off the motors? 
-            motorLeft.write(0);
-            motorRight.write(0);
-        
-        }
 //--- motor braking ---
 /*
 if (controllerOutputLeft < 0.0){