Wrapper library for ESC PWM throttle control.
Fork of ESC by
esc.cpp@2:b2d19bc95805, 2017-05-05 (annotated)
- Committer:
- IonSystems
- Date:
- Fri May 05 14:10:46 2017 +0000
- Revision:
- 2:b2d19bc95805
- Parent:
- 1:4c02fede684b
Cameron has entered the game.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MitchJCarlson | 0:ec466ef657a2 | 1 | #include "mbed.h" |
MitchJCarlson | 0:ec466ef657a2 | 2 | #include "esc.h" |
MitchJCarlson | 0:ec466ef657a2 | 3 | |
IonSystems | 2:b2d19bc95805 | 4 | ESC::ESC(PwmOut pwmPinOut, int period, int throttle) |
IonSystems | 2:b2d19bc95805 | 5 | : esc(pwmPinOut), period(period), throttle(throttle) { |
MitchJCarlson | 0:ec466ef657a2 | 6 | esc.period_ms(period); |
MitchJCarlson | 0:ec466ef657a2 | 7 | esc.pulsewidth_us(throttle); |
MitchJCarlson | 0:ec466ef657a2 | 8 | } |
MitchJCarlson | 0:ec466ef657a2 | 9 | |
MitchJCarlson | 0:ec466ef657a2 | 10 | bool ESC::setThrottle(int t) { |
MitchJCarlson | 1:4c02fede684b | 11 | if (t >= 0 && t <= 100) { // qualify range, 0-100 |
MitchJCarlson | 1:4c02fede684b | 12 | throttle = t*10 + 1000; // map to range, 1-2 ms (1000-2000us) |
MitchJCarlson | 1:4c02fede684b | 13 | esc.pulsewidth_us(throttle); |
MitchJCarlson | 0:ec466ef657a2 | 14 | return true; |
MitchJCarlson | 0:ec466ef657a2 | 15 | } |
MitchJCarlson | 0:ec466ef657a2 | 16 | return false; |
MitchJCarlson | 0:ec466ef657a2 | 17 | } |
MitchJCarlson | 0:ec466ef657a2 | 18 | |
MitchJCarlson | 0:ec466ef657a2 | 19 | void ESC::pulse(void) { |
MitchJCarlson | 0:ec466ef657a2 | 20 | esc.pulsewidth_us(throttle); |
MitchJCarlson | 0:ec466ef657a2 | 21 | } |
IonSystems | 2:b2d19bc95805 | 22 | |
IonSystems | 2:b2d19bc95805 | 23 | void ESC::failsafe(void) { |
IonSystems | 2:b2d19bc95805 | 24 | esc.pulsewidth_us(0); |
IonSystems | 2:b2d19bc95805 | 25 | } |