ASCO Aerial Autonomy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
manual_control_functors.h
Go to the documentation of this file.
1 #pragma once
2 
4 
6 #include <aerial_autonomy/uav_basic_events.h>
7 
8 // Boost Includes
9 #include <boost/msm/front/functor_row.hpp>
10 #include <boost/msm/front/state_machine_def.hpp>
11 
12 #include <parsernode/common.h>
13 
17 namespace be = uav_basic_events;
18 
24 template <class LogicStateMachineT>
26  : EventAgnosticActionFunctor<UAVSystem, LogicStateMachineT> {
27  void run(UAVSystem &robot_system) {
28  VLOG(1) << "Enabling SDK";
29  robot_system.enableAutonomousMode();
30  }
31 };
32 
39 template <class LogicStateMachineT>
41  : EventAgnosticGuardFunctor<UAVSystem, LogicStateMachineT> {
42  bool guard(UAVSystem &robot_system) {
43  parsernode::common::quaddata data = robot_system.getUAVData();
44  if (data.batterypercent <
45  robot_system.getConfiguration().minimum_battery_percent()) {
46  LOG(WARNING) << "Battery too low! " << data.batterypercent;
47  return false;
48  }
49  return data.rc_sdk_control_switch;
50  }
51 };
52 
58 template <class LogicStateMachineT>
60  : InternalActionFunctor<UAVSystem, LogicStateMachineT> {
68  bool run(UAVSystem &robot_system, LogicStateMachineT &logic_state_machine) {
69  parsernode::common::quaddata data = robot_system.getUAVData();
70  // If sdk mode is allowed
71  if (data.rc_sdk_control_switch) {
72  if (data.localpos.z < robot_system.getConfiguration().landing_height()) {
73  VLOG(1) << "Switching to Landed mode";
74  logic_state_machine.process_event(be::Land());
75  } else {
76  VLOG(1) << "Switching to Hovering mode";
77  logic_state_machine.process_event(be::Takeoff());
78  }
79  return false;
80  }
81  return true;
82  }
83 };
84 
90 template <class LogicStateMachineT>
91 using ManualControlState_ =
92  BaseState<UAVSystem, LogicStateMachineT,
Guard to avoid switching to SDK mode unless hardware allows it.
Definition: manual_control_functors.h:40
Base state for all states in logic state machine.
Definition: base_state.h:24
void run(UAVSystem &robot_system)
Override this run function for different sub classes. This function performs the logic checking for e...
Definition: manual_control_functors.h:27
Internal action that returns whether it processed an event.
Definition: base_functors.h:208
Action functor that does not require the event triggering it.
Definition: base_functors.h:113
Owns, initializes, and facilitates communication between different hardware/software components...
Definition: uav_system.h:21
bool run(UAVSystem &robot_system, LogicStateMachineT &logic_state_machine)
Check if hardware is allowing to switch to sdk mode and trigger appropriate events.
Definition: manual_control_functors.h:68
void enableAutonomousMode()
Public API call to enable Quadcopter SDK. This call is only necessary if Quad goes into manual mode d...
Definition: uav_system.h:125
parsernode::common::quaddata getUAVData() const
Get sensor data from UAV.
Definition: uav_system.h:109
bool guard(UAVSystem &robot_system)
Override this run function for different sub classes. This function performs the logic checking for e...
Definition: manual_control_functors.h:42
Check if hardware is allowing to switch sdk mode.
Definition: manual_control_functors.h:59
Guard functor that does not require the event triggering it.
Definition: base_functors.h:157
UAVSystemConfig getConfiguration()
Get system configuration.
Definition: uav_system.h:192
Basic events such as takeoff land etc.
Definition: manual_control_functors.h:25