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);
56 tcSlow = trajectoryConstraintsDefault;
60 FSM_TRANSITION(wait_for_start);
67 void set_initial_position()
69 // TODO define initial position
70 robot_set_est_pos_trans(ROBOT_AXIS_TO_BACK_M,
71 PLAYGROUND_HEIGHT_M - (ROBOT_WIDTH_M/2.0),
78 // drive lift to home position
80 // unset the homing request
84 FSM_STATE(wait_for_start)
88 ul_logdeb("WAIT_FOR_START mode set\n");
90 ul_logdeb("WAIT_FOR_START mode NOT set\n");
93 ul_logdeb("COMPETITION mode set\n");
95 ul_logdeb("COMPETITION mode NOT set\n");
99 pthread_create(&thid, NULL, timing_thread, NULL);
100 #ifdef WAIT_FOR_START
105 /* start competition timer */
106 sem_post(&robot.start);
108 set_initial_position();
109 FSM_TRANSITION(aproach_buillon);
113 // We set initial position periodically in
114 // order for it to be updated on the display
115 // if the team color is changed during waiting
117 set_initial_position();
118 if (robot.start_state == START_PLUGGED_IN)
122 case EV_MOTION_ERROR:
124 //case EV_VIDLE_DONE:
125 case EV_SWITCH_STRATEGY:
126 DBG_PRINT_EVENT("unhandled event");
135 FSM_STATE(aproach_buillon)
139 robot_trajectory_new(&tcSlow); // new trajectory
140 robot_trajectory_add_point_trans(
142 PLAYGROUND_HEIGHT_M - (ROBOT_WIDTH_M/2.0));
143 robot_trajectory_add_point_trans(
146 robot_trajectory_add_final_point_trans(
153 FSM_TRANSITION(reach_central_buillon);
160 FSM_STATE(push_bottle)
164 robot_trajectory_new(&tcSlow); // new trajectory
165 robot_trajectory_add_point_trans(
168 robot_trajectory_add_final_point_trans(
170 ROBOT_AXIS_TO_FRONT_M + 0.05,
171 ARRIVE_FROM(DEG2RAD(270), 0.10));
174 FSM_TRANSITION(reach_central_buillon);
181 FSM_STATE(reach_central_buillon)
185 robot_trajectory_new(&tcSlow); // new trajectory
186 robot_trajectory_add_point_trans(
189 robot_trajectory_add_point_trans(
192 robot_trajectory_add_final_point_trans(
198 FSM_TRANSITION(leave_central_buillon);
205 FSM_STATE(leave_central_buillon)
209 robot_trajectory_new_backward(&tcSlow); // new trajectory
210 robot_trajectory_add_final_point_trans(
216 FSM_TRANSITION(push_bottle_bw);
223 FSM_STATE(push_bottle_bw)
227 robot_trajectory_new_backward(&tcSlow); // new trajectory
228 robot_trajectory_add_point_trans(
231 robot_trajectory_add_final_point_trans(
233 ROBOT_AXIS_TO_BACK_M + 0.05,
234 ARRIVE_FROM(DEG2RAD(270), 0.10));
242 /************************************************************************
244 ************************************************************************/
251 if (rv) error(1, errno, "robot_init() returned %d\n", rv);
253 robot.obstacle_avoidance_enabled = true;
255 robot.fsm.main.debug_states = 1;
256 robot.fsm.motion.debug_states = 1;
257 //robot.fsm.act.debug_states = 1;
259 robot.fsm.main.state = &fsm_state_main_init;
260 //robot.fsm.main.transition_callback = trans_callback;
261 //robot.fsm.motion.transition_callback = move_trans_callback;
264 if (rv) error(1, errno, "robot_start() returned %d\n", rv);