ASCO Aerial Autonomy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
uav_arm_system_handler.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <ros/ros.h>
4 
5 #include <parsernode/parser.h>
6 #include <pluginlib/class_loader.h>
7 
8 #include <arm_parsers/arm_simulator.h>
9 #include <arm_parsers/generic_arm.h>
10 #include <arm_parsers/simple_arm.h>
11 
17 
18 #include "uav_system_handler_config.pb.h"
19 
28 template <class LogicStateMachineT, class EventManagerT>
30 public:
36  UAVArmSystemHandler(UAVSystemHandlerConfig &config)
37  : nh_uav_("~uav"), nh_arm_("~arm"), nh_tracker_("~tracker"),
38  parser_loader_("parsernode", "parsernode::Parser"),
39  uav_hardware_(
40  parser_loader_.createUnmanagedInstance(config.uav_parser_type())),
41  // \todo Make arm hardware a plugin
42  arm_hardware_(
43  config.uav_arm_system_handler_config().arm_parser_type() ==
44  "GenericArm"
45  ? dynamic_cast<ArmParser *>(new GenericArm(nh_arm_))
46  : (config.uav_arm_system_handler_config().arm_parser_type() ==
47  "SimpleArm"
48  ? dynamic_cast<ArmParser *>(new SimpleArm(nh_arm_))
49  : dynamic_cast<ArmParser *>(new ArmSimulator()))),
50  tracker_(
51  config.uav_system_config()
52  .uav_vision_system_config()
53  .tracker_type() == "ROI"
54  ? dynamic_cast<BaseTracker *>(
55  new RoiToPositionConverter(nh_tracker_))
56  : dynamic_cast<BaseTracker *>(new AlvarTracker(nh_tracker_))),
57  uav_system_(*tracker_, *uav_hardware_, *arm_hardware_,
58  config.uav_system_config()),
59  common_handler_(config.base_config(), uav_system_),
60  uav_controller_timer_(
61  std::bind(&UAVArmSystem::runActiveController, std::ref(uav_system_),
62  HardwareType::UAV),
63  std::chrono::milliseconds(config.uav_controller_timer_duration())),
64  arm_controller_timer_(
65  std::bind(&UAVArmSystem::runActiveController, std::ref(uav_system_),
66  HardwareType::Arm),
67  std::chrono::milliseconds(config.uav_arm_system_handler_config()
68  .arm_controller_timer_duration())) {
69  // Initialize UAV plugin
70  uav_hardware_->initialize(nh_uav_);
71 
72  // Get the party started
73  common_handler_.startTimers();
74  uav_controller_timer_.start();
75  arm_controller_timer_.start();
76  }
77 
81  UAVArmSystemHandler(const UAVArmSystemHandler &) = delete;
82 
87  parsernode::common::quaddata getUAVData() {
88  parsernode::common::quaddata quad_data;
89  uav_hardware_->getquaddata(quad_data);
90  return quad_data;
91  }
92 
99  bool isConnected() { return common_handler_.isConnected(); }
100 
101 private:
102  ros::NodeHandle nh_uav_;
103  ros::NodeHandle nh_arm_;
104  ros::NodeHandle nh_tracker_;
105  pluginlib::ClassLoader<parsernode::Parser>
106  parser_loader_;
107  std::unique_ptr<parsernode::Parser> uav_hardware_;
108  std::unique_ptr<ArmParser> arm_hardware_;
109  std::unique_ptr<BaseTracker> tracker_;
110  UAVArmSystem uav_system_;
112  common_handler_;
113  AsyncTimer uav_controller_timer_;
115  AsyncTimer arm_controller_timer_;
116 };
bool isConnected()
Forward common handler connected function for testing is GUI is connected to this node or not...
Definition: uav_arm_system_handler.h:99
UAV vision system with an arm.
Definition: uav_arm_system.h:12
UAVArmSystemHandler(UAVSystemHandlerConfig &config)
Constructor.
Definition: uav_arm_system_handler.h:36
Only aerial vehicle.
Converts a ROI in image to vector in camera frame.
Definition: roi_to_position_converter.h:25
Interface for classes that provide a vector to a tracked target.
Definition: base_tracker.h:13
Owns all of the autonomous system components and is responsible for thread management. Also owns a common system handler object to handle creation of state machine and connecting it to GUI.
Definition: uav_arm_system_handler.h:29
void start()
Starts running the timer thread.
Definition: async_timer.cpp:16
void startTimers()
Start state machine internal event processing and status timer.
Definition: common_system_handler.h:70
Calls given function on a timer in its own thread.
Definition: async_timer.h:11
bool isConnected()
Checks if internal ROS topics are connected.
Definition: common_system_handler.h:62
parsernode::common::quaddata getUAVData()
Get UAV state.
Definition: uav_arm_system_handler.h:87
Provides vector to a tracked object based on output from alvar.
Definition: alvar_tracker.h:13
HardwareType
Type of hardware used by ControllerHardwareConnector. Enum ID must be contiguous. ...
Definition: base_controller_hardware_connector.h:11