my

Fork of ESC by Mitch Carlson

Committer:
MitchJCarlson
Date:
Thu Jun 06 18:57:02 2013 +0000
Revision:
0:ec466ef657a2
Child:
1:4c02fede684b
Made library folders

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MitchJCarlson 0:ec466ef657a2 1 /**
MitchJCarlson 0:ec466ef657a2 2 * esc.cpp
MitchJCarlson 0:ec466ef657a2 3 * UWB Quadcopter Project
MitchJCarlson 0:ec466ef657a2 4 *
MitchJCarlson 0:ec466ef657a2 5 *
MitchJCarlson 0:ec466ef657a2 6 * @Author
MitchJCarlson 0:ec466ef657a2 7 * Mitch Carlson
MitchJCarlson 0:ec466ef657a2 8 */
MitchJCarlson 0:ec466ef657a2 9 #include "mbed.h"
MitchJCarlson 0:ec466ef657a2 10 #include "esc.h"
MitchJCarlson 0:ec466ef657a2 11
MitchJCarlson 0:ec466ef657a2 12 ESC::ESC(PwmOut pwmPinOut, int period)
MitchJCarlson 0:ec466ef657a2 13 : esc(pwmPinOut), period(period), throttle(1000) {
MitchJCarlson 0:ec466ef657a2 14 esc.period_ms(period);
MitchJCarlson 0:ec466ef657a2 15 esc.pulsewidth_us(throttle);
MitchJCarlson 0:ec466ef657a2 16 }
MitchJCarlson 0:ec466ef657a2 17
MitchJCarlson 0:ec466ef657a2 18 bool ESC::setThrottle(int t) {
MitchJCarlson 0:ec466ef657a2 19 if (t >= 0 && t <= 100) { // qualify range
MitchJCarlson 0:ec466ef657a2 20 throttle = t*10 + 1000; // map range, 1-2 ms (1000-2000us)
MitchJCarlson 0:ec466ef657a2 21 return true;
MitchJCarlson 0:ec466ef657a2 22 }
MitchJCarlson 0:ec466ef657a2 23 return false;
MitchJCarlson 0:ec466ef657a2 24 }
MitchJCarlson 0:ec466ef657a2 25
MitchJCarlson 0:ec466ef657a2 26 void ESC::pulse(void) {
MitchJCarlson 0:ec466ef657a2 27 esc.pulsewidth_us(throttle);
MitchJCarlson 0:ec466ef657a2 28 }