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:
Tue Aug 14 21:06:48 2018 +0000
Revision:
74:d281aaef9766
Parent:
62:d502889e74f1
1) Fixed deadband on float broadcast ; 2) Fixed find neutral commands

Who changed what in which revision?

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