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

Committer:
tnhnrl
Date:
Wed Feb 14 21:10:51 2018 +0000
Revision:
41:ed5b95ab97e3
Parent:
PololuHbridge/PololuHbridge.cpp@9:d5fcdcb3c89d
Servo Class Added (just the class)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mkelly10 9:d5fcdcb3c89d 1 #include "mbed.h"
tnhnrl 41:ed5b95ab97e3 2 #include "PololuHBridge.hpp"
mkelly10 9:d5fcdcb3c89d 3
mkelly10 9:d5fcdcb3c89d 4
mkelly10 9:d5fcdcb3c89d 5 PololuHBridge::PololuHBridge(PinName pwm, PinName dir, PinName reset):
mkelly10 9:d5fcdcb3c89d 6 _pwm(pwm),
mkelly10 9:d5fcdcb3c89d 7 _direction(dir),
mkelly10 9:d5fcdcb3c89d 8 _rst(reset)
mkelly10 9:d5fcdcb3c89d 9 {
mkelly10 9:d5fcdcb3c89d 10 _pwm.period_us(50);
mkelly10 9:d5fcdcb3c89d 11 run(0.0);
mkelly10 9:d5fcdcb3c89d 12 //pull Hbridge reset low then high to clear any faults
mkelly10 9:d5fcdcb3c89d 13 _rst = 0;
mkelly10 9:d5fcdcb3c89d 14 _rst = 1;
mkelly10 9:d5fcdcb3c89d 15 _direction = 0;
mkelly10 9:d5fcdcb3c89d 16 }
mkelly10 9:d5fcdcb3c89d 17
mkelly10 9:d5fcdcb3c89d 18 void PololuHBridge::run(float cmd)
mkelly10 9:d5fcdcb3c89d 19 {
mkelly10 9:d5fcdcb3c89d 20 _p = _clamp(cmd, -1.0, 1.0);
mkelly10 9:d5fcdcb3c89d 21
mkelly10 9:d5fcdcb3c89d 22 //This sets motor direction. Positive should give positve velocity (piston retract)
mkelly10 9:d5fcdcb3c89d 23 if (_p <= 0.0) {
mkelly10 9:d5fcdcb3c89d 24 _direction = 1;
mkelly10 9:d5fcdcb3c89d 25 //the pwm function needs an absolute value
mkelly10 9:d5fcdcb3c89d 26 _p = abs(_p);
mkelly10 9:d5fcdcb3c89d 27 } else if (_p > 0.0) {
mkelly10 9:d5fcdcb3c89d 28 _direction = 0;
mkelly10 9:d5fcdcb3c89d 29 }
mkelly10 9:d5fcdcb3c89d 30 _pwm = _p;
mkelly10 9:d5fcdcb3c89d 31 return;
mkelly10 9:d5fcdcb3c89d 32 }
mkelly10 9:d5fcdcb3c89d 33
mkelly10 9:d5fcdcb3c89d 34 void PololuHBridge::reset()
mkelly10 9:d5fcdcb3c89d 35 {
mkelly10 9:d5fcdcb3c89d 36 _rst = 0;
mkelly10 9:d5fcdcb3c89d 37 _rst = 1;
mkelly10 9:d5fcdcb3c89d 38 }
mkelly10 9:d5fcdcb3c89d 39
mkelly10 9:d5fcdcb3c89d 40 void PololuHBridge::stop()
mkelly10 9:d5fcdcb3c89d 41 {
mkelly10 9:d5fcdcb3c89d 42 //stop the motor output
mkelly10 9:d5fcdcb3c89d 43 _pwm = 0;
mkelly10 9:d5fcdcb3c89d 44 }
mkelly10 9:d5fcdcb3c89d 45
mkelly10 9:d5fcdcb3c89d 46 float PololuHBridge::_clamp(float value, float min, float max)
mkelly10 9:d5fcdcb3c89d 47 {
mkelly10 9:d5fcdcb3c89d 48 if(value < min) {
mkelly10 9:d5fcdcb3c89d 49 return min;
mkelly10 9:d5fcdcb3c89d 50 } else if(value > max) {
mkelly10 9:d5fcdcb3c89d 51 return max;
mkelly10 9:d5fcdcb3c89d 52 } else {
mkelly10 9:d5fcdcb3c89d 53 return value;
mkelly10 9:d5fcdcb3c89d 54 }
mkelly10 9:d5fcdcb3c89d 55 }