Nicolae Marton / Mbed 2 deprecated TDP3_OOP

Dependencies:   mbed

Revision:
0:a02a278513d9
Child:
3:54c41af9e119
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LineFollowingRobot/RobotControl.cpp	Sat Jan 26 18:18:13 2019 +0000
@@ -0,0 +1,49 @@
+#include "RobotControl_H.h"
+#include <mbed.h>
+
+
+RobotControl::RobotControl(PinName pin1, PinName pin2, PinName pin3):m_motorEnable(pin1),m_motorBw(pin2),m_motorFw(pin3){
+    /*class constructor : initializes the motors with 
+    forward enable and speed of 0.3 */
+    
+    m_dir = true;
+    m_speed = 0.3;
+    SetDirection(m_dir);
+    SetSpeed(m_speed);
+}
+    
+    
+void RobotControl::SetDirection(bool dir){
+    /*set direction of one of the sides depending on pwmSelect
+    direction : 1 go forward  ,0 go backwards */    
+    
+    m_motorBw.write(0);
+    m_motorFw.write(0);
+    
+    wait(0.1);
+        
+    if(dir){
+        m_motorEnable = true;
+        m_pwmPtr = &m_motorFw;
+    }else{
+        m_motorEnable = false;
+        m_pwmPtr = &m_motorBw;
+    }
+    
+    m_prevDir = dir;
+        
+}
+
+
+void RobotControl::SetSpeed(float speed){
+    /*set speed on the pwm which is point by m_pwmPtr (set by SetDirection)
+    speed : the speed given to the motor, ranges from 0 to 1*/
+    
+    if(speed<=1.0 && speed > 0.0){
+        m_pwmPtr->write(speed);
+    }else{
+        m_pwmPtr->write(0);
+    }     
+}
+
+