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 /* from homologation */
43 /* movement states - buillon */
44 FSM_STATE_DECL(aproach_buillon);
45 /* Pushing the bottle */
46 FSM_STATE_DECL(push_bottle);
48 FSM_STATE_DECL(reach_central_buillon);
49 FSM_STATE_DECL(leave_central_buillon);
50 FSM_STATE_DECL(push_bottle_bw);
51 FSM_STATE_DECL(return_home);
57 tcSlow = trajectoryConstraintsDefault;
61 FSM_TRANSITION(wait_for_start);
68 void set_initial_position()
70 // TODO define initial position
71 robot_set_est_pos_trans(ROBOT_AXIS_TO_BACK_M,
72 PLAYGROUND_HEIGHT_M - (ROBOT_WIDTH_M/2.0),
79 // drive lift to home position
81 // unset the homing request
85 FSM_STATE(wait_for_start)
89 ul_logdeb("WAIT_FOR_START mode set\n");
91 ul_logdeb("WAIT_FOR_START mode NOT set\n");
94 ul_logdeb("COMPETITION mode set\n");
96 ul_logdeb("COMPETITION mode NOT set\n");
100 pthread_create(&thid, NULL, timing_thread, NULL);
101 #ifdef WAIT_FOR_START
106 /* start competition timer */
107 sem_post(&robot.start);
109 set_initial_position();
110 FSM_TRANSITION(aproach_buillon);
114 // We set initial position periodically in
115 // order for it to be updated on the display
116 // if the team color is changed during waiting
118 set_initial_position();
119 if (robot.start_state == START_PLUGGED_IN)
123 case EV_MOTION_ERROR:
125 //case EV_VIDLE_DONE:
126 case EV_SWITCH_STRATEGY:
127 DBG_PRINT_EVENT("unhandled event");
136 FSM_STATE(aproach_buillon)
140 robot_trajectory_new(&tcSlow); // new trajectory
141 robot_trajectory_add_point_trans(
143 PLAYGROUND_HEIGHT_M - (ROBOT_WIDTH_M/2.0));
144 robot_trajectory_add_point_trans(
147 robot_trajectory_add_final_point_trans(
154 FSM_TRANSITION(reach_central_buillon);
161 FSM_STATE(push_bottle)
165 robot_trajectory_new(&tcSlow); // new trajectory
166 robot_trajectory_add_point_trans(
169 robot_trajectory_add_final_point_trans(
171 ROBOT_AXIS_TO_FRONT_M + 0.05,
172 ARRIVE_FROM(DEG2RAD(270), 0.10));
175 FSM_TRANSITION(reach_central_buillon);
182 FSM_STATE(reach_central_buillon)
186 robot_trajectory_new(&tcSlow); // new trajectory
187 robot_trajectory_add_point_trans(
190 robot_trajectory_add_point_trans(
193 robot_trajectory_add_final_point_trans(
199 FSM_TRANSITION(leave_central_buillon);
206 FSM_STATE(leave_central_buillon)
210 robot_trajectory_new_backward(&tcSlow); // new trajectory
211 robot_trajectory_add_final_point_trans(
217 FSM_TRANSITION(push_bottle_bw);
224 FSM_STATE(push_bottle_bw)
228 robot_trajectory_new_backward(&tcSlow); // new trajectory
229 robot_trajectory_add_point_trans(
232 robot_trajectory_add_final_point_trans(
234 ROBOT_AXIS_TO_BACK_M + 0.05,
235 ARRIVE_FROM(DEG2RAD(270), 0.10));
238 FSM_TRANSITION(return_home);
245 FSM_STATE(return_home)
249 robot_trajectory_new(&tcSlow); // new trajectory
250 robot_trajectory_add_point_trans(
253 robot_trajectory_add_final_point_trans(
256 ARRIVE_FROM(DEG2RAD(180), 0.10));
264 /************************************************************************
266 ************************************************************************/
273 if (rv) error(1, errno, "robot_init() returned %d\n", rv);
275 robot.obstacle_avoidance_enabled = true;
277 robot.fsm.main.debug_states = 1;
278 robot.fsm.motion.debug_states = 1;
279 //robot.fsm.act.debug_states = 1;
281 robot.fsm.main.state = &fsm_state_main_init;
282 //robot.fsm.main.transition_callback = trans_callback;
283 //robot.fsm.motion.transition_callback = move_trans_callback;
286 if (rv) error(1, errno, "robot_start() returned %d\n", rv);