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: Command CommandPool GenCMD LSM9DS0 Mode Motor PinDetect Xbee mbed
Fork of VR_Robot by
main.cpp@7:348c8891e542, 2015-11-28 (annotated)
- Committer:
- Xiaofei
- Date:
- Sat Nov 28 19:48:30 2015 +0000
- Revision:
- 7:348c8891e542
- Parent:
- 6:7a38f754e030
- Child:
- 8:cc8fe9b9949f
C
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Xiaofei | 7:348c8891e542 | 1 | // Controller code |
| Xiaofei | 7:348c8891e542 | 2 | #pragma once |
| Xiaofei | 7:348c8891e542 | 3 | #include "mbed.h" |
| Xiaofei | 7:348c8891e542 | 4 | #include "CommandPool.h" |
| Xiaofei | 7:348c8891e542 | 5 | #include "Xbee.h" |
| Xiaofei | 7:348c8891e542 | 6 | #include "GenCMD.h" |
| Xiaofei | 7:348c8891e542 | 7 | #include "PinDetect.h" |
| Xiaofei | 7:348c8891e542 | 8 | #include "Mode.h" |
| Xiaofei | 7:348c8891e542 | 9 | |
| Xiaofei | 7:348c8891e542 | 10 | GenCMD gen_cmd; |
| Xiaofei | 7:348c8891e542 | 11 | Xbee xbee(p9,p10,p11); |
| Xiaofei | 7:348c8891e542 | 12 | DigitalOut led(LED1); |
| Xiaofei | 7:348c8891e542 | 13 | Mode mode; |
| Xiaofei | 7:348c8891e542 | 14 | char cmd_buffer = '\0'; |
| Xiaofei | 7:348c8891e542 | 15 | |
| Xiaofei | 7:348c8891e542 | 16 | Serial pc(USBTX,USBRX); |
| Xiaofei | 7:348c8891e542 | 17 | |
| Xiaofei | 7:348c8891e542 | 18 | int main() |
| Xiaofei | 7:348c8891e542 | 19 | { |
| Xiaofei | 7:348c8891e542 | 20 | gen_cmd.init(); |
| Xiaofei | 7:348c8891e542 | 21 | xbee.Reset(); |
| Xiaofei | 7:348c8891e542 | 22 | |
| Xiaofei | 7:348c8891e542 | 23 | while(1) |
| Xiaofei | 7:348c8891e542 | 24 | { |
| Xiaofei | 7:348c8891e542 | 25 | if(mode.on) |
| Xiaofei | 7:348c8891e542 | 26 | { |
| Xiaofei | 7:348c8891e542 | 27 | gen_cmd.GenerateCMD(cmd_buffer); |
| Xiaofei | 7:348c8891e542 | 28 | xbee.Send(cmd_buffer); |
| Xiaofei | 7:348c8891e542 | 29 | led = !led; |
| Xiaofei | 7:348c8891e542 | 30 | } |
| Xiaofei | 7:348c8891e542 | 31 | else |
| Xiaofei | 7:348c8891e542 | 32 | { |
| Xiaofei | 7:348c8891e542 | 33 | xbee.Send(STOP); |
| Xiaofei | 7:348c8891e542 | 34 | } |
| Xiaofei | 7:348c8891e542 | 35 | |
| Xiaofei | 7:348c8891e542 | 36 | wait(0.01); |
| Xiaofei | 7:348c8891e542 | 37 | } |
| Xiaofei | 7:348c8891e542 | 38 | return 0; |
| Xiaofei | 7:348c8891e542 | 39 | } |
| Xiaofei | 7:348c8891e542 | 40 | |
| Xiaofei | 7:348c8891e542 | 41 | /* Robot code |
| Xiaofei | 2:d77f669c7feb | 42 | #pragma once |
| Xiaofei | 0:526a865b9b03 | 43 | #include "mbed.h" |
| Xiaofei | 0:526a865b9b03 | 44 | #include "CommandPool.h" |
| Xiaofei | 2:d77f669c7feb | 45 | #include "Xbee.h" |
| Xiaofei | 5:c1b3251ba5d5 | 46 | #include "GenCMD.h" |
| Xiaofei | 0:526a865b9b03 | 47 | |
| Xiaofei | 0:526a865b9b03 | 48 | Command* cmd; |
| Xiaofei | 0:526a865b9b03 | 49 | CommandPool pool; |
| Xiaofei | 5:c1b3251ba5d5 | 50 | GenCMD gen_cmd; |
| Xiaofei | 5:c1b3251ba5d5 | 51 | Xbee xbee(p9,p10,p11); |
| Xiaofei | 6:7a38f754e030 | 52 | DigitalOut led(LED1); |
| Xiaofei | 5:c1b3251ba5d5 | 53 | |
| Xiaofei | 7:348c8891e542 | 54 | char cmd_buffer='\0'; |
| Xiaofei | 6:7a38f754e030 | 55 | |
| Xiaofei | 0:526a865b9b03 | 56 | int main() |
| Xiaofei | 0:526a865b9b03 | 57 | { |
| Xiaofei | 0:526a865b9b03 | 58 | pool.init(); |
| Xiaofei | 7:348c8891e542 | 59 | xbee.Reset(); |
| Xiaofei | 2:d77f669c7feb | 60 | |
| Xiaofei | 0:526a865b9b03 | 61 | while(1) |
| Xiaofei | 0:526a865b9b03 | 62 | { |
| Xiaofei | 7:348c8891e542 | 63 | xbee.Recv(cmd_buffer); |
| Xiaofei | 7:348c8891e542 | 64 | pc.printf("%i\n",cmd_buffer); |
| Xiaofei | 7:348c8891e542 | 65 | cmd = pool.getCommand(cmd_buffer); |
| Xiaofei | 7:348c8891e542 | 66 | if(cmd) |
| Xiaofei | 7:348c8891e542 | 67 | { |
| Xiaofei | 7:348c8891e542 | 68 | cmd->execute(); |
| Xiaofei | 7:348c8891e542 | 69 | } |
| Xiaofei | 6:7a38f754e030 | 70 | led = !led; |
| Xiaofei | 7:348c8891e542 | 71 | wait(0.01); |
| Xiaofei | 0:526a865b9b03 | 72 | } |
| Xiaofei | 0:526a865b9b03 | 73 | return 0; |
| Xiaofei | 0:526a865b9b03 | 74 | } |
| Xiaofei | 7:348c8891e542 | 75 | */ |
