My modifications/additions to the code

Dependencies:   ADXL345 ADXL345_I2C IMUfilter ITG3200 Servo fishgait mbed-rtos mbed pixy_cam

Fork of robotic_fish_ver_4_8 by jetfishteam

Revision:
7:e005cfaff8d1
Parent:
6:a4d6f3e4bf28
Child:
8:0574a5db1fc4
--- a/motor_controller.cpp	Wed Jan 29 05:04:50 2014 +0000
+++ b/motor_controller.cpp	Thu Jan 30 02:04:23 2014 +0000
@@ -1,5 +1,15 @@
 #include "motor_controller.h"
 
+float sigm(float input)
+{
+    if (input>0)
+        return 1;
+    else if (input<0)
+        return -1;
+    else
+        return 0;
+}
+
 PololuMController::PololuMController(PinName pwmport, PinName A, PinName B)
 {
     pwm=new PwmOut(pwmport);
@@ -49,9 +59,17 @@
 
 void PololuMController::drive_sinusoidal(float currentTime, float dutyCycle, float frequency)
 {
-    //convert frequency form 0.0 to 1.0
-    float f = (FREQ_MAX - FREQ_MIN) * f + FREQ_MIN; 
-    
-    setpolarspeed(dutyCycle*sin( 2.0* MATH_PI* f * currentTime));
+   
+    setpolarspeed(dutyCycle*sin( 2.0* MATH_PI* frequency * currentTime));
     return;
 }
+
+void PololuMController::drive_rectangular(float currentTime, float amplitude, float frequency)
+{    
+    //setpolarspeed(dutyCycle*sin( 2.0* MATH_PI* f * currentTime));
+    float sinRes = sin( 2.0* MATH_PI* frequency * currentTime);
+    
+    float dutycycle = amplitude * sigm( sinRes);
+    setpolarspeed(dutycycle);
+    return;
+}