Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of ESC by
esc.cpp@5:07bbe020eb65, 2016-07-26 (annotated)
- Committer:
- gelmes
- Date:
- Tue Jul 26 17:22:33 2016 +0000
- Revision:
- 5:07bbe020eb65
- Parent:
- 1:735702ea5519
This is a working implementation of the Controller;
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| MatteoT | 0:116260c66d88 | 1 | #include "mbed.h" |
| MatteoT | 0:116260c66d88 | 2 | #include "esc.h" |
| MatteoT | 0:116260c66d88 | 3 | |
| MatteoT | 0:116260c66d88 | 4 | ESC::ESC(const PinName pwmPinOut, const int period) |
| MatteoT | 0:116260c66d88 | 5 | : esc(pwmPinOut), period(period), throttle(1000) |
| MatteoT | 0:116260c66d88 | 6 | { |
| MatteoT | 0:116260c66d88 | 7 | esc.period_ms(period); |
| MatteoT | 0:116260c66d88 | 8 | esc.pulsewidth_us(throttle); |
| MatteoT | 0:116260c66d88 | 9 | } |
| MatteoT | 0:116260c66d88 | 10 | |
| MatteoT | 1:735702ea5519 | 11 | bool ESC::setThrottle (const float t) |
| MatteoT | 0:116260c66d88 | 12 | { |
| MatteoT | 0:116260c66d88 | 13 | if (t >= 0.0 && t <= 1.0) { // qualify range, 0-1 |
| MatteoT | 0:116260c66d88 | 14 | throttle = 1000.0*t + 1000; // map to range, 1-2 ms (1000-2000us) |
| MatteoT | 0:116260c66d88 | 15 | return true; |
| MatteoT | 0:116260c66d88 | 16 | } |
| MatteoT | 0:116260c66d88 | 17 | return false; |
| MatteoT | 0:116260c66d88 | 18 | } |
| MatteoT | 1:735702ea5519 | 19 | bool ESC::operator= (const float t){ |
| MatteoT | 0:116260c66d88 | 20 | return this->setThrottle(t); |
| MatteoT | 0:116260c66d88 | 21 | } |
| MatteoT | 0:116260c66d88 | 22 | |
| MatteoT | 1:735702ea5519 | 23 | float ESC::getThrottle () const{ |
| MatteoT | 0:116260c66d88 | 24 | return throttle; |
| MatteoT | 0:116260c66d88 | 25 | } |
| MatteoT | 1:735702ea5519 | 26 | ESC::operator float () const{ |
| MatteoT | 0:116260c66d88 | 27 | return this->getThrottle(); |
| MatteoT | 0:116260c66d88 | 28 | } |
| MatteoT | 0:116260c66d88 | 29 | |
| MatteoT | 1:735702ea5519 | 30 | void ESC::pulse () |
| MatteoT | 0:116260c66d88 | 31 | { |
| MatteoT | 0:116260c66d88 | 32 | esc.pulsewidth_us(throttle); |
| MatteoT | 0:116260c66d88 | 33 | } |
| MatteoT | 1:735702ea5519 | 34 | void ESC::operator() () |
| MatteoT | 0:116260c66d88 | 35 | { |
| MatteoT | 0:116260c66d88 | 36 | this->pulse(); |
| MatteoT | 0:116260c66d88 | 37 | } |
