return atan2((ytarget - yrobot), (xtarget - xrobot));
}
-/* automaton to survey neighborhood in two stages */
+
+
+/**
+ * FSM state for neighborhood observation.
+ *
+ * Detect targets using shape_detect.
+ * If no target detected, turn 120deg and try again.
+ * Scan all 360deg and then go back to move_around state.
+ *
+ * If target detected, go to approach_target state.
+ */
FSM_STATE(survey)
{
static char turn_cntr = 0;
switch(FSM_EVENT) {
case EV_ENTRY:
- /* run shape detection
- - if detection is positive go to the target
- - if no target detected turn 120° to the left */
- if (detect_target() & 0) {
+#if 0 // FIXME just for test
+ if (detect_target()) {
+#else
+ if (turn_cntr > 1) {
+ robot_pos_type target;
+ detected_target.clear();
+ for (double i = 1; i < 5; i++) {
+ target.x = i;
+ target.y = i/2.0;
+ detected_target.push_back(target);
+ }
+#endif
// target detected, go to the target
- robot.target_detected = true;
FSM_TRANSITION(approach_target);
DBG_PRINT_EVENT("Target detected!");
} else {
// no target detected in this heading, turn 120°
- robot.target_detected = false;
robot_get_est_pos(&x, &y, &phi);
robot_goto_notrans(x, y, TURN(DEG2RAD(120)+phi), &tcSlow);
turn_cntr++;
}
break;
- case EV_CRANE_DONE:
- //FSM_TIMER(1000);
- break;
case EV_TIMER:
if (turn_cntr > 2) {
- turn_cntr = 0;
FSM_TRANSITION(move_around);
} else {
FSM_TRANSITION(survey);
break;
case EV_START:
case EV_RETURN:
+ case EV_CRANE_DONE:
+ case EV_SWITCH_STRATEGY:
+ DBG_PRINT_EVENT("unhandled event!");
break;
case EV_MOTION_ERROR:
- case EV_SWITCH_STRATEGY:
- DBG_PRINT_EVENT("unhandled event");
FSM_TRANSITION(move_around);
break;
case EV_EXIT:
+ turn_cntr = 0;
break;
}
}