#define COMMON_STATES_H
-#include "roboevent.h"
#include "fsm_top.h"
#include <robot.h>
#include <unistd.h>
Timer t;
survey() {
turn_cntr = 0;
-// DBG_PRINT_EVENT("survey");
+ do_work();
+ }
+ ~survey() {
+ turn_cntr = 0;
+ }
+ sc::result react(const evTimer& ) {
+ if (turn_cntr > 2) {
+ return transit<move_around>();
+ } else {
+ do_work();
+ return discard_event();
+ }
+ }
+ sc::result react(const evMotionDone&) {
+ runTimer(t,1000, new evTimer());
+ return discard_event();
+ }
+
+ typedef mpl::list<
+ sc::custom_reaction<evTimer>,
+ sc::custom_reaction<evMotionDone>,
+ sc::transition<evMotionError, move_around>,
+ sc::transition<evEntry, approach_target> > reactions;
+ void do_work() {
+ // DBG_PRINT_EVENT("survey");
#if 1 // FIXME just for test
if (detect_target()) {
#else
turn_cntr++;
// DBG_PRINT_EVENT("no target");
}
-
- }
- ~survey() {
- turn_cntr = 0;
- }
- sc::result react(const evTimer& ) {
- if (turn_cntr > 2) {
- return transit<move_around>();
- } else {
- return transit<survey>();
- }
- }
- sc::result react(const evMotionDone&) {
- runTimer(t,1000, new evTimer());
- return discard_event();
- }
-
- typedef mpl::list<
- sc::custom_reaction<evTimer>,
- sc::custom_reaction<evMotionDone>,
- sc::transition<evMotionError, move_around>,
- sc::transition<evEntry, approach_target> > reactions;
+ }
};
/**
return transit<move_around>();
}
}
+ typedef mpl::list<
+ sc::custom_reaction<evMotionDone>,
+ sc::custom_reaction<evReturn>,
+ sc::custom_reaction<evMotionError> > reactions;
+
};
struct move_around : TimedSimpleState<move_around, competing> {
struct wait_and_try_again : TimedState< wait_and_try_again, MotionBase > {
Timer wait_tout;
+ int target_inacc_cnt;
wait_and_try_again(my_context ctx) : base_state(ctx) {
stop();
runTimer(wait_tout, 1000, new evTimer());
+ target_inacc_cnt = 0;
}
sc::result react(const evTimer &) {
switch (recalculate_trajectory()) {
case TARGET_OK: return transit<movement>();
// Target inaccessible because of an obstacle
case TARGET_INACC:
- ul_logerr("Inaccessible\n");
- return transit<wait_and_try_again>();
- /* FIXME (Filip): this could happen forever */
+ if (++target_inacc_cnt < 3) {
+ ul_logerr("Inaccessible\n");
+ runTimer(wait_tout, 1000, new evTimer());
+ /* FIXME (Filip): this could happen forever */
+ } else { /* go away if the point is not accessible, try max. 3x */
+ robot.sched.queue_event(robot.MAIN, new evMotionError());
+ //DBG_PRINT_EVENT("Target inaccessible, go to new target.");
+ return transit<wait_for_command>();
+ }
// Fatal error during planning
case TARGET_ERROR:
robot.sched.queue_event(robot.MAIN, new evMotionDone());
//ShmapSetRectangleFlag(2.74, 0.0, 3.0, 2.1, MAP_FLAG_WALL, 0); /* right */
}
-static void trans_callback(struct robo_fsm *fsm)
+void trans_callback()
{
-/* if (fsm == &robot.fsm.main) {
- strncpy(robot.orte.fsm_main.state_name, fsm->state_name, sizeof(robot.orte.fsm_main.state_name));
+ if (robot.MAIN == robot.sched.getActualHandle()) {
+ strncpy(robot.orte.fsm_main.state_name, robot.MAIN->state_name, sizeof(robot.orte.fsm_main.state_name));
ORTEPublicationSend(robot.orte.publication_fsm_main);
- } else if (fsm == &robot.fsm.motion) {
- strncpy(robot.orte.fsm_motion.state_name, fsm->state_name, sizeof(robot.orte.fsm_motion.state_name));
+ } else if (robot.MOTION == robot.sched.getActualHandle()) {
+ strncpy(robot.orte.fsm_motion.state_name, robot.MOTION->state_name, sizeof(robot.orte.fsm_motion.state_name));
ORTEPublicationSend(robot.orte.publication_fsm_motion);
- } else if (fsm == &robot.fsm.act) {
- strncpy(robot.orte.fsm_act.state_name, fsm->state_name, sizeof(robot.orte.fsm_act.state_name));
- ORTEPublicationSend(robot.orte.publication_fsm_act);
}
-*/
}
/**
ref_pos.y = y;
ref_pos.phi = phi;
}
+}
+
+void Robot::set_state_name(const char* name)
+{
+ sched.getActualHandle()->state_name = name;
+ trans_callback();
}
\ No newline at end of file
void set_est_pos(double x, double y, double phi);
void get_est_pos_trans(double &x, double &y, double &phi);
void get_est_pos(double &x, double &y, double &phi);
+ void set_state_name(const char* name);
}; /* robot */
extern Robot robot;
#include "robodata.h"
#include "actuators.h"
#include "guard.hpp"
-#include "roboevent.h"
#include <timedFSM.h>
#include <boost/mpl/list.hpp>
#include <boost/statechart/transition.hpp>