typedef enum {
LOAD_SUCCESS = 0,
LOAD_FAIL,
- LOOK_AROUND_SUCCESS,
- LOOK_AROUND_FAIL
+ //LOOK_AROUND_SUCCESS, // obsolete, no sharp sensor
+ //LOOK_AROUND_FAIL // obsolete, no sharp sensor
} SUBFSM_RET_VAL;
#define FSM_EVENT_RET_VAL ((SUBFSM_RET_VAL)FSM_EVENT_PTR)
struct TrajectoryConstraints tcFast, tcSlow;
/************************************************************************
- * Trajectory constraints used, are initialized in the init state
+ * Variables related to puck collecting
************************************************************************/
-int free_puck_to_get_next = 0; // next free puck number (index of the free_puck_pick_up_sequence array) to pick up
+int free_puck_to_try_to_get_next = 0; // next free puck number (index of the free_puck_pick_up_sequence array) to pick up
/************************************************************************
* Definition of particular "free pucks pick up sequences"
FSM_STATE(collect_free_pucks)
{
static const int lot = 7; // this variable location is temporary...; going to be received from the camera
- static int puck_approach_attempt_no;
switch (FSM_EVENT) {
case EV_ENTRY:
- puck_approach_attempt_no = 0;
- FSM_SIGNAL(ACT, EV_PREPARE_FOR_LOAD, NULL);
- robot_goto_next_puck_in_sequence(lot, free_puck_to_get_next);
+ robot_goto_next_puck_in_sequence(lot, free_puck_to_try_to_get_next);
break;
case EV_MOTION_DONE: {
- printf("-----arrived where the free puck no. %d should be\n", free_puck_to_get_next);
- if (PUCK_REACHABLE(robot.puck_distance)) {
- SUBFSM_TRANSITION(load_the_puck, NULL);
- } else {
- switch (puck_approach_attempt_no) {
- case 0:
- printf("-----moving forward by 5 cm\n");
- robot_move_by(0.05, NO_TURN(), &tcSlow);
- puck_approach_attempt_no++;
- break;
- case 1:
- SUBFSM_TRANSITION(look_around_for_puck, NULL);
- break;
- }
- }
+ printf("-----arrived where the free puck no. %d should be\n", free_puck_to_try_to_get_next);
+ SUBFSM_TRANSITION(load_the_puck, NULL);
}
break;
case EV_RETURN:
switch(FSM_EVENT_RET_VAL) {
+ /* obsolete, no sharp sensor present
case LOOK_AROUND_SUCCESS: // FIXME: test number of pucks loaded!!
printf(">>>>>> Look around succeeded\n");
SUBFSM_TRANSITION(load_the_puck, NULL);
- break;
+ break; */
case LOAD_SUCCESS:
printf(">>>>>> Loading the puck succeeded\n");
- if(free_puck_to_get_next<4) {
- free_puck_to_get_next++;
- robot_goto_next_puck_in_sequence(lot, free_puck_to_get_next);
+ if(free_puck_to_try_to_get_next<4) {
+ free_puck_to_try_to_get_next++;
+ robot_goto_next_puck_in_sequence(lot, free_puck_to_try_to_get_next);
}
- puck_approach_attempt_no = 0;
break;
+ /* obsolete, no sharp sensor present
case LOOK_AROUND_FAIL:
printf(">>>>>> Looking around for the puck FAILED\n");
break; // FIXME: remove the break
+ */
case LOAD_FAIL:
printf(">>>>>> Loading the puck FAILED\n");
- if(free_puck_to_get_next<6) { // FIXME: test number of pucks loaded!!
- free_puck_to_get_next++;
- robot_goto_next_puck_in_sequence(lot, free_puck_to_get_next);
+ if(free_puck_to_try_to_get_next<6) { // FIXME: test number of pucks loaded!!
+ free_puck_to_try_to_get_next++;
+ robot_goto_next_puck_in_sequence(lot, free_puck_to_try_to_get_next);
} else {
// FIXME (TODO): transition to next strategy state
}
break;
case EV_PUCK_REACHABLE:
robot_stop();
- printf("-----reached some free puck, hopefully no. %d\n", free_puck_to_get_next);
+ printf("-----reached some free puck, hopefully no. %d\n", free_puck_to_try_to_get_next);
SUBFSM_TRANSITION(load_the_puck, NULL);
break;
case EV_ACTION_DONE:
FSM_STATE(load_the_puck)
{
+ static int puck_load_attempt_count;
switch (FSM_EVENT) {
case EV_ENTRY:
+ puck_load_attempt_count = 0;
FSM_SIGNAL(ACT, EV_SCRABBLE, NULL);
FSM_TIMER(200);
break;
SUBFSM_RET((void *)LOAD_SUCCESS);
break;
case EV_ACTION_ERROR:
- SUBFSM_RET((void *)LOAD_FAIL);
+ puck_load_attempt_count++;
+ if (puck_load_attempt_count > 2) {
+ SUBFSM_RET((void *)LOAD_FAIL);
+ } else {
+ robot_move_by(0.02, NO_TURN(), &tcSlow);
+ }
break;
case EV_RETURN:
case EV_LASER_POWER:
}
}
+/* of no use without the sharp sensor measuring "puck distance"
FSM_STATE(look_around_for_puck)
{
static int lfp_status = 0;
break;
}
}
+*/
/*