with the tof code

Dependencies:   mbed Servo ros_lib_kinetic

Revision:
2:6197e1cf2cd1
Child:
3:df6160e2f6d9
diff -r 9bc7f95c3c7d -r 6197e1cf2cd1 Motors/Motor.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Motors/Motor.cpp	Thu Oct 24 14:24:27 2019 +0000
@@ -0,0 +1,47 @@
+/*--------------------------------------------------------------------------------
+Filename: main.cpp
+Description: Main program loop
+--------------------------------------------------------------------------------*/
+
+#include "Motor.h"
+
+/*--------------------------------------------------------------------------------
+Function name: cMotor
+Input Parameters: PwmOut pwm - Motor PWM, DigitalOut fwd - Motor input1, DigitalOut rev - Motor Input2
+Output Parameters: N/A
+Description: Class constructor (Initialisation upon creating class)
+----------------------------------------------------------------------------------*/
+cMotor::cMotor(PwmOut pwm, DigitalOut fwd, DigitalOut rev):_pwm(pwm), _fwd(fwd), _rev(rev){
+    
+    // Set initial condition of PWM
+    _pwm.period(0.001); //1KHz
+    _pwm = 0;
+
+    // Initial condition of output enables
+    _fwd = 0;
+    _rev = 0;
+}
+
+/*--------------------------------------------------------------------------------
+Function name: Forwards
+Input Parameters: float speed - PWM duty between 0-1
+Output Parameters: N/A
+Description: Drives the motor forwards at a designated speed
+----------------------------------------------------------------------------------*/
+void cMotor::Forwards(float speed){
+    _fwd = 1;
+    _rev = 0;
+    _pwm = speed;
+}
+
+/*--------------------------------------------------------------------------------
+Function name: Backwards
+Input Parameters: float speed - PWM duty between 0-1
+Output Parameters: N/A
+Description: Drives the motor backwards at a designated speed
+----------------------------------------------------------------------------------*/
+void cMotor::Backwards(float speed){
+    _fwd = 0;
+    _rev = 1;
+    _pwm = speed;
+}