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
PololuHbridge/PololuHBridge.cpp@62:d502889e74f1, 2018-06-18 (annotated)
- Committer:
- tnhnrl
- Date:
- Mon Jun 18 14:45:37 2018 +0000
- Revision:
- 62:d502889e74f1
- Child:
- 74:d281aaef9766
in process of making an exit command on timeout from data transmission
Who changed what in which revision?
User | Revision | Line number | New 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 | //pc().printf("Debug (run): %0.2f\n\r", _pwm); |
tnhnrl | 62:d502889e74f1 | 33 | return; |
tnhnrl | 62:d502889e74f1 | 34 | } |
tnhnrl | 62:d502889e74f1 | 35 | |
tnhnrl | 62:d502889e74f1 | 36 | void PololuHBridge::reset() |
tnhnrl | 62:d502889e74f1 | 37 | { |
tnhnrl | 62:d502889e74f1 | 38 | _rst = 0; |
tnhnrl | 62:d502889e74f1 | 39 | _rst = 1; |
tnhnrl | 62:d502889e74f1 | 40 | } |
tnhnrl | 62:d502889e74f1 | 41 | |
tnhnrl | 62:d502889e74f1 | 42 | void PololuHBridge::stop() |
tnhnrl | 62:d502889e74f1 | 43 | { |
tnhnrl | 62:d502889e74f1 | 44 | //stop the motor output |
tnhnrl | 62:d502889e74f1 | 45 | _pwm = 0; |
tnhnrl | 62:d502889e74f1 | 46 | } |
tnhnrl | 62:d502889e74f1 | 47 | |
tnhnrl | 62:d502889e74f1 | 48 | float PololuHBridge::_clamp(float value, float min, float max) |
tnhnrl | 62:d502889e74f1 | 49 | { |
tnhnrl | 62:d502889e74f1 | 50 | if(value < min) { |
tnhnrl | 62:d502889e74f1 | 51 | return min; |
tnhnrl | 62:d502889e74f1 | 52 | } else if(value > max) { |
tnhnrl | 62:d502889e74f1 | 53 | return max; |
tnhnrl | 62:d502889e74f1 | 54 | } else { |
tnhnrl | 62:d502889e74f1 | 55 | return value; |
tnhnrl | 62:d502889e74f1 | 56 | } |
tnhnrl | 62:d502889e74f1 | 57 | } |