2 * homologation.cc 08/04/29
4 * Robot's control program intended for homologation (approval phase) on Eurobot 2009.
6 * Copyright: (c) 2009 CTU Dragons
7 * CTU FEE - Department of Control Engineering
20 #include <movehelper.h>
27 #include "actuators.h"
29 #include "match-timing.h"
30 #include "eb2010misc.h"
33 UL_LOG_CUST(ulogd_homologation); /* Log domain name = ulogd + name of the file */
35 /************************************************************************
36 * Trajectory constraints used, are initialized in the init state
37 ************************************************************************/
39 struct TrajectoryConstraints tcFast, tcSlow, tcVerySlow;
41 /************************************************************************
42 * FSM STATES DECLARATION
43 ************************************************************************/
45 /* initial and starting states */
47 FSM_STATE_DECL(wait_for_start);
49 FSM_STATE_DECL(aproach_first_fugure);
50 FSM_STATE_DECL(load_first_figure);
51 FSM_STATE_DECL(to_red_square);
52 FSM_STATE_DECL(go_home);
53 FSM_STATE_DECL(go_out);
54 // FSM_STATE_DECL(experiment_decider);
55 // FSM_STATE_DECL(approach_next_corn);
56 // FSM_STATE_DECL(rush_the_corn);
57 // FSM_STATE_DECL(turn_around);
58 // FSM_STATE_DECL(zvedej_vidle);
60 /************************************************************************
61 * INITIAL AND STARTING STATES
62 ************************************************************************/
68 tcSlow = trajectoryConstraintsDefault;
72 FSM_TRANSITION(wait_for_start);
79 void set_initial_position()
82 robot_set_est_pos_trans(0.4 - ROBOT_AXIS_TO_FRONT_M,
83 PLAYGROUND_HEIGHT_M - 0.21,
90 // drive lift to home position
92 // unset the homing request
97 #define WAIT_FOR_START
102 FSM_STATE(wait_for_start)
105 #ifdef WAIT_FOR_START
106 ul_logdeb("WAIT_FOR_START mode set\n");
108 ul_logdeb("WAIT_FOR_START mode NOT set\n");
111 ul_logdeb("COMPETITION mode set\n");
113 ul_logdeb("COMPETITION mode NOT set\n");
117 pthread_create(&thid, NULL, timing_thread, NULL);
118 #ifdef WAIT_FOR_START
123 /* start competition timer */
124 sem_post(&robot.start);
126 set_initial_position();
127 FSM_TRANSITION(aproach_first_fugure);
131 // We set initial position periodically in
132 // order for it to be updated on the display
133 // if the team color is changed during waiting
135 set_initial_position();
136 if (robot.start_state == START_PLUGGED_IN)
140 case EV_MOTION_ERROR:
142 //case EV_VIDLE_DONE:
143 case EV_SWITCH_STRATEGY:
144 DBG_PRINT_EVENT("unhandled event");
151 // FSM_STATE(zvedej_vidle)
153 // static int cnt = 0;
154 // switch(FSM_EVENT) {
158 // act_vidle((VIDLE_UP - VIDLE_DOWN)*cnt/3 + VIDLE_DOWN, VIDLE_FAST_SPEED);
159 // ul_logdeb("--------------------cnt: %d\n", cnt);
163 // //FSM_TRANSITION(sledge_down);
168 // case EV_VIDLE_DONE:
169 // case EV_MOTION_DONE:
170 // case EV_MOTION_ERROR:
171 // case EV_SWITCH_STRATEGY:
172 // DBG_PRINT_EVENT("unhandled event");
178 /************************************************************************
180 ************************************************************************/
182 FSM_STATE(aproach_first_fugure)
186 // disables using side switches on bumpers when going up
187 robot.use_left_bumper = false;
188 robot.use_right_bumper = false;
189 robot.use_back_bumpers = false;
191 robot_trajectory_new(&tcSlow);
192 //robot_move_by(0.5, NO_TURN(), &tcSlow);
193 robot_trajectory_add_point_trans(
195 PLAYGROUND_HEIGHT_M - (ROBOT_WIDTH_M/2) - 0.05);
196 robot_trajectory_add_final_point_trans(
204 //FSM_TRANSITION(load_first_figure);
208 FSM_TRANSITION(load_first_figure);
212 case EV_MOTION_ERROR:
213 case EV_SWITCH_STRATEGY:
214 DBG_PRINT_EVENT("unhandled event");
220 FSM_STATE(load_first_figure)
224 robot_trajectory_new_backward(&tcSlow);
225 robot_trajectory_add_final_point_trans(
226 0.2+0.1+ROBOT_AXIS_TO_BACK_M,
227 0.29+0.28+0.28, NO_TURN());
235 FSM_TRANSITION(to_red_square);
238 //case EV_VIDLE_DONE:
239 case EV_MOTION_ERROR:
240 case EV_SWITCH_STRATEGY:
241 DBG_PRINT_EVENT("unhandled event");
243 // enables using side switches on bumpers
244 //robot.use_left_switch = true;
245 //robot.use_right_switch = true;
246 //robot.ignore_hokuyo = false;
251 FSM_STATE(to_red_square)
255 robot.use_left_bumper = true;
256 robot.use_right_bumper = true;
257 robot.use_back_bumpers = true;
258 robot_trajectory_new(&tcSlow);
259 // face the rim with front of the robot
260 //robot_trajectory_add_final_point_trans(PLAYGROUND_WIDTH_M-0.35, 0.12, ARRIVE_FROM(DEG2RAD(-90), 0.10));
261 // face the rim with back of the robot
262 //robot_trajectory_add_point_trans(0.4+0.05+0.2, 0.35+0.35+0.17);
263 robot_trajectory_add_final_point_trans(0.4+0.05+0.2 + ROBOT_AXIS_TO_FIGURE_CENTER_M + 0.05, 0.35+0.35+0.17, NO_TURN());
271 FSM_TRANSITION(go_out);
275 //case EV_VIDLE_DONE:
276 case EV_MOTION_ERROR:
277 case EV_SWITCH_STRATEGY:
278 DBG_PRINT_EVENT("unhandled event");
284 // static enum where_to_go {
289 // } where_to_go = CORN;
291 // static struct corn *corn_to_get;
297 robot_move_by(0.2, NO_TURN(), &tcSlow);
298 // face the rim with front of the robot
302 FSM_TRANSITION(go_home);
309 case EV_MOTION_ERROR:
310 case EV_SWITCH_STRATEGY:
311 DBG_PRINT_EVENT("unhandled event");
322 robot_trajectory_new(&tcSlow);
323 robot_trajectory_add_final_point_trans(0.4, PLAYGROUND_HEIGHT_M - 0.2, ARRIVE_FROM(DEG2RAD(180), 0.20));
329 case EV_MOTION_ERROR:
330 case EV_SWITCH_STRATEGY:
331 DBG_PRINT_EVENT("unhandled event");
336 // static int cnt = 0;
337 // FSM_STATE(approach_next_corn)
339 // switch(FSM_EVENT) {
342 // robot_get_est_pos(&x, &y, &phi);
343 // ul_logdeb("approach_next_corn: puck cnt: %d, est pos %.3f, %.3f, %.3f\n",
346 // corn_to_get = choose_next_corn();
347 // if (corn_to_get) {
348 // Pos *p = get_corn_approach_position(corn_to_get);
349 // corn_to_get->was_collected = true;
350 // //robot_trajectory_new(&tcFast);
351 // //robot_trajectory_add_final_point_trans(robot_trajectory_add_final_point_trans(p->x, p->y, TURN(p->phi));
352 // robot_goto_trans(p->x, p->y, TURN(p->phi), &tcFast);
354 // where_to_go = CONTAINER;
356 // where_to_go = NO_MORE_CORN;
360 // case EV_MOTION_DONE:
362 // FSM_TRANSITION(experiment_decider);
367 // case EV_VIDLE_DONE:
368 // case EV_MOTION_ERROR:
369 // case EV_SWITCH_STRATEGY:
370 // DBG_PRINT_EVENT("unhandled event");
376 // FSM_STATE(rush_the_corn)
378 // switch(FSM_EVENT) {
381 // if (robot.team_color == BLUE) {
382 // x = corn_to_get->position.x;
384 // x = PLAYGROUND_WIDTH_M - corn_to_get->position.x;
386 // ul_logdeb("x = %.3f, %.3f \n", x, corn_to_get->position.y);
387 // remove_wall_around_corn(x, corn_to_get->position.y);
388 // robot_goto_trans(PLAYGROUND_WIDTH_M - 0.4, 0.15, ARRIVE_FROM(DEG2RAD(-90), 0.02), &tcFast);
389 // where_to_go = TURN_AROUND;
391 // case EV_MOTION_DONE:
392 // FSM_TRANSITION(experiment_decider);
397 // case EV_VIDLE_DONE:
398 // case EV_MOTION_ERROR:
399 // case EV_SWITCH_STRATEGY:
400 // DBG_PRINT_EVENT("unhandled event");
406 // // used to perform the maneuvre
407 // FSM_STATE(turn_around)
409 // switch(FSM_EVENT) {
411 // robot_trajectory_new_backward(&tcFast);
412 // robot_trajectory_add_final_point_trans(PLAYGROUND_WIDTH_M-0.35, 0.45, TURN_CCW(90));
414 // case EV_MOTION_DONE:
415 // where_to_go = CORN;
416 // FSM_TRANSITION(experiment_decider);
421 // case EV_VIDLE_DONE:
422 // case EV_MOTION_ERROR:
423 // case EV_SWITCH_STRATEGY:
424 // DBG_PRINT_EVENT("unhandled event");
431 /************************************************************************
433 ************************************************************************/
440 if (rv) error(1, errno, "robot_init() returned %d\n", rv);
442 robot.obstacle_avoidance_enabled = true;
444 robot.fsm.main.debug_states = 1;
445 robot.fsm.motion.debug_states = 1;
446 //robot.fsm.act.debug_states = 1;
448 robot.fsm.main.state = &fsm_state_main_init;
449 //robot.fsm.main.transition_callback = trans_callback;
450 //robot.fsm.motion.transition_callback = move_trans_callback;
453 if (rv) error(1, errno, "robot_start() returned %d\n", rv);
460 /************************************************************************
462 ************************************************************************/
474 case EV_ACTION_ERROR:
476 case EV_MOTION_ERROR:
477 case EV_SWITCH_STRATEGY:
478 DBG_PRINT_EVENT("unhandled event");