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

motor_controller.cpp

Committer:
rkk
Date:
2014-01-29
Revision:
6:a4d6f3e4bf28
Parent:
5:090ef6275773
Child:
7:e005cfaff8d1

File content as of revision 6:a4d6f3e4bf28:

#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 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));
    return;
}