DCS_TEAM / Mbed 2 deprecated Chemical_Sensor_DMA

Dependencies:   mbed

Dependents:   DCS_FINAL_CODE

Fork of Chemical_Sensor_DMA by Jared Baxter

Revision:
2:3771b3195c7b
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MotorControl.cpp	Thu Oct 29 17:15:20 2015 +0000
@@ -0,0 +1,76 @@
+#include "MotorControl.h"
+#include "mbed.h"
+
+// constructor 
+MotorControl::MotorControl(PinName cw, PinName ccw, int period, int safetyPeriod) :  
+        _cw(cw),
+        _ccw(ccw) {
+    
+    // turn motor off
+    _cw = 0;
+    _ccw = 0;
+    
+    _cw.period_us(period);
+    _ccw.period_us(period);
+    
+    _period = period;
+    _safetyPeriod = safetyPeriod;
+}
+
+void MotorControl::off() {
+    _cw = 0;
+    _ccw = 0;    
+    pause_us(_safetyPeriod);
+}
+
+void MotorControl::clockwise(float dutyCycle) {
+    _cw = dutyCycle;
+}
+
+void MotorControl::releaseMallet() {
+    // make sure motor is off
+    off();
+    
+    // pulse clockwise to release mallet
+    _cw = 1;
+    pause_ms(10);
+    _cw = 0;
+    pause_ms(75);
+    
+    // pulse counter-clockwise to stop snail cam
+    _ccw = 0.7;
+    pause_ms(8);
+    _ccw = 0;
+    
+    // make sure motor is off
+    off();
+}
+
+void MotorControl::reset() {
+    
+}
+
+void MotorControl::hardReset(int duration) {
+    // make sure motor is off
+    off();
+    
+    // long pulse clockwise to reset mallet
+    _cw = 1;
+    pause_ms(200);
+    _cw = 0;
+    
+    // short pulse counter-clockwise to stop snail cam
+    _ccw = 1;
+    pause_ms(10);
+    _ccw = 0;
+    
+    
+    wait_ms(duration);
+    // short pulse counter-clockwise to set snail cam in groove on mallet
+    _ccw = 1;
+    pause_ms(3);
+    _ccw = 0;
+    
+    // make sure motor is off
+    off();
+}
\ No newline at end of file