Soft robot team / Mbed OS Robot_team1

Dependencies:   QEI Motordriver ros_lib_melodic

Revision:
12:817da876ae2f
Parent:
11:35809512ec11
diff -r 35809512ec11 -r 817da876ae2f motor/Motor.cpp
--- a/motor/Motor.cpp	Wed Nov 13 15:59:06 2019 +0000
+++ b/motor/Motor.cpp	Fri Nov 15 17:38:04 2019 +0000
@@ -1,13 +1,12 @@
 #include "mbed.h"
 
 #include "Motor.h"
-#include "QEI.h"
 
 ///////////////////////////////////////////////////////////////////
 // Constructor
 ///////////////////////////////////////////////////////////////////
-Motor::Motor(PinName in1, PinName in2, PinName pwm, QEI wheel)
-: in1(in1), in2(in2), pwm(pwm), wheel(wheel)
+Motor::Motor(PinName in1, PinName in2, PinName pwm)
+: in1(in1), in2(in2), pwm(pwm) 
 {
     this->pwm.period_ms(10);
 }
@@ -15,63 +14,25 @@
 ///////////////////////////////////////////////////////////////////
 // Public methods
 ///////////////////////////////////////////////////////////////////
-
-void Motor::moveForward(int pulse)
+void Motor::stop()
 {
-    moveDistance(-0.5, pulse, 1); 
+    in1 = 0;
+    in2 = 0;
 }
 
-void Motor::moveBackward(int pulse)
-{  
-    moveDistance(0.5, pulse, -1);
+void Motor::moveForward()
+{
+    in1 = 1; 
+    in2 = 0;    
 }
 
-void Motor::moveLeft(float speed)
-{  
-    moveDistance(speed, 3000, -1);
-}
-
-void Motor::moveRight(float speed)
-{  
-    moveDistance(speed, 3000, 1);
+void Motor::moveBackward()
+{
+    in1 = 0; 
+    in2 = 1;
 }
 
 void Motor::setSpeed(float speed)
 {
     pwm.write(speed);
 }
-
-void Motor::moveDistance(float speed, int pulse, int pulse_direction)
-{
-    // Variables to allow for any pulse reading   
-    float initial_pulse_reading = wheel.getPulses();
-    float current_pulse_reading = wheel.getPulses();
-    
-    // - is forward on our robot
-    setSpeed(speed);
-    
-    // loop for moving forward
-    if (pulse_direction > 0)
-    {
-        while(current_pulse_reading <= (initial_pulse_reading + pulse * pulse_direction))
-        {
-            current_pulse_reading = wheel.getPulses();
-        }
-    }
-    else
-    {
-        while(current_pulse_reading >= (initial_pulse_reading + pulse * pulse_direction))
-        {
-            current_pulse_reading = wheel.getPulses();
-        }
-    }        
-
-    setSpeed(0);
-}
-
-
-void Motor::move(float speed)
-{
-    // - is forward on our robot
-    setSpeed(speed);    
-}
\ No newline at end of file