return false;
}
-/**
- * Take data from hokuyo and run shape detection on it.
- *
- * Absolute positions of all detected targets centers are stored in alobal variable (vector).
- *
- * @return True if at least one target detected, else false.
- */
-static bool detect_target()
-{
- struct hokuyo_scan_type hokuyo = robot.hokuyo;
-
- Shape_detect sd;
- std::vector<Shape_detect::Arc> arcs;
- sd.prepare(hokuyo.data);
- sd.arc_detect(arcs);
-
- // clear old targets
- detected_target.clear();
-
- if (arcs.size() > 0) {
- robot_pos_type e, target, hok;
-
- robot_get_est_pos(&e.x, &e.y, &e.phi);
-
- double sinus = sin(e.phi);
- double cosinus = cos(e.phi);
-
- // save absolute positions of all detected targets
- for (int i = 0; i < arcs.size(); i++) {
- Shape_detect::Arc *a = &arcs[i];
-
- hok.x = HOKUYO_CENTER_OFFSET_M + (double)a->center.x / 1000.0;
- hok.y = (double)a->center.y / 1000.0;
-
- /* transform target position which is relative to Hokuyo
- center to absolute position in space */
- target.x = (hok.x * cosinus) - (hok.y * sinus) + e.x;
- target.y = (hok.x * sinus) + (hok.y * cosinus) + e.y;
-
- // filter those targets not in playground range
- //if (goal_is_in_playground(target.x, target.y))
- // detected_target.push_back(target);
- }
- }
- return detected_target.size();
-}
-
/**
* Calculates point to approach the target.
*
return atan2((ytarget - ycenter), (xtarget - xcenter));
}
-
-/**
- * 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;
- double x, y, phi;
-
- switch(FSM_EVENT) {
- case EV_ENTRY:
- DBG_PRINT_EVENT("survey");
-#if 1 // 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
- FSM_TRANSITION(approach_target);
- DBG_PRINT_EVENT("Target detected!");
- } else {
- // no target detected in this heading, turn 120°
- robot_get_est_pos(&x, &y, &phi);
- robot_goto_notrans(x, y, TURN(DEG2RAD(120)+phi), &tcSlow);
- turn_cntr++;
- DBG_PRINT_EVENT("no target");
- }
- break;
- case EV_TIMER:
- if (turn_cntr > 2) {
- FSM_TRANSITION(move_around);
- } else {
- FSM_TRANSITION(survey);
- }
- break;
- case EV_MOTION_DONE:
- FSM_TIMER(1000);
- break;
- case EV_MOTION_ERROR:
- FSM_TRANSITION(move_around);
- break;
- case EV_EXIT:
- turn_cntr = 0;
- break;
- }
-}
-
/**
* FSM state for approaching all detected targets.
*
switch(FSM_EVENT) {
case EV_ENTRY:
- enable_obstacle_avoidance(false);
DBG_PRINT_EVENT("approaching target");
get_approach_point(robot.target_pos.x, robot.target_pos.y, &x_approach, &y_approach, &phi_approach);
case EV_TARGET_DETECTED:
robot_stop();
robot.target_localization_enab = false;
+ enable_obstacle_avoidance(false);
FSM_TRANSITION(approach_target);
break;
case EV_TIMER:
act_jaws(OPEN);
FSM_TIMER(1000);
break;
- case EV_TARGET_DETECTED:
- robot_stop();
- robot.target_localization_enab = false;
- FSM_TRANSITION(approach_target);
- break;
case EV_TIMER:
enable_obstacle_avoidance(true);
robot.target_localization_enab = true;
break;
}
}
-
-/*
-FSM_STATE()
-{
- switch(FSM_EVENT) {
- case EV_ENTRY:
- break;
- case EV_START:
- case EV_TIMER:
- case EV_RETURN:
- case EV_CRANE_DONE:
- case EV_MOTION_DONE:
- case EV_MOTION_ERROR:
- case EV_SWITCH_STRATEGY:
- DBG_PRINT_EVENT("unhandled event");
- case EV_EXIT:
- break;
- }
-}
-*/