18 #ifndef PRBT_HARDWARE_SUPPORT_RUN_PERMITTED_STATE_MACHINE_H 19 #define PRBT_HARDWARE_SUPPORT_RUN_PERMITTED_STATE_MACHINE_H 26 #include <boost/msm/back/state_machine.hpp> 27 #include <boost/msm/front/functor_row.hpp> 28 #include <boost/msm/front/state_machine_def.hpp> 29 #include <boost/core/demangle.hpp> 38 #define COLOR_GREEN "\033[32m" 39 #define COLOR_GREEN_BOLD "\033[1;32m" 41 #define STATE_ENTER_OUTPUT ROS_DEBUG_STREAM_NAMED("RunPermittedStateMachine", "Event: " << className(boost::core::demangle(typeid(ev).name())) \ 42 << " - Entering: " << COLOR_GREEN_BOLD << className(boost::core::demangle(typeid(*this).name())) << COLOR_GREEN); 43 #define STATE_EXIT_OUTPUT ROS_DEBUG_STREAM_NAMED("RunPermittedStateMachine", "Event: " << className(boost::core::demangle(typeid(ev).name())) \ 44 << " - Leaving: " << className(boost::core::demangle(typeid(*this).name()))); 45 #define ACTION_OUTPUT ROS_DEBUG_STREAM_NAMED("RunPermittedStateMachine", "Event: " << className(boost::core::demangle(typeid(ev).name())) \ 46 << " - Action: " << className(boost::core::demangle(typeid(*this).name()))); 89 namespace msm = boost::msm;
90 namespace mpl = boost::mpl;
116 : recover_op_(recover_operation),
117 halt_op_(halt_operation),
118 hold_op_(hold_operation),
119 unhold_op_(unhold_operation)
128 template <
class Event,
class FSM>
133 template <
class Event,
class FSM>
141 template <
class Event,
class FSM>
146 template <
class Event,
class FSM>
155 template <
class Event,
class FSM>
160 template <
class Event,
class FSM>
169 template <
class Event,
class FSM>
174 template <
class Event,
class FSM>
183 template <
class Event,
class FSM>
188 template <
class Event,
class FSM>
197 template <
class Event,
class FSM>
202 template <
class Event,
class FSM>
223 : run_permitted_(run_permitted){}
246 template <
class EVT,
class FSM,
class SourceState,
class TargetState>
247 bool operator()(EVT
const &evt, FSM &, SourceState &, TargetState &)
249 return evt.run_permitted_;
255 template <
class EVT,
class FSM,
class SourceState,
class TargetState>
256 bool operator()(EVT
const &evt, FSM &, SourceState &, TargetState &)
258 return !evt.run_permitted_;
273 template <
class EVT,
class FSM,
class SourceState,
class TargetState>
274 void operator()(EVT
const &ev, FSM &fsm, SourceState &, TargetState &)
278 fsm.task_queue_.push(
AsyncRunPermittedTask(fsm.recover_op_, [&fsm]() { fsm.process_event(recover_done()); }));
289 template <
class EVT,
class FSM,
class SourceState,
class TargetState>
290 void operator()(EVT
const &ev, FSM &fsm, SourceState &, TargetState &)
294 fsm.task_queue_.push(
AsyncRunPermittedTask(fsm.halt_op_, [&fsm]() { fsm.process_event(halt_done()); }));
305 template <
class EVT,
class FSM,
class SourceState,
class TargetState>
306 void operator()(EVT
const &ev, FSM &fsm, SourceState &, TargetState &)
310 fsm.task_queue_.push(
AsyncRunPermittedTask(fsm.hold_op_, [&fsm]() { fsm.process_event(hold_done()); }));
321 template <
class EVT,
class FSM,
class SourceState,
class TargetState>
322 void operator()(EVT
const &ev, FSM &fsm, SourceState &, TargetState &)
326 fsm.task_queue_.push(
AsyncRunPermittedTask(fsm.unhold_op_, [&fsm]() { fsm.process_event(unhold_done()); }));
337 Row< RobotInactive , run_permitted_updated , Enabling , recover_start, run_permitted_true >,
338 Row< RobotInactive , run_permitted_updated , none , none , run_permitted_false>,
339 Row< Enabling , run_permitted_updated , none , none , run_permitted_true >,
340 Row< Enabling , run_permitted_updated , StopRequestedDuringEnable , none , run_permitted_false>,
341 Row< Enabling , recover_done , none , unhold_start , none >,
342 Row< Enabling , unhold_done , RobotActive , none , none >,
343 Row< StopRequestedDuringEnable , run_permitted_updated , none , none , none >,
344 Row< StopRequestedDuringEnable , recover_done , Stopping , halt_start , none >,
345 Row< StopRequestedDuringEnable , unhold_done , Stopping , hold_start , none >,
346 Row< RobotActive , run_permitted_updated , none , none , run_permitted_true >,
347 Row< RobotActive , run_permitted_updated , Stopping , hold_start , run_permitted_false>,
348 Row< Stopping , run_permitted_updated , EnableRequestedDuringStop , none , run_permitted_true >,
349 Row< Stopping , hold_done , none , halt_start , none >,
350 Row< Stopping , halt_done , RobotInactive , none , none >,
351 Row< EnableRequestedDuringStop , hold_done , none , halt_start , none >,
352 Row< EnableRequestedDuringStop , halt_done , Enabling , recover_start, none >,
353 Row< EnableRequestedDuringStop , run_permitted_updated , Stopping , none , run_permitted_false>,
354 Row< EnableRequestedDuringStop , run_permitted_updated , none , none , run_permitted_true >
379 #endif // PRBT_HARDWARE_SUPPORT_RUN_PERMITTED_STATE_MACHINE_H void on_exit(Event const &ev, FSM &)
RobotInactive initial_state
Initial state.
void on_entry(Event const &ev, FSM &)
void on_exit(Event const &ev, FSM &)
void operator()(EVT const &ev, FSM &fsm, SourceState &, TargetState &)
RunPermittedTaskQueue task_queue_
The task queue.
RunPermittedStateMachine_(const TServiceCallFunc &recover_operation, const TServiceCallFunc &halt_operation, const TServiceCallFunc &hold_operation, const TServiceCallFunc &unhold_operation)
Construct the front-end state machine. Store the required task execution functions.
TServiceCallFunc halt_op_
The halt operation.
run_permitted_updated(const bool run_permitted)
void on_exit(Event const &ev, FSM &)
Pushes the unhold-task on the task queue.
bool operator()(EVT const &evt, FSM &, SourceState &, TargetState &)
void on_entry(Event const &ev, FSM &)
TServiceCallFunc operation_
Pushes the recover-task on the task queue.
TServiceCallFunc recover_op_
The recover operation.
std::function< void()> finished_handler_
bool operator()(EVT const &evt, FSM &, SourceState &, TargetState &)
TServiceCallFunc unhold_op_
The unhold operation.
Pushes the hold-task on the task queue.
void on_exit(Event const &ev, FSM &)
TServiceCallFunc hold_op_
The hold operation.
void on_entry(Event const &ev, FSM &)
void operator()(EVT const &ev, FSM &fsm, SourceState &, TargetState &)
void on_entry(Event const &ev, FSM &)
std::queue< AsyncRunPermittedTask > RunPermittedTaskQueue
Define the task queue type.
AsyncRunPermittedTask(const TServiceCallFunc &operation, const std::function< void()> &finished_handler)
void operator()(EVT const &ev, FSM &fsm, SourceState &, TargetState &)
void on_entry(Event const &ev, FSM &)
void on_exit(Event const &ev, FSM &)
void execute()
Execute the task.
#define STATE_EXIT_OUTPUT
#define STATE_ENTER_OUTPUT
void operator()(EVT const &ev, FSM &fsm, SourceState &, TargetState &)
std::function< bool()> TServiceCallFunc
msm::back::state_machine< RunPermittedStateMachine_ > RunPermittedStateMachine
The top-level (back-end) state machine.
An AsyncRunPermittedTask is represented by a task execution and a completion signalling.
void on_entry(Event const &ev, FSM &)
Pushes the halt-task on the task queue.
void on_exit(Event const &ev, FSM &)
void signalCompletion()
Signal completion of the task execution.
Holds the updated run_permitted value.