ASCO Aerial Autonomy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
uav_state_machine.h
Go to the documentation of this file.
1 #pragma once
2 
14 // back-end
16 
17 // front-end
18 #include <boost/msm/front/state_machine_def.hpp>
19 
20 // functors
21 #include <boost/msm/front/functor_row.hpp>
22 
23 // Actions and guards used
25 
26 // Robot System used
28 
29 // Logging library
30 #include <glog/logging.h>
31 
32 // Store state machine states
33 #include <array>
34 
35 // Base state machine
37 
38 namespace msmf = boost::msm::front;
39 namespace be = uav_basic_events;
40 
41 // Forward Declaration
43 
49 using UAVStateMachine =
51 
56 
61  : public msmf::state_machine_def<UAVStateMachineFrontEnd>,
62  public BaseStateMachine<UAVSystem> {
63 public:
70  template <class Event, class FSM> void on_entry(Event const &, FSM &) {
71  VLOG(1) << "entering: UAV system";
72  }
79  template <class Event, class FSM> void on_exit(Event const &, FSM &) {
80  VLOG(1) << "leaving: UAV system";
81  }
82 
90  : BaseStateMachine(uav_system) {}
91 
100  : boost::mpl::vector<
101  // Start Event Next Action Guard
102  // +--------------+-------------+--------------+---------------------+---------------------------+
103  msmf::Row<usa::Landed, be::Takeoff, usa::TakingOff,
104  usa::TakeoffAction, usa::TakeoffGuard>,
105  msmf::Row<usa::Landed, ManualControlEvent, usa::ManualControlState,
106  msmf::none, msmf::none>,
107  // +--------------+-------------+--------------+---------------------+---------------------------+
108  msmf::Row<usa::TakingOff, Completed, usa::Hovering, msmf::none,
109  msmf::none>,
110  // +--------------+-------------+--------------+---------------------+---------------------------+
111  msmf::Row<usa::Hovering, PositionYaw, usa::ReachingGoal,
112  usa::ReachingGoalSet, usa::ReachingGoalGuard>,
113  msmf::Row<usa::Hovering, be::Land, usa::Landing, usa::LandingAction,
114  msmf::none>,
115  msmf::Row<usa::Hovering, ManualControlEvent,
116  usa::ManualControlState, msmf::none, msmf::none>,
117  // +--------------+-------------+--------------+---------------------+---------------------------+
118  msmf::Row<usa::ReachingGoal, be::Abort, usa::Hovering,
119  usa::UAVControllerAbort, msmf::none>,
120  msmf::Row<usa::ReachingGoal, be::Land, usa::Landing,
121  usa::ReachingGoalLand, msmf::none>,
122  // +--------------+-------------+--------------+---------------------+---------------------------+
123  msmf::Row<usa::Landing, Completed, usa::Landed, msmf::none,
124  msmf::none>,
125  msmf::Row<usa::ReachingGoal, Completed, usa::Hovering,
126  usa::UAVControllerAbort, msmf::none>,
127  // +--------------+-------------+--------------+---------------------+---------------------------+
128  msmf::Row<usa::ManualControlState, be::Takeoff, usa::Hovering,
129  usa::ManualControlSwitchAction,
130  usa::ManualControlSwitchGuard>,
131  msmf::Row<usa::ManualControlState, be::Land, usa::Landed,
132  usa::ManualControlSwitchAction,
133  usa::ManualControlSwitchGuard>
134  // +--------------+-------------+--------------+---------------------+---------------------------+
135  > {};
140 };
141 
145 static constexpr std::array<const char *, 6> state_names = {
146  "Landed", "TakingOff", "Hovering",
147  "ReachingGoal", "Landing", "ManualControlState"};
155 const char *pstate(UAVStateMachine const &p) {
156  return state_names.at(p.current_state()[0]);
157 }
ManualControlState_< LogicStateMachineT > ManualControlState
Manual control state.
Definition: uav_states_actions.h:39
Base state for all states in logic state machine.
Definition: base_state.h:24
Thread safe state machine class that extends boost::msm::back::state_machine class.
Definition: thread_safe_state_machine.h:28
Owns, initializes, and facilitates communication between different hardware/software components...
Definition: uav_system.h:21
front-end: define the FSM structure
Definition: uav_state_machine.h:60
UAVStateMachineFrontEnd(UAVSystem &uav_system)
Constructor with arguments to store robot system.
Definition: uav_state_machine.h:89
Transition table for State Machine.
Definition: uav_state_machine.h:99
void on_exit(Event const &, FSM &)
Action to take on leaving state machine.
Definition: uav_state_machine.h:79
Class to provide typedefs for all basic uav states and actions.
Definition: uav_states_actions.h:14
const char * pstate(UAVStateMachine const &p)
Get current state name.
Definition: uav_state_machine.h:155
void on_entry(Event const &, FSM &)
Action to take on entering state machine.
Definition: uav_state_machine.h:70
Base state machine.
Definition: base_state_machine.h:18