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(to_container_ortho);
53 // FSM_STATE_DECL(experiment_decider);
54 // FSM_STATE_DECL(approach_next_corn);
55 // FSM_STATE_DECL(rush_the_corn);
56 // FSM_STATE_DECL(turn_around);
57 // FSM_STATE_DECL(zvedej_vidle);
59 /************************************************************************
60 * INITIAL AND STARTING STATES
61 ************************************************************************/
67 tcFast = trajectoryConstraintsDefault;
71 tcSlow = trajectoryConstraintsDefault;
74 tcVerySlow = trajectoryConstraintsDefault;
75 tcVerySlow.maxv = 0.05;
76 tcVerySlow.maxacc = 0.05;
78 FSM_TRANSITION(wait_for_start);
85 void set_initial_position()
88 robot_set_est_pos_trans(0.4 - ROBOT_AXIS_TO_FRONT_M,
89 PLAYGROUND_HEIGHT_M - 0.21,
96 // drive lift to home position
98 // unset the homing request
103 #define WAIT_FOR_START
105 #undef WAIT_FOR_START
108 FSM_STATE(wait_for_start)
111 #ifdef WAIT_FOR_START
112 ul_logdeb("WAIT_FOR_START mode set\n");
114 ul_logdeb("WAIT_FOR_START mode NOT set\n");
117 ul_logdeb("COMPETITION mode set\n");
119 ul_logdeb("COMPETITION mode NOT set\n");
123 pthread_create(&thid, NULL, timing_thread, NULL);
124 #ifdef WAIT_FOR_START
129 /* start competition timer */
130 sem_post(&robot.start);
132 set_initial_position();
133 FSM_TRANSITION(aproach_first_fugure);
137 // We set initial position periodically in
138 // order for it to be updated on the display
139 // if the team color is changed during waiting
141 set_initial_position();
142 if (robot.start_state == START_PLUGGED_IN)
146 case EV_MOTION_ERROR:
148 //case EV_VIDLE_DONE:
149 case EV_SWITCH_STRATEGY:
150 DBG_PRINT_EVENT("unhandled event");
157 // FSM_STATE(zvedej_vidle)
159 // static int cnt = 0;
160 // switch(FSM_EVENT) {
164 // act_vidle((VIDLE_UP - VIDLE_DOWN)*cnt/3 + VIDLE_DOWN, VIDLE_FAST_SPEED);
165 // ul_logdeb("--------------------cnt: %d\n", cnt);
169 // //FSM_TRANSITION(sledge_down);
174 // case EV_VIDLE_DONE:
175 // case EV_MOTION_DONE:
176 // case EV_MOTION_ERROR:
177 // case EV_SWITCH_STRATEGY:
178 // DBG_PRINT_EVENT("unhandled event");
184 /************************************************************************
186 ************************************************************************/
188 FSM_STATE(aproach_first_fugure)
192 // disables using side switches on bumpers when going up
193 robot.use_left_bumper = false;
194 robot.use_right_bumper = false;
195 robot.use_back_bumpers = false;
197 robot_trajectory_new(&tcSlow);
198 robot_trajectory_add_point_trans(
200 PLAYGROUND_HEIGHT_M - (ROBOT_WIDTH_M/2) - 0.05);
201 robot_trajectory_add_final_point_trans(
209 //FSM_TRANSITION(load_first_figure);
213 FSM_TRANSITION(load_first_figure);
217 case EV_MOTION_ERROR:
218 case EV_SWITCH_STRATEGY:
219 DBG_PRINT_EVENT("unhandled event");
225 FSM_STATE(load_first_figure)
229 robot_trajectory_new_backward(&tcSlow);
230 robot_trajectory_add_final_point_trans(
231 0.2+0.1+ROBOT_AXIS_TO_BACK_M,
232 0.29+0.28+0.28, NO_TURN());
240 FSM_TRANSITION(to_red_square);
242 //case EV_VIDLE_DONE:
243 case EV_MOTION_ERROR:
244 case EV_SWITCH_STRATEGY:
245 DBG_PRINT_EVENT("unhandled event");
247 // enables using side switches on bumpers
248 //robot.use_left_switch = true;
249 //robot.use_right_switch = true;
250 //robot.ignore_hokuyo = false;
255 FSM_STATE(to_red_square)
259 robot_trajectory_new(&tcSlow);
260 // face the rim with front of the robot
261 //robot_trajectory_add_final_point_trans(PLAYGROUND_WIDTH_M-0.35, 0.12, ARRIVE_FROM(DEG2RAD(-90), 0.10));
262 // face the rim with back of the robot
263 //robot_trajectory_add_point_trans(0.4+0.05+0.2, 0.35+0.35+0.17);
264 robot_trajectory_add_final_point_trans(0.4+0.05+0.2 + ROBOT_AXIS_TO_FIGURE_CENTER_M, 0.35+0.35+0.17, NO_TURN());
272 //FSM_TRANSITION(wait_for_start);
276 //case EV_VIDLE_DONE:
277 case EV_MOTION_ERROR:
278 case EV_SWITCH_STRATEGY:
279 DBG_PRINT_EVENT("unhandled event");
285 // static enum where_to_go {
290 // } where_to_go = CORN;
292 // static struct corn *corn_to_get;
294 // FSM_STATE(experiment_decider)
297 // switch(FSM_EVENT) {
299 // if (where_to_go == CORN) {
300 // FSM_TRANSITION(approach_next_corn);
301 // } else if (where_to_go == CONTAINER) {
302 // FSM_TRANSITION(rush_the_corn);
303 // } else if (where_to_go == TURN_AROUND) {
304 // FSM_TRANSITION(turn_around);
305 // } else /* NO_MORE_CORN */ {
311 // case EV_VIDLE_DONE:
312 // case EV_MOTION_DONE:
313 // case EV_MOTION_ERROR:
314 // case EV_SWITCH_STRATEGY:
315 // DBG_PRINT_EVENT("unhandled event");
321 // static int cnt = 0;
322 // FSM_STATE(approach_next_corn)
324 // switch(FSM_EVENT) {
327 // robot_get_est_pos(&x, &y, &phi);
328 // ul_logdeb("approach_next_corn: puck cnt: %d, est pos %.3f, %.3f, %.3f\n",
331 // corn_to_get = choose_next_corn();
332 // if (corn_to_get) {
333 // Pos *p = get_corn_approach_position(corn_to_get);
334 // corn_to_get->was_collected = true;
335 // //robot_trajectory_new(&tcFast);
336 // //robot_trajectory_add_final_point_trans(robot_trajectory_add_final_point_trans(p->x, p->y, TURN(p->phi));
337 // robot_goto_trans(p->x, p->y, TURN(p->phi), &tcFast);
339 // where_to_go = CONTAINER;
341 // where_to_go = NO_MORE_CORN;
345 // case EV_MOTION_DONE:
347 // FSM_TRANSITION(experiment_decider);
352 // case EV_VIDLE_DONE:
353 // case EV_MOTION_ERROR:
354 // case EV_SWITCH_STRATEGY:
355 // DBG_PRINT_EVENT("unhandled event");
361 // FSM_STATE(rush_the_corn)
363 // switch(FSM_EVENT) {
366 // if (robot.team_color == BLUE) {
367 // x = corn_to_get->position.x;
369 // x = PLAYGROUND_WIDTH_M - corn_to_get->position.x;
371 // ul_logdeb("x = %.3f, %.3f \n", x, corn_to_get->position.y);
372 // remove_wall_around_corn(x, corn_to_get->position.y);
373 // robot_goto_trans(PLAYGROUND_WIDTH_M - 0.4, 0.15, ARRIVE_FROM(DEG2RAD(-90), 0.02), &tcFast);
374 // where_to_go = TURN_AROUND;
376 // case EV_MOTION_DONE:
377 // FSM_TRANSITION(experiment_decider);
382 // case EV_VIDLE_DONE:
383 // case EV_MOTION_ERROR:
384 // case EV_SWITCH_STRATEGY:
385 // DBG_PRINT_EVENT("unhandled event");
391 // // used to perform the maneuvre
392 // FSM_STATE(turn_around)
394 // switch(FSM_EVENT) {
396 // robot_trajectory_new_backward(&tcFast);
397 // robot_trajectory_add_final_point_trans(PLAYGROUND_WIDTH_M-0.35, 0.45, TURN_CCW(90));
399 // case EV_MOTION_DONE:
400 // where_to_go = CORN;
401 // FSM_TRANSITION(experiment_decider);
406 // case EV_VIDLE_DONE:
407 // case EV_MOTION_ERROR:
408 // case EV_SWITCH_STRATEGY:
409 // DBG_PRINT_EVENT("unhandled event");
416 /************************************************************************
418 ************************************************************************/
425 if (rv) error(1, errno, "robot_init() returned %d\n", rv);
427 robot.obstacle_avoidance_enabled = true;
429 robot.fsm.main.debug_states = 1;
430 robot.fsm.motion.debug_states = 1;
431 //robot.fsm.act.debug_states = 1;
433 robot.fsm.main.state = &fsm_state_main_init;
434 //robot.fsm.main.transition_callback = trans_callback;
435 //robot.fsm.motion.transition_callback = move_trans_callback;
438 if (rv) error(1, errno, "robot_start() returned %d\n", rv);
445 /************************************************************************
447 ************************************************************************/
459 case EV_ACTION_ERROR:
461 case EV_MOTION_ERROR:
462 case EV_SWITCH_STRATEGY:
463 DBG_PRINT_EVENT("unhandled event");