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.
commands.h@49:731c95cd5852, 2017-03-24 (annotated)
- Committer:
- NKarandey
- Date:
- Fri Mar 24 16:57:35 2017 +0000
- Revision:
- 49:731c95cd5852
- Child:
- 51:bab6e5eb864a
Convert the project into a modular structure
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| NKarandey | 49:731c95cd5852 | 1 | #include <vector> |
| NKarandey | 49:731c95cd5852 | 2 | |
| NKarandey | 49:731c95cd5852 | 3 | #include "mbed.h" |
| NKarandey | 49:731c95cd5852 | 4 | #include "controlLoops.h" |
| NKarandey | 49:731c95cd5852 | 5 | |
| NKarandey | 49:731c95cd5852 | 6 | Ticker lifeTicker; |
| NKarandey | 49:731c95cd5852 | 7 | |
| NKarandey | 49:731c95cd5852 | 8 | volatile bool commandFinished = false; |
| NKarandey | 49:731c95cd5852 | 9 | void stopCommand() { |
| NKarandey | 49:731c95cd5852 | 10 | commandFinished = true; |
| NKarandey | 49:731c95cd5852 | 11 | lifeTicker.detach(); |
| NKarandey | 49:731c95cd5852 | 12 | controlTicker.detach(); |
| NKarandey | 49:731c95cd5852 | 13 | } |
| NKarandey | 49:731c95cd5852 | 14 | |
| NKarandey | 49:731c95cd5852 | 15 | void rotateWith(float r, float v) { |
| NKarandey | 49:731c95cd5852 | 16 | |
| NKarandey | 49:731c95cd5852 | 17 | } |
| NKarandey | 49:731c95cd5852 | 18 | |
| NKarandey | 49:731c95cd5852 | 19 | void setVelocity(float v) { |
| NKarandey | 49:731c95cd5852 | 20 | // targetV = v; |
| NKarandey | 49:731c95cd5852 | 21 | // goalRevs = 900.0f; |
| NKarandey | 49:731c95cd5852 | 22 | // print("Spinning with V=%.2f\n\r", targetV); |
| NKarandey | 49:731c95cd5852 | 23 | |
| NKarandey | 49:731c95cd5852 | 24 | lifeTicker.attach(&stopCommand, 10); |
| NKarandey | 49:731c95cd5852 | 25 | } |
| NKarandey | 49:731c95cd5852 | 26 | |
| NKarandey | 49:731c95cd5852 | 27 | void playTune(float freq) { |
| NKarandey | 49:731c95cd5852 | 28 | motorPWMPeriod = 1.0f / freq; |
| NKarandey | 49:731c95cd5852 | 29 | // motorOut(0, 0.5); |
| NKarandey | 49:731c95cd5852 | 30 | Thread::wait(1000); |
| NKarandey | 49:731c95cd5852 | 31 | } |
| NKarandey | 49:731c95cd5852 | 32 | |
| NKarandey | 49:731c95cd5852 | 33 | void playTunes(const vector<float>& tunes) { |
| NKarandey | 49:731c95cd5852 | 34 | for (int i=0; i<tunes.size(); ++i) { |
| NKarandey | 49:731c95cd5852 | 35 | playTune(tunes[i]); |
| NKarandey | 49:731c95cd5852 | 36 | } |
| NKarandey | 49:731c95cd5852 | 37 | // motorPWMPeriod = defaultMotorPWMPeriod; |
| NKarandey | 49:731c95cd5852 | 38 | stopMotor(); |
| NKarandey | 49:731c95cd5852 | 39 | } |
