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@8:4a32fc9ee939, 2017-05-17 (annotated)
- Committer:
- szh66
- Date:
- Wed May 17 00:07:32 2017 +0000
- Revision:
- 8:4a32fc9ee939
- Parent:
- 7:7215adbae3da
- Child:
- 9:65a9aad9a5b5
add encoder reading in DriveControl
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kolanery | 0:cb667de3a336 | 1 | #include "drivecontrol.h" |
szh66 | 6:1bcfda49e146 | 2 | //#include "pin_assignment.h" |
kolanery | 4:73510c7fa316 | 3 | #include "io_modules.h" |
szh66 | 6:1bcfda49e146 | 4 | #include "mbed.h" |
szh66 | 6:1bcfda49e146 | 5 | |
szh66 | 6:1bcfda49e146 | 6 | // Battery Debugger Interface |
szh66 | 6:1bcfda49e146 | 7 | AnalogIn battery(PA_3); |
szh66 | 6:1bcfda49e146 | 8 | |
szh66 | 6:1bcfda49e146 | 9 | |
szh66 | 6:1bcfda49e146 | 10 | // Led Debugger Interface |
szh66 | 6:1bcfda49e146 | 11 | DigitalOut led_1(PB_12); |
szh66 | 6:1bcfda49e146 | 12 | DigitalOut led_2(PB_13); |
szh66 | 6:1bcfda49e146 | 13 | DigitalOut led_3(PB_14); |
szh66 | 6:1bcfda49e146 | 14 | DigitalOut led_4(PB_15); |
szh66 | 6:1bcfda49e146 | 15 | |
szh66 | 6:1bcfda49e146 | 16 | // System io |
szh66 | 6:1bcfda49e146 | 17 | Serial serial (PA_9, PA_10); |
kolanery | 2:619b02232144 | 18 | |
kolanery | 0:cb667de3a336 | 19 | // Define states for debugging the mouse hardware |
kolanery | 2:619b02232144 | 20 | // const int DRIVE = 1, TURN = 2, DEBUG = 3, STOP = 4; |
kolanery | 0:cb667de3a336 | 21 | // Direction of which to turn |
kolanery | 2:619b02232144 | 22 | // const int LEFT = 0, RIGHT = 1; |
kolanery | 0:cb667de3a336 | 23 | // Start and End Pos |
kolanery | 0:cb667de3a336 | 24 | const int START_POS = 0, END_POS = 0; |
kolanery | 2:619b02232144 | 25 | |
kolanery | 0:cb667de3a336 | 26 | // Terminating condition for the main control loop |
kolanery | 0:cb667de3a336 | 27 | bool hasFoundCenter = false; |
kolanery | 0:cb667de3a336 | 28 | |
kolanery | 0:cb667de3a336 | 29 | // Battery Consumption Indicator |
kolanery | 0:cb667de3a336 | 30 | void setup() { |
szh66 | 6:1bcfda49e146 | 31 | // pc.baud(9600); |
kolanery | 4:73510c7fa316 | 32 | // using the serial functions will have an impact on timing. |
szh66 | 6:1bcfda49e146 | 33 | // serial.printf("voltage value is: %3.3f%%\r\n", battery.read()*100.0f); |
kolanery | 4:73510c7fa316 | 34 | // serial.printf("normalized: 0x%04X \r\n", battery.read_u16()); |
kolanery | 2:619b02232144 | 35 | if (battery.read() < 0.67f){ |
kolanery | 0:cb667de3a336 | 36 | // flash led |
kolanery | 4:73510c7fa316 | 37 | led_1 = 1; |
kolanery | 4:73510c7fa316 | 38 | led_2 = 1; |
kolanery | 4:73510c7fa316 | 39 | led_3 = 1; |
kolanery | 4:73510c7fa316 | 40 | led_4 = 1; |
kolanery | 0:cb667de3a336 | 41 | } |
kolanery | 0:cb667de3a336 | 42 | } |
kolanery | 0:cb667de3a336 | 43 | |
kolanery | 0:cb667de3a336 | 44 | // Performs the basic drive control of the mouse |
kolanery | 0:cb667de3a336 | 45 | int main() { |
kolanery | 4:73510c7fa316 | 46 | DriveControl * driver = new DriveControl (START_POS, END_POS); |
kolanery | 2:619b02232144 | 47 | while(1) { |
kolanery | 2:619b02232144 | 48 | setup(); |
kolanery | 4:73510c7fa316 | 49 | led_1 = 1; |
szh66 | 8:4a32fc9ee939 | 50 | driver->getEncoder(); |
szh66 | 8:4a32fc9ee939 | 51 | wait(1); |
kolanery | 7:7215adbae3da | 52 | //if (!driver->has_front_wall()) { |
szh66 | 8:4a32fc9ee939 | 53 | //driver->drive_forward(); |
kolanery | 7:7215adbae3da | 54 | //} |
kolanery | 7:7215adbae3da | 55 | /* |
kolanery | 7:7215adbae3da | 56 | else if (!driver->has_right_wall) { |
kolanery | 7:7215adbae3da | 57 | // driver->turn_right(); |
kolanery | 7:7215adbae3da | 58 | // turn_right() in drivecontrol will call pid_controller::turn(RIGHT) |
kolanery | 7:7215adbae3da | 59 | } |
kolanery | 7:7215adbae3da | 60 | else if (!driver->has_left_wall) { |
kolanery | 7:7215adbae3da | 61 | // driver->turn_left() |
kolanery | 7:7215adbae3da | 62 | } |
kolanery | 7:7215adbae3da | 63 | else { // has all three walls |
kolanery | 7:7215adbae3da | 64 | // driver->turn_around(); |
kolanery | 7:7215adbae3da | 65 | }*/ |
kolanery | 7:7215adbae3da | 66 | |
szh66 | 8:4a32fc9ee939 | 67 | //wait_ms(1); |
szh66 | 6:1bcfda49e146 | 68 | // driver->stop(); |
kolanery | 0:cb667de3a336 | 69 | } |
kolanery | 2:619b02232144 | 70 | } |