the fish that looks like a jet

Dependencies:   ADXL345 ADXL345_I2C IMUfilter ITG3200 mbed Servo

Revision:
0:ff9bc5f69c57
Child:
5:090ef6275773
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/motor_controller.cpp	Tue Jan 21 21:32:05 2014 +0000
@@ -0,0 +1,54 @@
+#include "motor_controller.h"
+
+PololuMController::PololuMController(PinName pwmport, PinName A, PinName B)
+{
+    pwm=new PwmOut(pwmport);
+    outA=new DigitalOut(A);
+    outB=new DigitalOut(B);
+    outA->write(0);
+    outB->write(1);
+    timestamp=0;
+}
+
+PololuMController::~PololuMController()
+{
+    delete pwm;
+    delete outA;
+    delete outB;
+}
+
+void PololuMController::setspeed(float speed)
+{
+    pwm->write(speed);
+    return;
+}
+
+void PololuMController::setpolarspeed(float speed)
+{
+    if (speed>=0)
+    {
+        outA->write(0);
+        outB->write(1);
+        pwm->write(abs(speed));
+    }
+    else
+    {
+        outA->write(1);
+        outB->write(0);
+        pwm->write(abs(speed));
+    }
+    return;
+}
+
+void PololuMController::reverse()
+{
+    outA->write(!(outA->read()));
+    outB->write(!(outB->read()));
+    return;
+}
+
+void PololuMController::drive_sinusoidal(float cur_time, float a, float w, float phi)
+{
+    setpolarspeed(a*sin(w*cur_time+phi));
+    return;
+}
\ No newline at end of file