the fish that looks like a jet

Dependencies:   ADXL345 ADXL345_I2C IMUfilter ITG3200 mbed Servo

motor_controller.cpp

Committer:
sandwich
Date:
2014-01-28
Revision:
5:090ef6275773
Parent:
0:ff9bc5f69c57
Child:
6:a4d6f3e4bf28

File content as of revision 5:090ef6275773:

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