case RBRUSH_DRIVE:
if (robot.orte.laser_cmd.speed == LASER_DRIVE_ON) {
off_laser();
+ ROBOT_LOCK(state);
+ robot.state = JUST_STARTED;
+ ROBOT_UNLOCK(state);
} else {
on_laser();
+ ROBOT_LOCK(state);
+ robot.state = LASER_STARTED;
+ ROBOT_UNLOCK(state);
}
break;
case BAGR_DRIVE:
/* initial and starting states */
FSM_STATE_DECL(init);
-FSM_STATE_DECL(wait_for_deposit);
-FSM_STATE_DECL(wait_for_laser);
FSM_STATE_DECL(wait_for_start);
FSM_STATE_DECL(decide_where_now);
/* movement states */
{
switch (FSM_EVENT) {
case EV_ENTRY:
- robot_set_est_pos_trans(ROBOT_WIDTH_M/2,
- PLAYGROUND_HEIGHT_M - ROBOT_AXIS_TO_BACK_M,
- DEG2RAD(-45));
- FSM_TRANSITION(wait_for_start);
- break;
- default:
- break;
- }
-}
-
-FSM_STATE(wait_for_laser)
-{
- switch (FSM_EVENT) {
-#ifdef WAIT_FOR_START
- case EV_START:
-#else
- case EV_ENTRY:
-#endif
- robot_set_est_pos_trans(ROBOT_WIDTH_M/2,
- PLAYGROUND_HEIGHT_M - ROBOT_AXIS_TO_BACK_M,
- DEG2RAD(-45));
off_brush_left();
off_brush_right();
brushes_out();
open_bottom_door();
close_back_door();
- robot_set_est_pos_trans(ROBOT_WIDTH_M/2,
- PLAYGROUND_HEIGHT_M - ROBOT_AXIS_TO_BACK_M,
- DEG2RAD(-45));
-
- on_laser();
-
-#ifdef WAIT_FOR_START
- FSM_TRANSITION(wait_for_deposit);
-#else
- FSM_TRANSITION(wait_for_start);
-#endif
- default:
- break;
- }
-}
-
-
-FSM_STATE(wait_for_deposit)
-{
- /* start event ocurred */
- switch (FSM_EVENT) {
- case EV_ENTRY:
- FSM_TIMER(2000);
- break;
- case EV_START:
- // If start is given in two seconds
- SUBFSM_TRANSITION(deposite_balls, NULL);
- break;
- case EV_RETURN:
- FSM_TRANSITION(wait_for_deposit);
- break;
- case EV_TIMER:
FSM_TRANSITION(wait_for_start);
break;
default:
#endif
on_laser();
+ robot_set_est_pos_trans(ROBOT_WIDTH_M/2,
+ PLAYGROUND_HEIGHT_M - ROBOT_AXIS_TO_BACK_M,
+ DEG2RAD(-45));
/* start to do something */
+ ROBOT_LOCK(state);
+ robot.state = COMPETITION_STARTED;
+ ROBOT_UNLOCK(state);
FSM_TRANSITION(decide_where_now);
break;
+ case EV_LASER_POWER:
+ on_laser();
+ break;
case EV_DEPOSITE_BALLS:
- FSM_TRANSITION(wait_for_deposit);
+ SUBFSM_TRANSITION(deposite_balls, NULL);
+ break;
+ case EV_RETURN:
break;
default: break;
}
robot.obstacle_avoidance_enabled = false;
robot.laser_enabled = true;
+ robot.state = JUST_STARTED;
/* init ORTE domain, create publishers, subscribers, .. */
robot_init_orte();
WHITE_BALL
};
+enum robot_state {
+ JUST_STARTED = 0,
+ LASER_STARTED,
+ COMPETITION_STARTED
+};
+
/**
* FSM
*/
#define __robot_lock_bumper lock
#define __robot_lock_drives lock
#define __robot_lock_disp lock_disp
+#define __robot_lock_state lock
/* robot's main data structure */
struct robot_eb2008 {
unsigned char carousel_cnt; /* The number of balls in carousel */
unsigned char carousel_pos; /* required position of the carousel */
+ enum robot_state state;
+
/** Temporary storage for new trajectory. After the trajectory creation is
* finished, this trajectory is submitted to fsmmove. */
void *new_trajectory;
{
struct robot_cmd_type *instance = (struct robot_cmd_type *)vinstance;
static struct robot_cmd_type last_instance;
- static enum {
- JUST_STARTED,
- LASER_STARTED,
- COMPETITION_STARTED,
- } state = JUST_STARTED;
+ enum robot_state state;
switch (info->status) {
case NEW_DATA:
- if (instance->start != last_instance.start) {
- printf("state %d ", state);
- if (instance->start)
- printf("plugged in\n");
- else
- printf("plugged out\n");
-
-
- switch (state) {
- case JUST_STARTED:
- if (!instance->start) {
- FSM_SIGNAL(MAIN, EV_START, NULL);
- state = LASER_STARTED;
- }
- break;
- case LASER_STARTED:
- if (instance->start) {
- FSM_SIGNAL(MAIN, EV_START, NULL);
- state = COMPETITION_STARTED;
- }
+ if (instance->start == last_instance.start)
+ break;
+
+ ROBOT_LOCK(state);
+ state = robot.state;
+ ROBOT_UNLOCK(state);
+ printf("in state=%d \n", state);
+
+ switch (state) {
+ case JUST_STARTED:
+ if (instance->start)
break;
- case COMPETITION_STARTED:
- if (!instance->start) {
- robot_exit();
- }
+ FSM_SIGNAL(MAIN, EV_LASER_POWER, NULL);
+ state = LASER_STARTED;
+ break;
+
+ case LASER_STARTED:
+ if (!instance->start)
break;
- }
+ FSM_SIGNAL(MAIN, EV_START, NULL);
+ state = COMPETITION_STARTED;
+ break;
+
+ case COMPETITION_STARTED:
+ if (!instance->start) {
+ robot_exit();
+ }
+ break;
}
last_instance = *instance;
+ printf("out state=%d \n", state);
+ ROBOT_LOCK(state);
+ robot.state = state;
+ ROBOT_UNLOCK(state);
break;
case DEADLINE:
DBG("ORTE deadline occurred - pwr_ctrl receive\n");