7 #include <movehelper.h>
14 #include "actuators.h"
16 #include "match-timing.h"
20 UL_LOG_CUST(ulogd_common_states); /* Log domain name = ulogd + name of the file */
22 #include "common-states.h"
24 /************************************************************************
25 * Functions used in and called from all the (almost identical)
26 * "wait for start" states in particular strategies.
27 ************************************************************************/
30 #define DBG_FSM_STATE(name) do { if (fsm->debug_states) ul_loginf("fsm %s %.1f: %s(%s)\n", \
31 fsm->debug_name, robot_current_time(), \
32 name, fsm_event_str(fsm->events[fsm->ev_head])); } while(0)
35 void set_initial_position()
37 robot_set_est_pos_trans(ROBOT_AXIS_TO_BACK_M,
38 PLAYGROUND_HEIGHT_M - (ROBOT_WIDTH_M/2.0),
45 // drive lift to home position
47 // unset the homing request
54 robot.check_turn_safety = false;
55 pthread_create(&thid, NULL, timing_thread, NULL);
59 // We set initial position periodically in order for it to be updated
60 // on the display if the team color is changed during waiting for
64 set_initial_position();
65 if (robot.start_state == START_PLUGGED_IN)
71 sem_post(&robot.start);
73 set_initial_position();
81 void inline enable_bumpers(bool enabled)
83 robot.use_left_bumper = enabled;
84 robot.use_right_bumper = enabled;
85 robot.use_back_bumpers = enabled;
88 /************************************************************************
89 * Trajectory constraints used; They are initialized in the main() function in competition.cc
90 ************************************************************************/
92 struct TrajectoryConstraints tcJerk, tcFast, tcSlow, tcVerySlow;
94 /* assures that the robot is near the slope rim; if outside our starting area, approach the slope first */
95 FSM_STATE(bypass_figure_in_front_of_start)
99 robot_trajectory_new(&tcSlow);
100 robot_trajectory_add_point_trans(
102 PLAYGROUND_HEIGHT_M - (ROBOT_WIDTH_M/2));
103 robot_trajectory_add_point_trans(
105 PLAYGROUND_HEIGHT_M - 0.35);
106 robot_trajectory_add_final_point_trans(
117 case EV_MOTION_ERROR:
118 case EV_SWITCH_STRATEGY:
119 DBG_PRINT_EVENT("unhandled event");
125 FSM_STATE(approach_second_green_figure)
129 robot.use_left_bumper = true;
130 robot.use_right_bumper = true;
131 robot.use_back_bumpers = true;
133 robot_trajectory_new(&tcSlow);
134 robot_trajectory_add_final_point_trans(
137 ARRIVE_FROM(DEG2RAD(180), 0.10));
144 FSM_TRANSITION(load_second_green_figure);
147 case EV_MOTION_ERROR:
153 FSM_STATE(load_second_green_figure)
157 robot_trajectory_new(&tcSlow);
158 robot_trajectory_add_final_point_trans(
159 ROBOT_AXIS_TO_FIGURE_CENTER_M + 0.05,
168 FSM_TRANSITION(go_out_second_green_figure);
171 case EV_MOTION_ERROR:
173 // enables using side switches on bumpers
174 //robot.use_left_switch = true;
175 //robot.use_right_switch = true;
176 //robot.ignore_hokuyo = false;
181 FSM_STATE(go_out_second_green_figure)
185 robot_trajectory_new_backward(&tcSlow);
186 robot_trajectory_add_final_point_trans(0.45 + 0.35, 0.7, NO_TURN());
190 FSM_TRANSITION(place_figure_to_protected_block);
194 case EV_MOTION_ERROR:
200 FSM_STATE(place_figure_to_protected_block)
204 robot_trajectory_new(&tcSlow);
205 robot_trajectory_add_final_point_trans(
207 0.12 + 0.08 + ROBOT_AXIS_TO_FIGURE_CENTER_M,
208 ARRIVE_FROM(DEG2RAD(-90), 0.20));
212 FSM_TRANSITION(leave_protected_figure);
219 case EV_MOTION_ERROR:
220 case EV_SWITCH_STRATEGY:
221 DBG_PRINT_EVENT("unhandled event");
227 FSM_STATE(leave_protected_figure)
232 robot_trajectory_new_backward(&tcSlow);
233 robot_trajectory_add_point_trans(
236 robot_trajectory_add_final_point_trans(
239 TURN_CW(DEG2RAD(0)));
246 //FSM_TRANSITION(load_second_figure);
249 case EV_MOTION_ERROR: