7 #include <movehelper.h>
14 #include "corns_configs.h"
15 #include "actuators.h"
17 #include "match-timing.h"
18 #include "eb2010misc.h"
20 #include "common-states.h"
22 static void set_initial_position()
24 robot_set_est_pos_trans(ROBOT_AXIS_TO_FRONT_M,
25 PLAYGROUND_HEIGHT_M - (ROBOT_WIDTH_M/2),
29 static void actuators_home()
39 robot.check_turn_safety = false;
40 pthread_create(&thid, NULL, timing_thread, NULL);
44 // We set initial position periodically in order for it to be updated
45 // on the display if the team color is changed during waiting for
49 set_initial_position();
50 if (robot.start_state == START_PLUGGED_IN)
56 sem_post(&robot.start);
58 set_initial_position();
63 robot.corns = get_all_corns(robot.corns_conf_side, robot.corns_conf_center);
66 /************************************************************************
67 * Trajectory constraints used, are initialized in the init state
68 ************************************************************************/
70 struct TrajectoryConstraints tcFast, tcSlow, tcVerySlow;
74 FSM_STATE(zvedej_vidle)
81 act_vidle((VIDLE_UP - VIDLE_DOWN)*cnt/3 + VIDLE_DOWN);
82 printf("--------------------cnt: %d\n", cnt);
86 //FSM_TRANSITION(sledge_down);
94 case EV_GOAL_NOT_REACHABLE:
95 DBG_PRINT_EVENT("unhandled event");
101 static enum strategy {
102 OPPONENTS_ORAGES_TOO,
104 } strategy = OPPONENTS_ORAGES_TOO;
106 static enum which_side which_slope;
107 static int slope_cnt = 0;
108 FSM_STATE(approach_the_slope)
112 if (strategy == OPPONENTS_ORAGES_TOO) {
113 if (slope_cnt == 0) {
115 FSM_TRANSITION(climb_the_slope);
116 } else if (slope_cnt == 1) {
117 which_slope = OPPONENTS;
119 x_coord(0.3, which_slope),
120 PLAYGROUND_HEIGHT_M - ROBOT_WIDTH_M/2 - 0.03,
121 ARRIVE_FROM(DEG2RAD(0), 0.02),
125 FSM_TRANSITION(approach_next_corn);
127 } else if (strategy == CORNS_ONLY) {
128 if (slope_cnt == 0) {
130 FSM_TRANSITION(climb_the_slope);
131 } else if (slope_cnt == 1) {
132 FSM_TRANSITION(approach_next_corn);
138 FSM_TRANSITION(climb_the_slope);
144 case EV_ACTION_ERROR:
145 case EV_GOAL_NOT_REACHABLE:
146 DBG_PRINT_EVENT("unhandled event");
152 FSM_STATE(climb_the_slope)
156 // disables using side switches on bumpers when going up
157 robot.use_left_switch = false;
158 robot.use_right_switch = false;
159 robot.use_back_switch = false;
160 act_vidle(VIDLE_DOWN);
161 robot.ignore_hokuyo = true;
162 robot_trajectory_new_backward(&tcSlow);
163 if (which_slope == MINE) {
164 robot_trajectory_add_point_trans(
165 x_coord(0.5 - ROBOT_AXIS_TO_BACK_M, which_slope),
166 PLAYGROUND_HEIGHT_M - (ROBOT_WIDTH_M/2));
168 robot_trajectory_add_point_trans(
169 x_coord(SLOPE_TO_RIM_M + SLOPE_LENGTH_M - ROBOT_AXIS_TO_BACK_M, which_slope),
170 PLAYGROUND_HEIGHT_M - (ROBOT_WIDTH_M/2) +0.01);
172 /* position for collecting oranges*/
173 robot_trajectory_add_final_point_trans(
174 x_coord(SLOPE_TO_RIM_M + SLOPE_LENGTH_M - ROBOT_AXIS_TO_BACK_M + 0.07, which_slope),
175 PLAYGROUND_HEIGHT_M - (ROBOT_WIDTH_M/2) +0.01,
184 FSM_TRANSITION(sledge_down);
188 case EV_ACTION_ERROR:
189 case EV_GOAL_NOT_REACHABLE:
190 DBG_PRINT_EVENT("unhandled event");
196 FSM_STATE(sledge_down)
200 robot_trajectory_new(&tcFast);
201 robot_trajectory_add_point_trans(
202 x_coord(1 - ROBOT_AXIS_TO_BACK_M, which_slope),
203 PLAYGROUND_HEIGHT_M - (ROBOT_WIDTH_M/2)+0.01);
204 robot_trajectory_add_point_trans(
205 x_coord(SLOPE_TO_RIM_M - ROBOT_AXIS_TO_BACK_M - 0.26, which_slope),
206 PLAYGROUND_HEIGHT_M - (ROBOT_WIDTH_M/2) - 0.10);
207 robot_trajectory_add_final_point_trans(
208 x_coord(0.50, which_slope),
209 PLAYGROUND_HEIGHT_M - 0.6,
214 FSM_TRANSITION(to_container_diag);
215 //FSM_TRANSITION(to_container_ortho);
221 case EV_ACTION_ERROR:
222 case EV_GOAL_NOT_REACHABLE:
223 DBG_PRINT_EVENT("unhandled event");
225 // enables using side switches on bumpers
226 robot.use_left_switch = true;
227 robot.use_right_switch = true;
228 robot.use_back_switch = true;
229 robot.ignore_hokuyo = false;
230 robot.check_turn_safety = true;
236 FSM_STATE(to_container_diag)
240 if (which_slope == MINE) {
241 robot_trajectory_new(&tcFast);
242 // face the rim with front of the robot
243 //robot_trajectory_add_final_point_trans(PLAYGROUND_WIDTH_M-0.35, 0.12, ARRIVE_FROM(DEG2RAD(-90), 0.10));
244 // face the rim with back of the robot
245 robot_trajectory_add_point_trans(PLAYGROUND_WIDTH_M-0.6, 0.35);
246 robot_trajectory_add_final_point_trans(PLAYGROUND_WIDTH_M-0.35, 0.45, ARRIVE_FROM(DEG2RAD(90),0.05));
248 robot_goto_trans(PLAYGROUND_WIDTH_M-0.35, 0.45, ARRIVE_FROM(DEG2RAD(90),0.05), &tcFast);
253 act_vidle(VIDLE_VYSIP);
257 FSM_TRANSITION(approach_the_slope);
258 //FSM_TRANSITION(approach_next_corn);
263 case EV_ACTION_ERROR:
264 case EV_GOAL_NOT_REACHABLE:
265 DBG_PRINT_EVENT("unhandled event");
271 FSM_STATE(to_container_ortho)
275 robot_trajectory_new(&tcFast);
276 robot_trajectory_add_point_trans(
277 SLOPE_TO_RIM_M - ROBOT_AXIS_TO_BACK_M - 0.15,
278 PLAYGROUND_HEIGHT_M - 0.355);
279 robot_trajectory_add_point_trans(0.55, PLAYGROUND_HEIGHT_M - 0.65);
280 robot_trajectory_add_point_trans(0.90, PLAYGROUND_HEIGHT_M - 0.75);
281 robot_trajectory_add_point_trans(PLAYGROUND_WIDTH_M - 0.60, PLAYGROUND_HEIGHT_M - 0.7);
282 robot_trajectory_add_point_trans(PLAYGROUND_WIDTH_M - 0.35, PLAYGROUND_HEIGHT_M - 0.9);
284 // face the rim with front of the robot
285 //robot_trajectory_add_final_point_trans(PLAYGROUND_WIDTH_M-0.35, 0.12, ARRIVE_FROM(DEG2RAD(-90), 0.10));
286 // face the rim with back of the robot
287 robot_trajectory_add_final_point_trans(PLAYGROUND_WIDTH_M-0.35, 0.40, TURN_CCW(DEG2RAD(90)));
290 act_vidle(VIDLE_VYSIP);
296 case EV_ACTION_ERROR:
297 case EV_GOAL_NOT_REACHABLE:
298 DBG_PRINT_EVENT("unhandled event");
304 static enum where_to_go {
309 } where_to_go = CORN;
311 static struct corn *corn_to_get;
313 FSM_STATE(experiment_decider)
318 if (where_to_go == CORN) {
319 FSM_TRANSITION(approach_next_corn);
320 } else if (where_to_go == CONTAINER) {
321 FSM_TRANSITION(rush_the_corn);
322 } else if (where_to_go == TURN_AROUND) {
323 FSM_TRANSITION(turn_around);
324 } else /* NO_MORE_CORN */ {
331 case EV_ACTION_ERROR:
333 case EV_GOAL_NOT_REACHABLE:
334 DBG_PRINT_EVENT("unhandled event");
341 FSM_STATE(approach_next_corn)
346 robot_get_est_pos(&x, &y, &phi);
347 printf("approach_next_corn: puck cnt: %d, est pos %.3f, %.3f, %.3f\n",
350 corn_to_get = choose_next_corn();
352 Pos *p = get_corn_approach_position(corn_to_get);
353 corn_to_get->was_collected = true;
354 //robot_trajectory_new(&tcFast);
355 //robot_trajectory_add_final_point_trans(robot_trajectory_add_final_point_trans(p->x, p->y, TURN(p->phi));
356 robot_goto_trans(p->x, p->y, TURN(p->phi), &tcFast);
358 where_to_go = CONTAINER;
360 where_to_go = NO_MORE_CORN;
366 FSM_TRANSITION(experiment_decider);
372 case EV_ACTION_ERROR:
373 case EV_GOAL_NOT_REACHABLE:
374 DBG_PRINT_EVENT("unhandled event");
380 FSM_STATE(rush_the_corn)
385 if (robot.team_color == BLUE) {
386 x = corn_to_get->position.x;
388 x = PLAYGROUND_WIDTH_M - corn_to_get->position.x;
390 remove_wall_around_corn(x, corn_to_get->position.y);
391 robot_goto_trans(PLAYGROUND_WIDTH_M - 0.4, 0.15, ARRIVE_FROM(DEG2RAD(-90), 0.02), &tcFast);
392 where_to_go = TURN_AROUND;
395 FSM_TRANSITION(experiment_decider);
401 case EV_ACTION_ERROR:
402 case EV_GOAL_NOT_REACHABLE:
403 DBG_PRINT_EVENT("unhandled event");
409 // used to perform the maneuvre
410 FSM_STATE(turn_around)
414 robot_trajectory_new_backward(&tcFast);
415 robot_trajectory_add_final_point_trans(PLAYGROUND_WIDTH_M-0.35, 0.45, TURN_CCW(90));
419 FSM_TRANSITION(experiment_decider);
425 case EV_ACTION_ERROR:
426 case EV_GOAL_NOT_REACHABLE:
427 DBG_PRINT_EVENT("unhandled event");