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);
53 FSM_STATE_DECL(goto_totem2);
54 FSM_STATE_DECL(approach_totem2);
55 FSM_STATE_DECL(leave_totem2);
57 FSM_STATE_DECL(go_home);
63 tcSlow = trajectoryConstraintsDefault;
67 FSM_TRANSITION(wait_for_start);
74 void set_initial_position()
76 // TODO define initial position
77 robot_set_est_pos_trans(ROBOT_AXIS_TO_BACK_M,
78 PLAYGROUND_HEIGHT_M - (ROBOT_WIDTH_M/2.0),
85 // drive lift to home position
87 // unset the homing request
91 FSM_STATE(wait_for_start)
95 ul_logdeb("WAIT_FOR_START mode set\n");
97 ul_logdeb("WAIT_FOR_START mode NOT set\n");
100 ul_logdeb("COMPETITION mode set\n");
102 ul_logdeb("COMPETITION mode NOT set\n");
106 pthread_create(&thid, NULL, timing_thread, NULL);
107 #ifdef WAIT_FOR_START
112 /* start competition timer */
113 sem_post(&robot.start);
115 set_initial_position();
116 FSM_TRANSITION(aproach_buillon);
120 // We set initial position periodically in
121 // order for it to be updated on the display
122 // if the team color is changed during waiting
124 set_initial_position();
125 if (robot.start_state == START_PLUGGED_IN)
129 case EV_MOTION_ERROR:
131 //case EV_VIDLE_DONE:
132 case EV_SWITCH_STRATEGY:
133 DBG_PRINT_EVENT("unhandled event");
142 FSM_STATE(aproach_buillon)
146 robot_trajectory_new(&tcSlow); // new trajectory
147 robot_trajectory_add_point_trans(
149 PLAYGROUND_HEIGHT_M - (ROBOT_WIDTH_M/2.0));
150 robot_trajectory_add_final_point_trans(
153 TURN_CW(DEG2RAD(180)));
157 FSM_TRANSITION(place_buillon);
164 FSM_STATE(place_buillon)
168 robot_trajectory_new(&tcSlow);
169 robot_trajectory_add_final_point_trans(
170 ROBOT_AXIS_TO_FRONT_M + ROBOT_JAWS_LENGHT_M,
176 FSM_TRANSITION(leave_buillon);
183 FSM_STATE(leave_buillon)
187 robot_trajectory_new_backward(&tcSlow); // new trajectory
188 robot_trajectory_add_final_point_trans(
195 FSM_TRANSITION(push_bottle);
202 FSM_STATE(push_bottle)
206 robot_trajectory_new(&tcSlow); // new trajectory
207 robot_trajectory_add_point_trans(
210 robot_trajectory_add_final_point_trans(
212 ROBOT_AXIS_TO_FRONT_M + 0.05,
213 ARRIVE_FROM(DEG2RAD(270), 0.10));
216 FSM_TRANSITION(leave_bottle);
223 FSM_STATE(leave_bottle)
227 robot_trajectory_new_backward(&tcSlow); // new trajectory
228 robot_trajectory_add_final_point_trans(
231 TURN_CCW(DEG2RAD(180)));
235 FSM_TRANSITION(goto_totem);
242 FSM_STATE(goto_totem)
246 robot_trajectory_new(&tcSlow); // new trajectory
247 robot_trajectory_add_final_point_trans(
250 TURN_CCW(DEG2RAD(90)));
253 FSM_TRANSITION(approach_totem);
260 FSM_STATE(approach_totem)
264 robot_trajectory_new(&tcSlow); // new trajectory
265 robot_trajectory_add_final_point_trans(
267 0.875 - ROBOT_AXIS_TO_FRONT_M - 0.05,
268 ARRIVE_FROM(DEG2RAD(90), 0.10));
271 FSM_TRANSITION(leave_totem);
277 FSM_STATE(leave_totem)
281 robot_trajectory_new_backward(&tcSlow); // new trajectory
282 robot_trajectory_add_final_point_trans(
288 FSM_TRANSITION(goto_totem2);
294 FSM_STATE(goto_totem2)
298 robot_trajectory_new(&tcSlow); // new trajectory
299 robot_trajectory_add_point_trans(
302 robot_trajectory_add_point_trans(
305 robot_trajectory_add_final_point_trans(
308 ARRIVE_FROM(DEG2RAD(270),0.1));
311 FSM_TRANSITION(approach_totem2);
318 FSM_STATE(approach_totem2)
322 robot_trajectory_new(&tcSlow); // new trajectory
323 robot_trajectory_add_final_point_trans(
325 1.125 + ROBOT_AXIS_TO_FRONT_M + 0.05,
326 ARRIVE_FROM(DEG2RAD(270), 0.10));
329 FSM_TRANSITION(leave_totem2);
335 FSM_STATE(leave_totem2)
339 robot_trajectory_new_backward(&tcSlow); // new trajectory
340 robot_trajectory_add_final_point_trans(
346 FSM_TRANSITION(go_home);
356 robot_trajectory_new(&tcSlow); // new trajectory
357 robot_trajectory_add_final_point_trans(
358 0.5 + ROBOT_AXIS_TO_FRONT_M,
360 ARRIVE_FROM(DEG2RAD(180),0.1));
368 // totem 1100 x 1000 polovička totemu 125
369 // druhá láhev na 1883
371 /************************************************************************
373 ************************************************************************/
380 if (rv) error(1, errno, "robot_init() returned %d\n", rv);
382 robot.obstacle_avoidance_enabled = true;
384 robot.fsm.main.debug_states = 1;
385 robot.fsm.motion.debug_states = 1;
386 //robot.fsm.act.debug_states = 1;
388 robot.fsm.main.state = &fsm_state_main_init;
389 //robot.fsm.main.transition_callback = trans_callback;
390 //robot.fsm.motion.transition_callback = move_trans_callback;
393 if (rv) error(1, errno, "robot_start() returned %d\n", rv);