#include <trgen.h>
#include "match-timing.h"
#include "eb2010misc.h"
+#include <stdbool.h>
#include "common-states.h"
+/************************************************************************
+ * Functions used in and called from all the (almost identical)
+ * "wait for start" states in particular strategies.
+ ************************************************************************/
+
static void set_initial_position()
{
robot_set_est_pos_trans(ROBOT_AXIS_TO_FRONT_M,
act_vidle(VIDLE_UP);
}
-
-
void start_entry()
{
pthread_t thid;
}
/************************************************************************
- * Trajectory constraints used, are initialized in the init state
+ * Trajectory constraints used; They are initialized in the main() function in competition.cc
************************************************************************/
struct TrajectoryConstraints tcFast, tcSlow, tcVerySlow;
+#define VIDLE_TIMEOUT 2000
+/************************************************************************
+ * States that form the "collect some oranges" subautomaton. Calling automaton
+ * SHOULD ALWAYS call the "approach_the_slope" state.
+ ************************************************************************/
-FSM_STATE(zvedej_vidle)
-{
- static int cnt = 0;
- switch(FSM_EVENT) {
- case EV_ENTRY:
- case EV_TIMER:
- FSM_TIMER(500);
- act_vidle((VIDLE_UP - VIDLE_DOWN)*cnt/3 + VIDLE_DOWN);
- printf("--------------------cnt: %d\n", cnt);
- cnt++;
- if(cnt >= 3) {
- robot_exit();
- //FSM_TRANSITION(sledge_down);
- }
- break;
- case EV_START:
- case EV_RETURN:
- case EV_ACTION_DONE:
- case EV_ACTION_ERROR:
- case EV_MOTION_DONE:
- case EV_GOAL_NOT_REACHABLE:
- DBG_PRINT_EVENT("unhandled event");
- case EV_EXIT:
- break;
+bool inline is_ready_to_climb_the_slope(enum which_side which_slope, double x, double y) {
+ bool ret;
+ if (which_slope == MINE) {
+ ret = x < 0.5 && y > PLAYGROUND_HEIGHT_M - 0.5;
+ } else if (which_slope == OPPONENTS) {
+ ret = x > 0.5 && y > PLAYGROUND_HEIGHT_M - 0.5;
+ } else {
+ printf("ERROR: unknown side;"); robot_exit();
}
+ return ret;
}
-static enum strategy {
- OPPONENTS_ORAGES_TOO,
- CORNS_ONLY
-} strategy = OPPONENTS_ORAGES_TOO;
-
static enum which_side which_slope;
-static int slope_cnt = 0;
+
+/* assures that the robot is near the slope rim; if outside our starting area, approach the slope first */
FSM_STATE(approach_the_slope)
{
switch(FSM_EVENT) {
- case EV_ENTRY:
- if (strategy == OPPONENTS_ORAGES_TOO) {
- if (slope_cnt == 0) {
- which_slope = MINE;
+ case EV_ENTRY: {
+ which_slope = (enum which_side) FSM_EVENT_INT;
+ double x, y, phi;
+ robot_get_est_pos_trans(&x, &y, &phi);
+ /* decide */
+ bool ready_to_climb_the_slope = is_ready_to_climb_the_slope(which_slope, x, y);
+ /* if necessary, approach the slope */
+ if (ready_to_climb_the_slope) {
FSM_TRANSITION(climb_the_slope);
- } else if (slope_cnt == 1) {
- which_slope = OPPONENTS;
+ } else {
robot_goto_trans(
- x_coord(0.3, which_slope),
- PLAYGROUND_HEIGHT_M - ROBOT_WIDTH_M/2 - 0.03,
- ARRIVE_FROM(DEG2RAD(0), 0.02),
+ x_coord(SLOPE_TO_RIM_M - ROBOT_AXIS_TO_BACK_M - 0.05, which_slope),
+ PLAYGROUND_HEIGHT_M - (ROBOT_WIDTH_M/2) - 0.05,
+ ARRIVE_FROM(DEG2RAD(0),0.05),
&tcFast);
- } else {
- which_slope = MINE;
- FSM_TRANSITION(approach_next_corn);
- }
- } else if (strategy == CORNS_ONLY) {
- if (slope_cnt == 0) {
- which_slope = MINE;
- FSM_TRANSITION(climb_the_slope);
- } else if (slope_cnt == 1) {
- FSM_TRANSITION(approach_next_corn);
}
+ break;
}
- slope_cnt++;
- break;
case EV_MOTION_DONE:
FSM_TRANSITION(climb_the_slope);
break;
}
}
+void inline enable_switches(bool enabled)
+{
+ robot.use_left_switch = enabled;
+ robot.use_right_switch = enabled;
+ robot.use_back_switch = enabled;
+}
+
FSM_STATE(climb_the_slope)
{
switch(FSM_EVENT) {
- case EV_ENTRY:
- // disables using side switches on bumpers when going up
- robot.use_left_switch = false;
- robot.use_right_switch = false;
- robot.use_back_switch = false;
- act_vidle(VIDLE_DOWN);
- robot.ignore_hokuyo = true;
- robot_trajectory_new_backward(&tcSlow);
- if (which_slope == MINE) {
- robot_trajectory_add_point_trans(
- x_coord(0.5 - ROBOT_AXIS_TO_BACK_M, which_slope),
- PLAYGROUND_HEIGHT_M - (ROBOT_WIDTH_M/2));
- } else {
+ case EV_ENTRY: {
+ // disables using side switches on bumpers when going up
+ enable_switches(false);
+ act_vidle(VIDLE_DOWN);
+ robot.ignore_hokuyo = true;
+ /* create the trajectory and go */
+ robot_trajectory_new_backward(&tcSlow);
robot_trajectory_add_point_trans(
x_coord(SLOPE_TO_RIM_M + SLOPE_LENGTH_M - ROBOT_AXIS_TO_BACK_M, which_slope),
PLAYGROUND_HEIGHT_M - (ROBOT_WIDTH_M/2) +0.01);
+ robot_trajectory_add_final_point_trans(
+ x_coord(SLOPE_TO_RIM_M + SLOPE_LENGTH_M - ROBOT_AXIS_TO_BACK_M + 0.07, which_slope),
+ PLAYGROUND_HEIGHT_M - (ROBOT_WIDTH_M/2) +0.01,
+ NO_TURN());
+ break;
}
- /* position for collecting oranges*/
- robot_trajectory_add_final_point_trans(
- x_coord(SLOPE_TO_RIM_M + SLOPE_LENGTH_M - ROBOT_AXIS_TO_BACK_M + 0.07, which_slope),
- PLAYGROUND_HEIGHT_M - (ROBOT_WIDTH_M/2) +0.01,
- NO_TURN());
- break;
case EV_MOTION_DONE:
- FSM_TIMER(2000);
+ FSM_TIMER(VIDLE_TIMEOUT);
act_vidle(VIDLE_UP);
break;
case EV_START:
case EV_TIMER:
+ // FIXME: respond to VIDLE EVENT
FSM_TRANSITION(sledge_down);
break;
case EV_RETURN:
robot_trajectory_add_point_trans(
x_coord(1 - ROBOT_AXIS_TO_BACK_M, which_slope),
PLAYGROUND_HEIGHT_M - (ROBOT_WIDTH_M/2)+0.01);
+ /*
robot_trajectory_add_point_trans(
x_coord(SLOPE_TO_RIM_M - ROBOT_AXIS_TO_BACK_M - 0.26, which_slope),
PLAYGROUND_HEIGHT_M - (ROBOT_WIDTH_M/2) - 0.10);
x_coord(0.50, which_slope),
PLAYGROUND_HEIGHT_M - 0.6,
NO_TURN());
+ */
+ robot_trajectory_add_point_trans(
+ x_coord(SLOPE_TO_RIM_M - ROBOT_AXIS_TO_BACK_M - 0.20, which_slope),
+ PLAYGROUND_HEIGHT_M - (ROBOT_WIDTH_M/2) - 0.08);
+ robot_trajectory_add_final_point_trans(
+ x_coord(SLOPE_TO_RIM_M - ROBOT_AXIS_TO_BACK_M - 0.26, which_slope),
+ PLAYGROUND_HEIGHT_M - (ROBOT_WIDTH_M/2) - 0.14,
+ NO_TURN());
break;
case EV_MOTION_DONE:
+ /* just for sure, try to close it one more time */
act_vidle(VIDLE_UP);
- FSM_TRANSITION(to_container_diag);
- //FSM_TRANSITION(to_container_ortho);
+ SUBFSM_RET(NULL);
break;
case EV_START:
case EV_TIMER:
DBG_PRINT_EVENT("unhandled event");
case EV_EXIT:
// enables using side switches on bumpers
- robot.use_left_switch = true;
- robot.use_right_switch = true;
- robot.use_back_switch = true;
+ enable_switches(true);
robot.ignore_hokuyo = false;
robot.check_turn_safety = true;
}
}
-FSM_STATE(to_container_diag)
+/************************************************************************
+ * The "unload our oranges" subautomaton
+ ************************************************************************/
+
+FSM_STATE(to_cntainer_and_unld)
{
switch(FSM_EVENT) {
case EV_ENTRY:
+ /*
if (which_slope == MINE) {
robot_trajectory_new(&tcFast);
// face the rim with front of the robot
// face the rim with back of the robot
robot_trajectory_add_point_trans(PLAYGROUND_WIDTH_M-0.6, 0.35);
robot_trajectory_add_final_point_trans(PLAYGROUND_WIDTH_M-0.35, 0.45, ARRIVE_FROM(DEG2RAD(90),0.05));
- } else {
+ } else { */
robot_goto_trans(PLAYGROUND_WIDTH_M-0.35, 0.45, ARRIVE_FROM(DEG2RAD(90),0.05), &tcFast);
- }
+ //}
break;
case EV_MOTION_DONE:
- FSM_TIMER(6000);
+ FSM_TIMER(3000); // FIXME: test this
act_vidle(VIDLE_VYSIP);
break;
case EV_TIMER:
act_vidle(VIDLE_UP);
- FSM_TRANSITION(approach_the_slope);
- //FSM_TRANSITION(approach_next_corn);
+ SUBFSM_RET(NULL);
break;
case EV_START:
case EV_RETURN:
}
}
-FSM_STATE(to_container_ortho)
-{
- switch(FSM_EVENT) {
- case EV_ENTRY:
- robot_trajectory_new(&tcFast);
- robot_trajectory_add_point_trans(
- SLOPE_TO_RIM_M - ROBOT_AXIS_TO_BACK_M - 0.15,
- PLAYGROUND_HEIGHT_M - 0.355);
- robot_trajectory_add_point_trans(0.55, PLAYGROUND_HEIGHT_M - 0.65);
- robot_trajectory_add_point_trans(0.90, PLAYGROUND_HEIGHT_M - 0.75);
- robot_trajectory_add_point_trans(PLAYGROUND_WIDTH_M - 0.60, PLAYGROUND_HEIGHT_M - 0.7);
- robot_trajectory_add_point_trans(PLAYGROUND_WIDTH_M - 0.35, PLAYGROUND_HEIGHT_M - 0.9);
-
- // face the rim with front of the robot
- //robot_trajectory_add_final_point_trans(PLAYGROUND_WIDTH_M-0.35, 0.12, ARRIVE_FROM(DEG2RAD(-90), 0.10));
- // face the rim with back of the robot
- robot_trajectory_add_final_point_trans(PLAYGROUND_WIDTH_M-0.35, 0.40, TURN_CCW(DEG2RAD(90)));
- break;
- case EV_MOTION_DONE:
- act_vidle(VIDLE_VYSIP);
- break;
- case EV_START:
- case EV_TIMER:
- case EV_RETURN:
- case EV_ACTION_DONE:
- case EV_ACTION_ERROR:
- case EV_GOAL_NOT_REACHABLE:
- DBG_PRINT_EVENT("unhandled event");
- case EV_EXIT:
- break;
- }
-}
+/************************************************************************
+ * The "collect corns" subautomaton
+ ************************************************************************/
static enum where_to_go {
CORN,
static struct corn *corn_to_get;
-FSM_STATE(experiment_decider)
+FSM_STATE(rush_corns_decider)
{
-
switch(FSM_EVENT) {
case EV_ENTRY:
if (where_to_go == CORN) {
}
case EV_MOTION_DONE:
cnt++;
- FSM_TRANSITION(experiment_decider);
+ FSM_TRANSITION(rush_corns_decider);
break;
case EV_START:
case EV_TIMER:
where_to_go = TURN_AROUND;
break;
case EV_MOTION_DONE:
- FSM_TRANSITION(experiment_decider);
+ FSM_TRANSITION(rush_corns_decider);
break;
case EV_START:
case EV_TIMER:
break;
case EV_MOTION_DONE:
where_to_go = CORN;
- FSM_TRANSITION(experiment_decider);
+ FSM_TRANSITION(rush_corns_decider);
break;
case EV_START:
case EV_TIMER: