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.
Dependencies: mbed
main.cpp@2:619b02232144, 2017-05-13 (annotated)
- Committer:
- kolanery
- Date:
- Sat May 13 06:13:23 2017 +0000
- Revision:
- 2:619b02232144
- Parent:
- 0:cb667de3a336
- Child:
- 3:4230b82fde43
update controller code
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kolanery | 0:cb667de3a336 | 1 | #include "mbed.h" |
kolanery | 0:cb667de3a336 | 2 | #include "drivecontrol.h" |
kolanery | 0:cb667de3a336 | 3 | #include "pin_assignment.h" |
kolanery | 0:cb667de3a336 | 4 | AnalogIn battery(PA_3); |
kolanery | 0:cb667de3a336 | 5 | Serial pc(PA_9, PA_10); |
kolanery | 0:cb667de3a336 | 6 | |
kolanery | 2:619b02232144 | 7 | DigitalOut testLed(PB_12); |
kolanery | 2:619b02232144 | 8 | DigitalOut testLed2(PB_13); |
kolanery | 2:619b02232144 | 9 | DigitalOut testLed3(PB_14); |
kolanery | 2:619b02232144 | 10 | DigitalOut testLed4(PB_15); |
kolanery | 2:619b02232144 | 11 | |
kolanery | 2:619b02232144 | 12 | Serial serial (PA_9, PA_10); |
kolanery | 2:619b02232144 | 13 | |
kolanery | 0:cb667de3a336 | 14 | // Define states for debugging the mouse hardware |
kolanery | 2:619b02232144 | 15 | // const int DRIVE = 1, TURN = 2, DEBUG = 3, STOP = 4; |
kolanery | 0:cb667de3a336 | 16 | // Direction of which to turn |
kolanery | 2:619b02232144 | 17 | // const int LEFT = 0, RIGHT = 1; |
kolanery | 0:cb667de3a336 | 18 | // Start and End Pos |
kolanery | 0:cb667de3a336 | 19 | const int START_POS = 0, END_POS = 0; |
kolanery | 2:619b02232144 | 20 | |
kolanery | 0:cb667de3a336 | 21 | // Terminating condition for the main control loop |
kolanery | 0:cb667de3a336 | 22 | bool hasFoundCenter = false; |
kolanery | 0:cb667de3a336 | 23 | |
kolanery | 0:cb667de3a336 | 24 | // Battery Consumption Indicator |
kolanery | 0:cb667de3a336 | 25 | void setup() { |
kolanery | 0:cb667de3a336 | 26 | pc.baud(9600); |
kolanery | 2:619b02232144 | 27 | if (battery.read() < 0.67f){ |
kolanery | 0:cb667de3a336 | 28 | // flash led |
kolanery | 2:619b02232144 | 29 | testLed = 1; |
kolanery | 2:619b02232144 | 30 | testLed2 = 1; |
kolanery | 2:619b02232144 | 31 | testLed3 = 1; |
kolanery | 2:619b02232144 | 32 | testLed4 = 1; |
kolanery | 0:cb667de3a336 | 33 | } |
kolanery | 0:cb667de3a336 | 34 | } |
kolanery | 0:cb667de3a336 | 35 | |
kolanery | 0:cb667de3a336 | 36 | // Performs the basic drive control of the mouse |
kolanery | 0:cb667de3a336 | 37 | int main() { |
kolanery | 0:cb667de3a336 | 38 | DriveControl * driver = new DriveControl(START_POS, END_POS); |
kolanery | 2:619b02232144 | 39 | while(1) { |
kolanery | 2:619b02232144 | 40 | setup(); |
kolanery | 2:619b02232144 | 41 | |
kolanery | 2:619b02232144 | 42 | serial.printf("voltage value is: %3.3f%%\r\n", battery.read()*100.0f); |
kolanery | 2:619b02232144 | 43 | serial.printf("normalized: 0x%04X \r\n", battery.read_u16()); |
kolanery | 2:619b02232144 | 44 | |
kolanery | 2:619b02232144 | 45 | testLed2 = 1; |
kolanery | 2:619b02232144 | 46 | testLed4 = 1; |
kolanery | 2:619b02232144 | 47 | |
kolanery | 2:619b02232144 | 48 | driver->drive_one_forward(); |
kolanery | 2:619b02232144 | 49 | wait(0.7); |
kolanery | 2:619b02232144 | 50 | driver->stop(); |
kolanery | 2:619b02232144 | 51 | wait(3); |
kolanery | 0:cb667de3a336 | 52 | } |
kolanery | 2:619b02232144 | 53 | } |