2 * competition.cc 12/02/28
4 * Robot's control program intended for homologation (approval phase) on Eurobot 2012.
6 * Copyright: (c) 2012 CTU Flamingos
7 * CTU FEE - Department of Control Engineering
16 #include <movehelper.h>
23 #include "actuators.h"
25 #include "match-timing.h"
28 UL_LOG_CUST(ulogd_homologation); /* Log domain name = ulogd + name of the file */
30 /************************************************************************
31 * Trajectory constraints used, are initialized in the init state
32 ************************************************************************/
34 struct TrajectoryConstraints tcFast, tcSlow, tcVerySlow;
36 /************************************************************************
37 * FSM STATES DECLARATION
38 ************************************************************************/
41 FSM_STATE_DECL(wait_for_start);
42 /* movement states - buillon */
43 FSM_STATE_DECL(aproach_buillon);
44 FSM_STATE_DECL(place_buillon);
45 FSM_STATE_DECL(leave_buillon);
46 /* Pushing the bottle */
47 FSM_STATE_DECL(push_bottle);
48 FSM_STATE_DECL(leave_bottle);
49 FSM_STATE_DECL(goto_totem);
50 FSM_STATE_DECL(approach_totem);
51 FSM_STATE_DECL(leave_totem);
52 FSM_STATE_DECL(go_home);
58 tcSlow = trajectoryConstraintsDefault;
62 FSM_TRANSITION(wait_for_start);
69 void set_initial_position()
71 // TODO define initial position
72 robot_set_est_pos_trans(ROBOT_AXIS_TO_BACK_M,
73 PLAYGROUND_HEIGHT_M - (ROBOT_WIDTH_M/2.0),
80 // drive lift to home position
82 // unset the homing request
86 FSM_STATE(wait_for_start)
90 ul_logdeb("WAIT_FOR_START mode set\n");
92 ul_logdeb("WAIT_FOR_START mode NOT set\n");
95 ul_logdeb("COMPETITION mode set\n");
97 ul_logdeb("COMPETITION mode NOT set\n");
101 pthread_create(&thid, NULL, timing_thread, NULL);
102 #ifdef WAIT_FOR_START
107 /* start competition timer */
108 sem_post(&robot.start);
110 set_initial_position();
111 FSM_TRANSITION(aproach_buillon);
115 // We set initial position periodically in
116 // order for it to be updated on the display
117 // if the team color is changed during waiting
119 set_initial_position();
120 if (robot.start_state == START_PLUGGED_IN)
124 case EV_MOTION_ERROR:
126 //case EV_VIDLE_DONE:
127 case EV_SWITCH_STRATEGY:
128 DBG_PRINT_EVENT("unhandled event");
137 FSM_STATE(aproach_buillon)
141 robot_trajectory_new(&tcSlow); // new trajectory
142 robot_trajectory_add_point_trans(
144 PLAYGROUND_HEIGHT_M - (ROBOT_WIDTH_M/2.0));
145 robot_trajectory_add_final_point_trans(
148 TURN_CW(DEG2RAD(180)));
152 FSM_TRANSITION(place_buillon);
159 FSM_STATE(place_buillon)
163 robot_trajectory_new(&tcSlow);
164 robot_trajectory_add_final_point_trans(
165 ROBOT_AXIS_TO_FRONT_M + ROBOT_JAWS_LENGHT_M,
171 FSM_TRANSITION(leave_buillon);
178 FSM_STATE(leave_buillon)
182 robot_trajectory_new_backward(&tcSlow); // new trajectory
183 robot_trajectory_add_final_point_trans(
190 FSM_TRANSITION(push_bottle);
197 FSM_STATE(push_bottle)
201 robot_trajectory_new(&tcSlow); // new trajectory
202 robot_trajectory_add_point_trans(
205 robot_trajectory_add_final_point_trans(
207 ROBOT_AXIS_TO_FRONT_M + 0.05,
208 ARRIVE_FROM(DEG2RAD(270), 0.10));
211 FSM_TRANSITION(leave_bottle);
218 FSM_STATE(leave_bottle)
222 robot_trajectory_new_backward(&tcSlow); // new trajectory
223 robot_trajectory_add_final_point_trans(
226 TURN_CCW(DEG2RAD(180)));
230 FSM_TRANSITION(goto_totem);
237 FSM_STATE(goto_totem)
241 robot_trajectory_new(&tcSlow); // new trajectory
242 robot_trajectory_add_final_point_trans(
245 TURN_CCW(DEG2RAD(90)));
248 FSM_TRANSITION(approach_totem);
255 FSM_STATE(approach_totem)
259 robot_trajectory_new(&tcSlow); // new trajectory
260 robot_trajectory_add_final_point_trans(
262 0.875 - ROBOT_AXIS_TO_FRONT_M - 0.05,
263 ARRIVE_FROM(DEG2RAD(90), 0.10));
266 FSM_TRANSITION(leave_totem);
272 FSM_STATE(leave_totem)
276 robot_trajectory_new_backward(&tcSlow); // new trajectory
277 robot_trajectory_add_final_point_trans(
283 FSM_TRANSITION(go_home);
294 robot_trajectory_new(&tcSlow); // new trajectory
295 robot_trajectory_add_point_trans(
298 robot_trajectory_add_point_trans(
301 robot_trajectory_add_final_point_trans(
304 ARRIVE_FROM(DEG2RAD(180),0.1));
312 // totem 1100 x 1000 polovička totemu 125
313 // druhá láhev na 1883
315 /************************************************************************
317 ************************************************************************/
324 if (rv) error(1, errno, "robot_init() returned %d\n", rv);
326 robot.obstacle_avoidance_enabled = true;
328 robot.fsm.main.debug_states = 1;
329 robot.fsm.motion.debug_states = 1;
330 //robot.fsm.act.debug_states = 1;
332 robot.fsm.main.state = &fsm_state_main_init;
333 //robot.fsm.main.transition_callback = trans_callback;
334 //robot.fsm.motion.transition_callback = move_trans_callback;
337 if (rv) error(1, errno, "robot_start() returned %d\n", rv);