2 * homologation.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(load_buillon);
45 FSM_STATE_DECL(place_buillon);
46 FSM_STATE_DECL(leave_buillon);
47 /* Pushing the bottle */
48 FSM_STATE_DECL(push_bottle);
55 tcSlow = trajectoryConstraintsDefault;
59 FSM_TRANSITION(wait_for_start);
66 void set_initial_position()
68 // TODO define initial position
69 robot_set_est_pos_trans(ROBOT_AXIS_TO_BACK_M,
70 PLAYGROUND_HEIGHT_M - (ROBOT_WIDTH_M/2.0),
77 // drive lift to home position
79 // unset the homing request
83 FSM_STATE(wait_for_start)
87 ul_logdeb("WAIT_FOR_START mode set\n");
89 ul_logdeb("WAIT_FOR_START mode NOT set\n");
92 ul_logdeb("COMPETITION mode set\n");
94 ul_logdeb("COMPETITION mode NOT set\n");
98 pthread_create(&thid, NULL, timing_thread, NULL);
104 /* start competition timer */
105 sem_post(&robot.start);
107 set_initial_position();
108 FSM_TRANSITION(aproach_buillon);
112 // We set initial position periodically in
113 // order for it to be updated on the display
114 // if the team color is changed during waiting
116 set_initial_position();
117 if (robot.start_state == START_PLUGGED_IN)
121 case EV_MOTION_ERROR:
123 //case EV_VIDLE_DONE:
124 case EV_SWITCH_STRATEGY:
125 DBG_PRINT_EVENT("unhandled event");
134 FSM_STATE(aproach_buillon)
138 robot_trajectory_new(&tcSlow); // new trajectory
139 robot_trajectory_add_point_trans(
141 PLAYGROUND_HEIGHT_M - (ROBOT_WIDTH_M/2.0));
142 robot_trajectory_add_final_point_trans(
145 TURN_CW(DEG2RAD(180)));
149 FSM_TRANSITION(place_buillon);
156 /*FSM_STATE(load_buillon)
160 robot_trajectory_new(&tcSlow);
161 robot_trajectory_add_final_point_trans(
171 FSM_TRANSITION(place_buillon);
178 FSM_STATE(place_buillon)
182 robot_trajectory_new(&tcSlow);
183 robot_trajectory_add_final_point_trans(
184 ROBOT_AXIS_TO_FRONT_M + ROBOT_JAWS_LENGHT_M,
190 FSM_TRANSITION(leave_buillon);
197 FSM_STATE(leave_buillon)
201 robot_trajectory_new_backward(&tcSlow); // new trajectory
202 robot_trajectory_add_final_point_trans(
209 FSM_TRANSITION(push_bottle);
216 FSM_STATE(push_bottle)
220 robot_trajectory_new(&tcSlow); // new trajectory
221 robot_trajectory_add_point_trans(
224 robot_trajectory_add_final_point_trans(
226 ROBOT_AXIS_TO_FRONT_M + 0.05,
227 ARRIVE_FROM(DEG2RAD(270), 0.10));
235 /************************************************************************
237 ************************************************************************/
244 if (rv) error(1, errno, "robot_init() returned %d\n", rv);
246 robot.obstacle_avoidance_enabled = true;
248 robot.fsm.main.debug_states = 1;
249 robot.fsm.motion.debug_states = 1;
250 //robot.fsm.act.debug_states = 1;
252 robot.fsm.main.state = &fsm_state_main_init;
253 //robot.fsm.main.transition_callback = trans_callback;
254 //robot.fsm.motion.transition_callback = move_trans_callback;
257 if (rv) error(1, errno, "robot_start() returned %d\n", rv);