ASCO Aerial Autonomy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
visual_servoing_functors.h
Go to the documentation of this file.
1 #pragma once
9 #include <glog/logging.h>
10 #include <parsernode/common.h>
11 
17 template <class LogicStateMachineT>
19  : EventAgnosticActionFunctor<UAVVisionSystem, LogicStateMachineT> {
20  void run(UAVVisionSystem &robot_system) {}
21 };
22 
28 template <class LogicStateMachineT>
30  : EventAgnosticActionFunctor<UAVVisionSystem, LogicStateMachineT> {
31  void run(UAVVisionSystem &robot_system) {
32  LOG(WARNING) << "Aborting visual servoing controller";
33  robot_system.abortController(HardwareType::UAV);
34  }
35 };
36 
42 template <class LogicStateMachineT>
44  : EventAgnosticActionFunctor<UAVVisionSystem, LogicStateMachineT> {
45  void run(UAVVisionSystem &robot_system) {
46  PositionYaw home_location = robot_system.getHomeLocation();
47  VLOG(1) << "Going home";
49  home_location);
50  }
51 };
52 
58 template <class LogicStateMachineT>
60  : EventAgnosticGuardFunctor<UAVVisionSystem, LogicStateMachineT> {
61  bool guard(UAVVisionSystem &robot_system) {
62  return robot_system.isHomeLocationSpecified();
63  }
64 };
65 
71 template <class LogicStateMachineT>
77 
82 template <class LogicStateMachineT>
84  : EventAgnosticGuardFunctor<UAVVisionSystem, LogicStateMachineT> {
85  bool guard(UAVVisionSystem &robot_system) {
86  if (!robot_system.initializeTracker()) {
87  LOG(WARNING) << "Could not initialize tracking.";
88  return false;
89  }
90  Position tracking_vector;
91  if (!robot_system.getTrackingVector(tracking_vector)) {
92  LOG(WARNING) << "Lost tracking while servoing.";
93  return false;
94  }
95  VLOG(1) << "Setting tracking vector";
96  double desired_distance = robot_system.getConfiguration()
97  .uav_vision_system_config()
98  .desired_visual_servoing_distance();
99  double tracking_vector_norm = tracking_vector.norm();
100  if (tracking_vector_norm < 1e-6) {
101  LOG(WARNING) << "Tracking vector too small cannot initialize direction";
102  return false;
103  } else {
104  // \todo Matt: could possibly move this block to the action functor
105  VLOG(1) << "Selecting home location";
106  robot_system.setHomeLocation();
108  tracking_vector * desired_distance / tracking_vector_norm);
109  }
110  return true;
111  }
112 };
113 
119 template <class LogicStateMachineT>
120 using VisualServoing_ =
121  BaseState<UAVVisionSystem, LogicStateMachineT,
Logic to abort if controller status is critical.
Definition: hovering_functors.h:57
Guard for home transition.
Definition: visual_servoing_functors.h:59
void setHomeLocation()
save current location as home location
Definition: uav_system.h:197
Action to reach a pre designated point.
Definition: visual_servoing_functors.h:43
Base state for all states in logic state machine.
Definition: base_state.h:24
Empty for now.
Definition: visual_servoing_functors.h:18
void abortController(HardwareType hardware_type)
Remove active controller for given hardware type.
Definition: base_robot_system.h:126
bool isHomeLocationSpecified()
Check if home location is specified.
Definition: uav_system.h:211
Only aerial vehicle.
void run(UAVVisionSystem &robot_system)
Override this run function for different sub classes. This function performs the logic checking for e...
Definition: visual_servoing_functors.h:20
Stores Position, yaw. PositionYaw is used as the goal for UAV systems.
Definition: position_yaw.h:10
Action functor that does not require the event triggering it.
Definition: base_functors.h:113
void setGoal(GoalT goal)
sets goal to the connector and swaps the active connector with the specified connector type...
Definition: base_robot_system.h:59
void run(UAVVisionSystem &robot_system)
Override this run function for different sub classes. This function performs the logic checking for e...
Definition: visual_servoing_functors.h:45
bool getTrackingVector(Position &pos)
Get the direction vector of the tracking target in the global frame.
Definition: uav_vision_system.h:44
void run(UAVVisionSystem &robot_system)
Override this run function for different sub classes. This function performs the logic checking for e...
Definition: visual_servoing_functors.h:31
A visual servoing controller that uses a tracker output as feedback.
Definition: visual_servoing_controller_drone_connector.h:16
bool initializeTracker()
Definition: uav_vision_system.h:48
Manages communication between a drone plugin and a position controller that outputs position commands...
Definition: position_controller_drone_connector.h:14
bool guard(UAVVisionSystem &robot_system)
Override this run function for different sub classes. This function performs the logic checking for e...
Definition: visual_servoing_functors.h:61
PositionYaw getHomeLocation()
Stored home location.
Definition: uav_system.h:218
Check tracking is valid before starting visual servoing.
Definition: visual_servoing_functors.h:83
bool guard(UAVVisionSystem &robot_system)
Override this run function for different sub classes. This function performs the logic checking for e...
Definition: visual_servoing_functors.h:85
Internal action when hovering.
Definition: hovering_functors.h:21
Definition: visual_servoing_functors.h:29
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
Action sequence that runs until one of the actions returns false.
Definition: shorting_action_sequence.h:46
UAV system with a camera and visual sevoing capabilities.
Definition: uav_vision_system.h:14
Store 3D position.
Definition: position.h:8
double norm() const
Returns the norm of the vector.
Definition: position.h:30