Sets motor currents based on input motorvalue

Files at this revision

API Documentation at this revision

Comitter:
tvlogman
Date:
Mon Oct 23 13:47:38 2017 +0000
Parent:
1:84cb991c4d28
Commit message:
Works now

Changed in this revision

motorConfig.cpp Show annotated file Show diff for this revision Revisions of this file
motorConfig.h Show annotated file Show diff for this revision Revisions of this file
--- a/motorConfig.cpp	Sun Oct 22 08:43:06 2017 +0000
+++ b/motorConfig.cpp	Mon Oct 23 13:47:38 2017 +0000
@@ -2,66 +2,35 @@
 #include "mbed.h"
 #include "FastPWM.h"
 
-// Member function definitions
-motorConfig::motorConfig(PinName a, PinName b, PinName c, PinName d, PinName e):ledG(a),ledR(b),ledB(c),directionPin(e),pwmPin(d){
-    currentState = KILLED;
+// Constructor
+motorConfig::motorConfig(PinName _directionPin, PinName _pwmPin):directionPin(_directionPin),pwmPin(_pwmPin){
     pwmPin.period(1.0/5000.0);
     directionPin = 0;
     }
 
+// Other member function definitions
 void motorConfig::setMotor(float motorValue){
-    switch(currentState){
-                case KILLED:
-                    pwmPin.write(0.0);
-                    // Set motor direction
-                    if (motorValue >=0){
-                        // corresponds to CW rotation of motor axle
-                        directionPin = 0;
-                        } else if(motorValue < 0){
-                        // corresponds to CCW rotation of motor axle
-                        directionPin = 1;
-                        }
-                    ledR = 0;
-                    ledG = 1;
-                    ledB = 1;
-                    break;
-                case ACTIVE:
-                    // Set motor direction
-                    if (motorValue >=0){
-                        // corresponds to CW rotation of motor axle
-                        directionPin.write(0);
-                        } else if(motorValue < 0){
-                        // corresponds to CCW rotation of motor axle
-                        directionPin.write(1);
-                        }
+    // Set motor direction
+    if (motorValue >=0){
+        // corresponds to CW rotation of motor axle
+        directionPin.write(0);
+        } else if(motorValue < 0){
+        // corresponds to CCW rotation of motor axle
+        directionPin.write(1);
+        }
                         
-                    // Set motor speed
-                    if (fabs(motorValue)>1){ 
-                        pwmPin = 1.0;
-                        }
-                    else {
-                        pwmPin.write(fabs(motorValue) + 0.4);
-                        }
-                    ledR = 1;
-                    ledG = 1;
-                    ledB = 0;      
-                    break;
-                case CALIBRATE:
-                    pwmPin.write(0.0);
-                    
-                    
-                    ledR = 1;
-                    ledG = 0;
-                    ledB = 0;
-                    
-                    break;
-            }
-    }
-
-void motorConfig::turnMotorOn(){
-    currentState = ACTIVE; 
+    // Set motor speed
+    if (fabs(motorValue)>1){ 
+        pwmPin = 1.0;
+        }
+    else {
+        pwmPin.write(fabs(motorValue) + 0.4);
+        }
+                          
     }
     
-void motorConfig::killSwitch(){
-    currentState = KILLED;
+void motorConfig::kill(){
+//    currentState = KILLED;
+    pwmPin.write(0.0);
+                
     }
\ No newline at end of file
--- a/motorConfig.h	Sun Oct 22 08:43:06 2017 +0000
+++ b/motorConfig.h	Mon Oct 23 13:47:38 2017 +0000
@@ -4,21 +4,14 @@
 #include "mbed.h"
 #include "FastPWM.h"
 
-enum robotStates {KILLED, ACTIVE, CALIBRATE};
-
 class motorConfig {
 public:
-    motorConfig(PinName, PinName, PinName, PinName, PinName);
-    robotStates currentState;
+    motorConfig(PinName, PinName);
     void setMotor(float motorValue);
     void turnMotorOn();
-    void killSwitch();
+    void kill();
     
-private:
-    DigitalOut ledG;
-    DigitalOut ledR;
-    DigitalOut ledB;
-    
+private:    
     DigitalOut directionPin; //D4
     PwmOut pwmPin; //D5
     };