ASCO Aerial Autonomy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
visual_servoing_state_machine.h
Go to the documentation of this file.
1 #pragma once
2 
16 // back-end
18 
19 // front-end
20 #include <boost/msm/front/state_machine_def.hpp>
21 
22 // functors
23 #include <boost/msm/front/functor_row.hpp>
24 
25 // Actions and guards used
27 
28 // Robot System used
30 
31 // Logging library
32 #include <glog/logging.h>
33 
34 // Store state machine states
35 #include <array>
36 
37 // Base state machine
39 
40 // Events
41 #include <aerial_autonomy/visual_servoing_events.h>
42 
44 
45 namespace msmf = boost::msm::front;
46 namespace vse = visual_servoing_events;
47 namespace be = uav_basic_events;
48 
49 // Forward Declaration
51 
59 
64 
69  : public msmf::state_machine_def<VisualServoingStateMachineFrontEnd>,
70  public BaseStateMachine<UAVVisionSystem> {
71 public:
78  template <class Event, class FSM> void on_entry(Event const &, FSM &) {
79  VLOG(1) << "entering: VisualServoing system";
80  }
87  template <class Event, class FSM> void on_exit(Event const &, FSM &) {
88  VLOG(1) << "leaving: VisualServoing system";
89  }
90 
98  : BaseStateMachine(uav_system) {}
99 
108  : boost::mpl::vector<
109  // Start Event Next Action Guard
110  // +--------------+-------------+--------------+---------------------+---------------------------+
111  msmf::Row<vsa::Landed, be::Takeoff, vsa::TakingOff,
112  vsa::TakeoffAction, vsa::TakeoffGuard>,
113  // +--------------+-------------+--------------+---------------------+---------------------------+
114  msmf::Row<vsa::Landed, ManualControlEvent, vsa::ManualControlState,
115  msmf::none, msmf::none>,
116  // +--------------+-------------+--------------+---------------------+---------------------------+
117  msmf::Row<vsa::TakingOff, Completed, vsa::Hovering, msmf::none,
118  msmf::none>,
119  // +--------------+-------------+--------------+---------------------+---------------------------+
120  msmf::Row<vsa::Hovering, PositionYaw, vsa::ReachingGoal,
121  vsa::ReachingGoalSet, vsa::ReachingGoalGuard>,
122  // +--------------+-------------+--------------+---------------------+---------------------------+
123  msmf::Row<vsa::Hovering, vse::TrackROI, vsa::VisualServoing,
124  vsa::VisualServoingTransitionAction,
125  vsa::VisualServoingTransitionGuard>,
126  // +--------------+-------------+--------------+---------------------+---------------------------+
127  msmf::Row<vsa::Hovering, vse::GoHome, vsa::ReachingGoal,
128  vsa::GoHomeTransitionAction, vsa::GoHomeTransitionGuard>,
129  // +--------------+-------------+--------------+---------------------+---------------------------+
130  msmf::Row<vsa::Hovering, be::Land, vsa::Landing, vsa::LandingAction,
131  msmf::none>,
132  // +--------------+-------------+--------------+---------------------+---------------------------+
133  msmf::Row<vsa::Hovering, ManualControlEvent,
134  vsa::ManualControlState, msmf::none, msmf::none>,
135  // +--------------+-------------+--------------+---------------------+---------------------------+
136  msmf::Row<vsa::ReachingGoal, be::Abort, vsa::Hovering,
137  vsa::UAVControllerAbort, msmf::none>,
138  // +--------------+-------------+--------------+---------------------+---------------------------+
139  msmf::Row<vsa::ReachingGoal, be::Land, vsa::Landing,
140  vsa::ReachingGoalLand, msmf::none>,
141  // +--------------+-------------+--------------+---------------------+---------------------------+
142  msmf::Row<vsa::VisualServoing, be::Abort, vsa::Hovering,
143  vsa::UAVControllerAbort, msmf::none>,
144  // +--------------+-------------+--------------+---------------------+---------------------------+
145  msmf::Row<vsa::VisualServoing, be::Land, vsa::Landing,
146  vsa::ReachingGoalLand, msmf::none>,
147  // +--------------+-------------+--------------+---------------------+---------------------------+
148  msmf::Row<vsa::Landing, Completed, vsa::Landed, msmf::none,
149  msmf::none>,
150  // +--------------+-------------+--------------+---------------------+---------------------------+
151  msmf::Row<vsa::ReachingGoal, Completed, vsa::Hovering,
152  vsa::UAVControllerAbort, msmf::none>,
153  // +--------------+-------------+--------------+---------------------+---------------------------+
154  msmf::Row<vsa::VisualServoing, Completed, vsa::Hovering,
155  vsa::UAVControllerAbort, msmf::none>,
156  // +--------------+-------------+--------------+---------------------+---------------------------+
157  msmf::Row<vsa::ManualControlState, be::Takeoff, vsa::Hovering,
158  vsa::ManualControlSwitchAction,
159  vsa::ManualControlSwitchGuard>,
160  // +--------------+-------------+--------------+---------------------+---------------------------+
161  msmf::Row<vsa::ManualControlState, be::Land, vsa::Landed,
162  vsa::ManualControlSwitchAction,
163  vsa::ManualControlSwitchGuard>> {};
168 };
169 
173 static constexpr std::array<const char *, 7> state_names = {
174  "Landed", "TakingOff", "Hovering", "ReachingGoal",
175  "VisualServoing", "Landing", "ManualControlState"};
183 const char *pstate(VisualServoingStateMachine const &p) {
184  return state_names.at(p.current_state()[0]);
185 }
ManualControlState_< LogicStateMachineT > ManualControlState
Manual control state.
Definition: uav_states_actions.h:39
front-end: define the FSM structure
Definition: visual_servoing_state_machine.h:68
Base state for all states in logic state machine.
Definition: base_state.h:24
const char * pstate(VisualServoingStateMachine const &p)
Get current state name.
Definition: visual_servoing_state_machine.h:183
Thread safe state machine class that extends boost::msm::back::state_machine class.
Definition: thread_safe_state_machine.h:28
void on_exit(Event const &, FSM &)
Action to take on leaving state machine.
Definition: visual_servoing_state_machine.h:87
Transition table for State Machine.
Definition: visual_servoing_state_machine.h:107
void on_entry(Event const &, FSM &)
Action to take on entering state machine.
Definition: visual_servoing_state_machine.h:78
Class to provide typedefs for all basic uav states and actions.
Definition: visual_servoing_states_actions.h:12
UAV system with a camera and visual sevoing capabilities.
Definition: uav_vision_system.h:14
Base state machine.
Definition: base_state_machine.h:18
VisualServoingStateMachineFrontEnd(UAVVisionSystem &uav_system)
Constructor with arguments to store robot system.
Definition: visual_servoing_state_machine.h:97