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
Fork of Robocode by
source/main.cpp@33:8a98f8b9d859, 2017-03-20 (annotated)
- Committer:
- cittecla
- Date:
- Mon Mar 20 14:11:46 2017 +0000
- Revision:
- 33:8a98f8b9d859
- Parent:
- 32:777976c4d733
Something
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| cittecla | 32:777976c4d733 | 1 | #include "mbed.h" |
| cittecla | 32:777976c4d733 | 2 | #include "pathfinding.h" |
| cittecla | 27:df11ab63cda4 | 3 | |
| cittecla | 18:a82994e67297 | 4 | |
| cittecla | 18:a82994e67297 | 5 | |
| cittecla | 32:777976c4d733 | 6 | int state = 10; |
| cittecla | 32:777976c4d733 | 7 | bool positioning_state = 0; |
| cittecla | 32:777976c4d733 | 8 | bool mapping_state = 0; |
| cittecla | 31:51f52ffa4b51 | 9 | |
| cittecla | 32:777976c4d733 | 10 | int main() |
| cittecla | 32:777976c4d733 | 11 | { |
| cittecla | 31:51f52ffa4b51 | 12 | |
| cittecla | 32:777976c4d733 | 13 | |
| cittecla | 33:8a98f8b9d859 | 14 | while (timer() < 300) { |
| cittecla | 33:8a98f8b9d859 | 15 | */// 5min |
| cittecla | 33:8a98f8b9d859 | 16 | //******************************************************************************* |
| cittecla | 33:8a98f8b9d859 | 17 | //Non_state machine driven function |
| cittecla | 33:8a98f8b9d859 | 18 | //This functions will be called every cycle, use for safety and sensor functipons |
| cittecla | 33:8a98f8b9d859 | 19 | //******************************************************************************* |
| cittecla | 32:777976c4d733 | 20 | |
| cittecla | 32:777976c4d733 | 21 | safty() { |
| cittecla | 31:51f52ffa4b51 | 22 | |
| cittecla | 31:51f52ffa4b51 | 23 | } |
| cittecla | 31:51f52ffa4b51 | 24 | |
| cittecla | 31:51f52ffa4b51 | 25 | scanning() { |
| cittecla | 32:777976c4d733 | 26 | |
| cittecla | 31:51f52ffa4b51 | 27 | } |
| cittecla | 32:777976c4d733 | 28 | |
| cittecla | 32:777976c4d733 | 29 | if(positioning_state) { |
| cittecla | 32:777976c4d733 | 30 | positioning(); |
| cittecla | 32:777976c4d733 | 31 | } |
| cittecla | 32:777976c4d733 | 32 | if(mapping_state) { |
| cittecla | 32:777976c4d733 | 33 | mapping(); |
| cittecla | 32:777976c4d733 | 34 | } |
| cittecla | 18:a82994e67297 | 35 | |
| cittecla | 33:8a98f8b9d859 | 36 | //******************************************************************************* |
| cittecla | 33:8a98f8b9d859 | 37 | //state machine driven function |
| cittecla | 33:8a98f8b9d859 | 38 | //This functions will only be called when their state is active. |
| cittecla | 33:8a98f8b9d859 | 39 | //The state machine will be in the same state until this action is completed or |
| cittecla | 33:8a98f8b9d859 | 40 | //a safty function kicks in and stops the current function. |
| cittecla | 33:8a98f8b9d859 | 41 | //Every function will return the next active state upon its transition table. |
| cittecla | 33:8a98f8b9d859 | 42 | //State and Transition Table can be found in the State_Machine.xlsx |
| cittecla | 33:8a98f8b9d859 | 43 | //******************************************************************************* |
| cittecla | 32:777976c4d733 | 44 | switch (state) { |
| cittecla | 32:777976c4d733 | 45 | case 0: |
| cittecla | 32:777976c4d733 | 46 | state = emergency_shutdown(); |
| cittecla | 32:777976c4d733 | 47 | break; |
| cittecla | 32:777976c4d733 | 48 | case 1: |
| cittecla | 32:777976c4d733 | 49 | state = colision_detected(); |
| cittecla | 32:777976c4d733 | 50 | break; |
| cittecla | 32:777976c4d733 | 51 | case 2: |
| cittecla | 32:777976c4d733 | 52 | state = current_to_high(); |
| cittecla | 32:777976c4d733 | 53 | break; |
| cittecla | 32:777976c4d733 | 54 | case 3: |
| cittecla | 32:777976c4d733 | 55 | state = overheating(); |
| cittecla | 32:777976c4d733 | 56 | break; |
| cittecla | 31:51f52ffa4b51 | 57 | |
| cittecla | 31:51f52ffa4b51 | 58 | |
| cittecla | 32:777976c4d733 | 59 | case 10: |
| cittecla | 32:777976c4d733 | 60 | state = idel(); |
| cittecla | 32:777976c4d733 | 61 | break; |
| cittecla | 32:777976c4d733 | 62 | case 11: |
| cittecla | 32:777976c4d733 | 63 | state = idel2(); |
| cittecla | 32:777976c4d733 | 64 | break; |
| cittecla | 32:777976c4d733 | 65 | |
| cittecla | 31:51f52ffa4b51 | 66 | |
| cittecla | 32:777976c4d733 | 67 | case 15: |
| cittecla | 32:777976c4d733 | 68 | state = initialisation(); |
| cittecla | 32:777976c4d733 | 69 | break; |
| cittecla | 32:777976c4d733 | 70 | case 16: |
| cittecla | 32:777976c4d733 | 71 | state = engage_motors(); |
| cittecla | 32:777976c4d733 | 72 | break; |
| cittecla | 32:777976c4d733 | 73 | case 17: |
| cittecla | 32:777976c4d733 | 74 | state = test_servos(); |
| cittecla | 32:777976c4d733 | 75 | break; |
| cittecla | 32:777976c4d733 | 76 | case 18: |
| cittecla | 32:777976c4d733 | 77 | state = inital_positioning(); |
| cittecla | 32:777976c4d733 | 78 | break; |
| cittecla | 31:51f52ffa4b51 | 79 | |
| cittecla | 31:51f52ffa4b51 | 80 | |
| cittecla | 32:777976c4d733 | 81 | case 25: |
| cittecla | 32:777976c4d733 | 82 | state = start_positioning(); |
| cittecla | 32:777976c4d733 | 83 | break; |
| cittecla | 32:777976c4d733 | 84 | case 26: |
| cittecla | 32:777976c4d733 | 85 | state = start_mapping(); |
| cittecla | 32:777976c4d733 | 86 | break; |
| cittecla | 32:777976c4d733 | 87 | case 27: |
| cittecla | 32:777976c4d733 | 88 | state = initial_turn(); |
| cittecla | 32:777976c4d733 | 89 | break; |
| cittecla | 31:51f52ffa4b51 | 90 | |
| cittecla | 31:51f52ffa4b51 | 91 | |
| cittecla | 32:777976c4d733 | 92 | case 35: |
| cittecla | 32:777976c4d733 | 93 | state = select_target(); |
| cittecla | 32:777976c4d733 | 94 | break; |
| cittecla | 32:777976c4d733 | 95 | case 36: |
| cittecla | 32:777976c4d733 | 96 | state = pathfinding(); |
| cittecla | 32:777976c4d733 | 97 | break; |
| cittecla | 32:777976c4d733 | 98 | case 37: |
| cittecla | 32:777976c4d733 | 99 | state = remove_target(); |
| cittecla | 32:777976c4d733 | 100 | break; |
| cittecla | 25:08ee4525155b | 101 | |
| cittecla | 19:baa8371d55b4 | 102 | |
| cittecla | 18:a82994e67297 | 103 | |
| cittecla | 32:777976c4d733 | 104 | case 40: |
| cittecla | 32:777976c4d733 | 105 | state = moving(); |
| cittecla | 32:777976c4d733 | 106 | break; |
| cittecla | 32:777976c4d733 | 107 | case 41: |
| cittecla | 32:777976c4d733 | 108 | state = moving_forward_for_distance(); |
| cittecla | 32:777976c4d733 | 109 | break; |
| cittecla | 32:777976c4d733 | 110 | case 42: |
| cittecla | 32:777976c4d733 | 111 | state = moving_backward_for_distance(); |
| cittecla | 32:777976c4d733 | 112 | break; |
| cittecla | 32:777976c4d733 | 113 | case 43: |
| cittecla | 32:777976c4d733 | 114 | state = turn_left_for_deg(); |
| cittecla | 32:777976c4d733 | 115 | break; |
| cittecla | 32:777976c4d733 | 116 | case 44: |
| cittecla | 32:777976c4d733 | 117 | state = turn_right_for_deg(); |
| cittecla | 32:777976c4d733 | 118 | break; |
| cittecla | 32:777976c4d733 | 119 | |
| cittecla | 32:777976c4d733 | 120 | case 46: |
| cittecla | 32:777976c4d733 | 121 | state = move_to_next_coord(); |
| cittecla | 32:777976c4d733 | 122 | break; |
| cittecla | 32:777976c4d733 | 123 | case 47: |
| cittecla | 32:777976c4d733 | 124 | state = move_in_search_for_brick(); |
| cittecla | 32:777976c4d733 | 125 | break; |
| cittecla | 18:a82994e67297 | 126 | |
| cittecla | 18:a82994e67297 | 127 | |
| cittecla | 32:777976c4d733 | 128 | case 50: |
| cittecla | 32:777976c4d733 | 129 | state = grabbing(); |
| cittecla | 32:777976c4d733 | 130 | break; |
| cittecla | 32:777976c4d733 | 131 | case 51: |
| cittecla | 32:777976c4d733 | 132 | state = arm_move_up(); |
| cittecla | 32:777976c4d733 | 133 | break; |
| cittecla | 32:777976c4d733 | 134 | case 52: |
| cittecla | 32:777976c4d733 | 135 | state = arm_move_down(); |
| cittecla | 32:777976c4d733 | 136 | break; |
| cittecla | 32:777976c4d733 | 137 | case 53: |
| cittecla | 32:777976c4d733 | 138 | state = arm_move_to_hold(); |
| cittecla | 32:777976c4d733 | 139 | break; |
| cittecla | 24:6c2fec64f890 | 140 | |
| cittecla | 32:777976c4d733 | 141 | case 55: |
| cittecla | 32:777976c4d733 | 142 | state = oben_grabber(); |
| cittecla | 32:777976c4d733 | 143 | break; |
| cittecla | 32:777976c4d733 | 144 | case 56: |
| cittecla | 32:777976c4d733 | 145 | state = close_grabber(); |
| cittecla | 32:777976c4d733 | 146 | break; |
| cittecla | 32:777976c4d733 | 147 | case 57: |
| cittecla | 32:777976c4d733 | 148 | state = test_color(); |
| cittecla | 25:08ee4525155b | 149 | |
| cittecla | 32:777976c4d733 | 150 | |
| cittecla | 32:777976c4d733 | 151 | default: |
| cittecla | 32:777976c4d733 | 152 | printf("Fatal Error, Unkonwn state!"); |
| cittecla | 32:777976c4d733 | 153 | state = 0; |
| cittecla | 32:777976c4d733 | 154 | break; |
| cittecla | 32:777976c4d733 | 155 | } |
| cittecla | 32:777976c4d733 | 156 | } |
| cittecla | 31:51f52ffa4b51 | 157 | } |
