Wrapper library for ESC PWM throttle control.
Fork of ESC by
esc.cpp@1:4c02fede684b, 2013-06-09 (annotated)
- Committer:
- MitchJCarlson
- Date:
- Sun Jun 09 22:23:45 2013 +0000
- Revision:
- 1:4c02fede684b
- Parent:
- 0:ec466ef657a2
- Child:
- 2:b2d19bc95805
refactor
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 | |
MitchJCarlson | 0:ec466ef657a2 | 4 | ESC::ESC(PwmOut pwmPinOut, int period) |
MitchJCarlson | 0:ec466ef657a2 | 5 | : esc(pwmPinOut), period(period), throttle(1000) { |
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 | } |