PES 2 - Gruppe 1 / Mbed 2 deprecated Robocode_Random

Dependencies:   mbed

Fork of Robocode by PES 2 - Gruppe 1

Committer:
cittecla
Date:
Tue May 09 13:58:57 2017 +0000
Revision:
112:c7afe49752b9
Parent:
107:02bc5b4e67b7
Child:
113:c8ea0cd9b20c
Child:
115:720dc5df42a5
a few changes in movement have been done

Who changed what in which revision?

UserRevisionLine numberNew contents of line
cittecla 38:3526c36e4c73 1 #include "Main.h"
cittecla 18:a82994e67297 2
cittecla 18:a82994e67297 3
aeschsim 81:a6f0f827dcb0 4 int state = 10;
cittecla 32:777976c4d733 5 bool positioning_state = 0;
cittecla 32:777976c4d733 6 bool mapping_state = 0;
cittecla 31:51f52ffa4b51 7
cittecla 71:ddf4eb5c3081 8 Timer game_timer;
cittecla 71:ddf4eb5c3081 9
cittecla 93:837a13760026 10
cittecla 32:777976c4d733 11 int main()
cittecla 32:777976c4d733 12 {
cittecla 61:b57577b0072f 13 printf("start...\r\n");
cittecla 94:0381e8b1beda 14 disable_servos();
cittecla 71:ddf4eb5c3081 15 while (game_timer.read() < 300) {
cittecla 64:c2fcf3b349e9 16 wait(0.01f);
cittecla 34:40d8d29b44b8 17 // 5min
cittecla 33:8a98f8b9d859 18 //*******************************************************************************
cittecla 33:8a98f8b9d859 19 //Non_state machine driven function
cittecla 33:8a98f8b9d859 20 //This functions will be called every cycle, use for safety and sensor functipons
cittecla 33:8a98f8b9d859 21 //*******************************************************************************
cittecla 32:777976c4d733 22
cittecla 38:3526c36e4c73 23 safety();
cittecla 31:51f52ffa4b51 24
cittecla 38:3526c36e4c73 25
cittecla 32:777976c4d733 26
cittecla 32:777976c4d733 27 if(positioning_state) {
cittecla 38:3526c36e4c73 28 positioning();
cittecla 32:777976c4d733 29 }
cittecla 32:777976c4d733 30 if(mapping_state) {
cittecla 38:3526c36e4c73 31 mapping();
cittecla 32:777976c4d733 32 }
cittecla 18:a82994e67297 33
cittecla 33:8a98f8b9d859 34 //*******************************************************************************
cittecla 33:8a98f8b9d859 35 //state machine driven function
cittecla 33:8a98f8b9d859 36 //This functions will only be called when their state is active.
cittecla 33:8a98f8b9d859 37 //The state machine will be in the same state until this action is completed or
cittecla 33:8a98f8b9d859 38 //a safty function kicks in and stops the current function.
cittecla 33:8a98f8b9d859 39 //Every function will return the next active state upon its transition table.
cittecla 33:8a98f8b9d859 40 //State and Transition Table can be found in the State_Machine.xlsx
cittecla 33:8a98f8b9d859 41 //*******************************************************************************
aeschsim 99:78d87027c85b 42
aeschsim 99:78d87027c85b 43
cittecla 72:4e8a151d804e 44 //printf("state: %d\r\n",state);
cittecla 32:777976c4d733 45 switch (state) {
cittecla 38:3526c36e4c73 46 case 0:
cittecla 38:3526c36e4c73 47 state = emergency_shutdown();
cittecla 38:3526c36e4c73 48 break;
cittecla 38:3526c36e4c73 49 case 1:
cittecla 38:3526c36e4c73 50 state = colision_detected();
cittecla 38:3526c36e4c73 51 break;
cittecla 38:3526c36e4c73 52 case 2:
cittecla 38:3526c36e4c73 53 state = current_to_high();
cittecla 38:3526c36e4c73 54 break;
cittecla 38:3526c36e4c73 55 case 3:
cittecla 38:3526c36e4c73 56 state = overheating();
cittecla 38:3526c36e4c73 57 break;
cittecla 31:51f52ffa4b51 58
cittecla 31:51f52ffa4b51 59
cittecla 38:3526c36e4c73 60 case 10:
cittecla 71:ddf4eb5c3081 61 state = idle();
cittecla 71:ddf4eb5c3081 62 printf("idle1...\r\n");
cittecla 38:3526c36e4c73 63 break;
cittecla 38:3526c36e4c73 64 case 11:
cittecla 71:ddf4eb5c3081 65 state = idle2();
cittecla 71:ddf4eb5c3081 66 printf("idle2...\r\n");
cittecla 38:3526c36e4c73 67 break;
cittecla 38:3526c36e4c73 68
cittecla 38:3526c36e4c73 69
cittecla 38:3526c36e4c73 70 case 15:
aeschsim 78:d9138c6f82a8 71 state = initialisation(); //init servo is included
cittecla 38:3526c36e4c73 72 break;
cittecla 38:3526c36e4c73 73 case 16:
cittecla 79:92b9d083322d 74 state = inital_arm_positioning();
cittecla 112:c7afe49752b9 75 state = 11; // change state here for test cases
cittecla 38:3526c36e4c73 76 break;
cittecla 71:ddf4eb5c3081 77 case 17:
cittecla 79:92b9d083322d 78 state = initial_positioning();
cittecla 71:ddf4eb5c3081 79 break;
cittecla 31:51f52ffa4b51 80
cittecla 38:3526c36e4c73 81 case 25:
cittecla 58:1a395b6928ee 82 state = 26;
cittecla 71:ddf4eb5c3081 83 game_timer.start();
cittecla 38:3526c36e4c73 84 break;
cittecla 38:3526c36e4c73 85 case 26:
cittecla 58:1a395b6928ee 86 state = 27;
cittecla 71:ddf4eb5c3081 87 positioning_state = 1;
cittecla 71:ddf4eb5c3081 88 break;
cittecla 71:ddf4eb5c3081 89 case 27:
cittecla 71:ddf4eb5c3081 90 state = 28;
cittecla 38:3526c36e4c73 91 mapping_state = 1;
cittecla 38:3526c36e4c73 92 break;
cittecla 71:ddf4eb5c3081 93 case 28:
cittecla 38:3526c36e4c73 94 state = initial_turn();
cittecla 38:3526c36e4c73 95 break;
cittecla 38:3526c36e4c73 96
cittecla 40:a46667b62671 97
cittecla 38:3526c36e4c73 98 case 35:
cittecla 38:3526c36e4c73 99 state = select_target();
cittecla 38:3526c36e4c73 100 break;
cittecla 38:3526c36e4c73 101 case 36:
cittecla 38:3526c36e4c73 102 state = pathfinding();
cittecla 38:3526c36e4c73 103 break;
cittecla 38:3526c36e4c73 104 case 37:
cittecla 41:462d379e85c4 105 state = switch_target_red();
cittecla 41:462d379e85c4 106 break;
cittecla 31:51f52ffa4b51 107
cittecla 31:51f52ffa4b51 108
cittecla 38:3526c36e4c73 109 case 40:
cittecla 38:3526c36e4c73 110 state = moving();
cittecla 38:3526c36e4c73 111 break;
cittecla 54:453f24775644 112
cittecla 38:3526c36e4c73 113
cittecla 38:3526c36e4c73 114 case 46:
cittecla 38:3526c36e4c73 115 state = move_to_next_coord();
cittecla 38:3526c36e4c73 116 break;
cittecla 38:3526c36e4c73 117 case 47:
cittecla 38:3526c36e4c73 118 state = move_in_search_for_brick();
cittecla 38:3526c36e4c73 119 break;
cittecla 87:df8c869a5a52 120 case 48:
cittecla 87:df8c869a5a52 121 state = generate_fake_target();
cittecla 87:df8c869a5a52 122 break;
cittecla 31:51f52ffa4b51 123
cittecla 31:51f52ffa4b51 124
cittecla 38:3526c36e4c73 125 case 50:
cittecla 38:3526c36e4c73 126 state = grabbing();
cittecla 38:3526c36e4c73 127 break;
cittecla 38:3526c36e4c73 128
cittecla 93:837a13760026 129
cittecla 87:df8c869a5a52 130
cittecla 87:df8c869a5a52 131 /******************************************************************************/
aeschsim 80:956f65714207 132 //Testtools
aeschsim 80:956f65714207 133
aeschsim 80:956f65714207 134 case 100: //Testtool for IR sensors
cittecla 79:92b9d083322d 135 printf("sensor 0: %f \r\n", getDistanceIR(0));
cittecla 79:92b9d083322d 136 printf("sensor 1: %f \r\n", getDistanceIR(1));
cittecla 79:92b9d083322d 137 printf("sensor 2: %f \r\n", getDistanceIR(2));
cittecla 79:92b9d083322d 138 printf("sensor 3: %f \r\n", getDistanceIR(3));
cittecla 79:92b9d083322d 139 printf("sensor 4: %f \r\n", getDistanceIR(4));
cittecla 79:92b9d083322d 140 printf("sensor 5: %f \r\n\n", getDistanceIR(5));
cittecla 79:92b9d083322d 141 state = 100;
cittecla 79:92b9d083322d 142 break;
aeschsim 80:956f65714207 143 case 101: //Testtool for get_color
aeschsim 80:956f65714207 144 char str1[] = "GREEN";
aeschsim 80:956f65714207 145 char str2[] = "RED";
aeschsim 80:956f65714207 146 printf("Color: %s\r\n",get_color()? str1 : str2);
aeschsim 80:956f65714207 147 wait_ms(500);
aeschsim 80:956f65714207 148 state = 101;
cittecla 87:df8c869a5a52 149 break;
cittecla 94:0381e8b1beda 150 case 102:
cittecla 107:02bc5b4e67b7 151 move_for_distance_with_radius(1,-0.19);
cittecla 94:0381e8b1beda 152 state = 103;
cittecla 94:0381e8b1beda 153 break;
cittecla 94:0381e8b1beda 154 case 103:
cittecla 107:02bc5b4e67b7 155 float distance = move_for_distance_with_radius(0,0);
cittecla 107:02bc5b4e67b7 156 if(distance < 0) {
cittecla 107:02bc5b4e67b7 157 //printf("remaining deg %f\r\n", deg);
cittecla 94:0381e8b1beda 158 stop_turn();
aeschsim 95:1c6867536350 159 state = 11;
cittecla 94:0381e8b1beda 160 }
aeschsim 96:8da1c57296ff 161 break;
aeschsim 99:78d87027c85b 162
cittecla 32:777976c4d733 163 }
cittecla 32:777976c4d733 164 }
cittecla 71:ddf4eb5c3081 165 }