most functionality to splashdwon, find neutral and start mission. short timeouts still in code for testing, will adjust to go directly to sit_idle after splashdown

Dependencies:   mbed MODSERIAL FATFileSystem

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers PololuHBridge.cpp Source File

PololuHBridge.cpp

00001 #include "mbed.h"
00002 #include "PololuHBridge.hpp"
00003 
00004 
00005 PololuHBridge::PololuHBridge(PinName pwm, PinName dir, PinName reset):
00006     _pwm(pwm),
00007     _direction(dir),
00008     _rst(reset)
00009 {
00010     _pwm.period_us(50);
00011     run(0.0);
00012     //pull Hbridge reset low then high to clear any faults
00013     _rst = 0;
00014     _rst = 1;
00015     _direction = 0;
00016 }
00017 
00018 void PololuHBridge::run(float cmd)
00019 {
00020     _p = _clamp(cmd, -1.0, 1.0);
00021 
00022     //This sets motor direction. Positive should give positve velocity (piston retract)
00023     if (_p <= 0.0) {
00024         _direction = 1;
00025         //the pwm function needs an absolute value
00026         _p = abs(_p);
00027     } else if (_p > 0.0) {
00028         _direction = 0;
00029     }
00030     _pwm = _p;
00031     
00032     return;
00033 }
00034 
00035 void PololuHBridge::reset()
00036 {
00037     _rst = 0;
00038     _rst = 1;
00039 }
00040 
00041 void PololuHBridge::stop()
00042 {
00043     //stop the motor output
00044     _pwm = 0;
00045 }
00046 
00047 float PololuHBridge::_clamp(float value, float min, float max)
00048 {
00049     if(value < min) {
00050         return min;
00051     } else if(value > max) {
00052         return max;
00053     } else {
00054         return value;
00055     }
00056 }