ASCO Aerial Autonomy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
uav_system.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "uav_system_config.pb.h"
4 // Html Utilities
6 // Base robot system
8 // Controllers
10 // Specific ControllerConnectors
12 
13 #include <iomanip>
14 #include <sstream>
15 
21 class UAVSystem : public virtual BaseRobotSystem {
22 protected:
26  parsernode::Parser &drone_hardware_;
30  UAVSystemConfig config_;
31 
32 private:
33  // Controllers
37  BuiltInPositionController builtin_position_controller_;
41  BuiltInVelocityController builtin_velocity_controller_;
45  ManualRPYTController manual_rpyt_controller_;
49  PositionControllerDroneConnector position_controller_drone_connector_;
53  BuiltInVelocityControllerDroneConnector velocity_controller_drone_connector_;
57  ManualRPYTControllerDroneConnector rpyt_controller_drone_connector_;
58 
62  PositionYaw home_location_;
63 
67  bool home_location_specified_;
68 
69 public:
73  UAVSystem(parsernode::Parser &drone_hardware)
74  : UAVSystem(drone_hardware, UAVSystemConfig()) {}
85  UAVSystem(parsernode::Parser &drone_hardware, UAVSystemConfig config)
86  : BaseRobotSystem(), drone_hardware_(drone_hardware), config_(config),
87  builtin_position_controller_(config.position_controller_config()),
88  builtin_velocity_controller_(config.velocity_controller_config()),
89  position_controller_drone_connector_(drone_hardware,
90  builtin_position_controller_),
91  velocity_controller_drone_connector_(drone_hardware,
92  builtin_velocity_controller_),
93  rpyt_controller_drone_connector_(drone_hardware,
94  manual_rpyt_controller_),
95  home_location_specified_(false) {
96  // Add control hardware connector containers
98  position_controller_drone_connector_);
100  velocity_controller_drone_connector_);
102  rpyt_controller_drone_connector_);
103  }
109  parsernode::common::quaddata getUAVData() const {
110  parsernode::common::quaddata data;
111  drone_hardware_.getquaddata(data);
112  return data;
113  }
114 
118  void takeOff() { drone_hardware_.takeoff(); }
119 
125  void enableAutonomousMode() { drone_hardware_.flowControl(true); }
126 
130  void land() { drone_hardware_.land(); }
131 
137  std::string getSystemStatus() const {
138  parsernode::common::quaddata data = getUAVData();
139  HtmlTableWriter table_writer;
140  table_writer.beginRow();
141  table_writer.addHeader("UAV Status", Colors::blue, 4);
142  table_writer.beginRow();
143  std::string battery_percent_color =
144  (data.batterypercent > config_.minimum_battery_percent() ? Colors::green
145  : Colors::red);
146  table_writer.addCell(data.batterypercent, "Battery Percent",
147  battery_percent_color, 2);
148  table_writer.beginRow();
149  table_writer.addCell(data.localpos.x, "Local x");
150  table_writer.addCell(data.localpos.y, "Local y");
151  table_writer.addCell(data.localpos.z, "Local z");
152  table_writer.addCell(data.altitude, "Altitude");
153  table_writer.beginRow();
154  table_writer.addCell(data.rpydata.x * (180 / M_PI), "Roll");
155  table_writer.addCell(data.rpydata.y * (180 / M_PI), "Pitch");
156  table_writer.addCell(data.rpydata.z * (180 / M_PI), "Yaw");
157  table_writer.beginRow();
158  table_writer.addCell(data.magdata.x, "Mag x");
159  table_writer.addCell(data.magdata.y, "Mag y");
160  table_writer.addCell(data.magdata.z, "Mag z");
161  table_writer.beginRow();
162  table_writer.addCell(data.linacc.x, "Acc x");
163  table_writer.addCell(data.linacc.y, "Acc y");
164  table_writer.addCell(data.linacc.z, "Acc z");
165  table_writer.beginRow();
166  table_writer.addCell(data.linvel.x, "Vel x");
167  table_writer.addCell(data.linvel.y, "Vel y");
168  table_writer.addCell(data.linvel.z, "Vel z");
169  table_writer.beginRow();
170  table_writer.addCell(data.velocity_goal.x, "Goal vel x");
171  table_writer.addCell(data.velocity_goal.y, "Goal vel y");
172  table_writer.addCell(data.velocity_goal.z, "Goal vel z");
173  table_writer.addCell(data.velocity_goal_yaw, "Goal yaw");
174  table_writer.beginRow();
175  table_writer.addCell(data.position_goal.x, "Goal pos x");
176  table_writer.addCell(data.position_goal.y, "Goal pos y");
177  table_writer.addCell(data.position_goal.z, "Goal pos z");
178  table_writer.addCell(data.velocity_goal_yaw, "Goal yaw");
179  table_writer.beginRow();
180  table_writer.addCell(data.mass, "Mass");
181  table_writer.addCell(data.timestamp, "Timestamp", Colors::white, 2);
182  table_writer.beginRow();
183  std::string quad_state_color = (data.armed ? Colors::green : Colors::white);
184  table_writer.addCell(data.quadstate, "Quadstate", quad_state_color, 2);
185  return table_writer.getTableString();
186  }
187 
192  UAVSystemConfig getConfiguration() { return config_; }
193 
198  parsernode::common::quaddata data = getUAVData();
199  home_location_.x = data.localpos.x;
200  home_location_.y = data.localpos.y;
201  home_location_.z = data.localpos.z;
202  home_location_.yaw = data.rpydata.z;
203  home_location_specified_ = true;
204  }
205 
211  bool isHomeLocationSpecified() { return home_location_specified_; }
212 
218  PositionYaw getHomeLocation() { return home_location_; }
219 };
Builtin velocity controller.
Definition: builtin_controller.h:92
static constexpr const char * white
White color hex code.
Definition: html_utils.h:34
static constexpr const char * green
Green color hex code.
Definition: html_utils.h:18
double y
y component in m
Definition: position.h:23
TypeMap< AbstractControllerHardwareConnector > controller_hardware_connector_container_
Container to store and retrieve controller-hardware-connectors.
Definition: base_robot_system.h:23
void setHomeLocation()
save current location as home location
Definition: uav_system.h:197
bool isHomeLocationSpecified()
Check if home location is specified.
Definition: uav_system.h:211
std::string getTableString()
Get the html table in string format.
Definition: html_utils.h:170
A controller that passes joystick commands to a drone's RPYT controller.
Definition: manual_rpyt_controller.h:11
UAVSystem(parsernode::Parser &drone_hardware)
Constructor with default configuration.
Definition: uav_system.h:73
double x
x component in m
Definition: position.h:22
Stores Position, yaw. PositionYaw is used as the goal for UAV systems.
Definition: position_yaw.h:10
UAVSystem(parsernode::Parser &drone_hardware, UAVSystemConfig config)
Constructor.
Definition: uav_system.h:85
parsernode::Parser & drone_hardware_
Hardware.
Definition: uav_system.h:26
Owns, initializes, and facilitates communication between different hardware/software components...
Definition: uav_system.h:21
Provides functions to switch between active controllers and get goals.
Definition: base_robot_system.h:16
Manages communication between a drone plugin and a velocity controller that outputs velocity commands...
Definition: builtin_velocity_controller_drone_connector.h:13
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
static constexpr const char * blue
Blue color hex code.
Definition: html_utils.h:22
void takeOff()
Public API call to takeoff.
Definition: uav_system.h:118
Manages communication between a drone plugin and a position controller that outputs position commands...
Definition: position_controller_drone_connector.h:14
parsernode::common::quaddata getUAVData() const
Get sensor data from UAV.
Definition: uav_system.h:109
void land()
Public API call to land.
Definition: uav_system.h:130
void addCell(const DataT &data, std::string header="", std::string bg_color=Colors::white, int colspan=1)
Add a cell to the table. Should be called after beginning a row. Otherwise will throw an exception...
Definition: html_utils.h:116
PositionYaw getHomeLocation()
Stored home location.
Definition: uav_system.h:218
Maps Joystick goals to rpythrust commands to quadrotor.
Definition: manual_rpyt_controller_drone_connector.h:12
std::string getSystemStatus() const
Provide the current state of UAV system.
Definition: uav_system.h:137
void beginRow()
Begin a new row in the table.
Definition: html_utils.h:135
double yaw
Orientation about body axis rad.
Definition: position_yaw.h:51
double z
z component in m
Definition: position.h:24
void addHeader(std::string header, std::string text_color=Colors::black, int colspan=1)
Add a table header. Should be called after beginning a row.
Definition: html_utils.h:152
UAVSystemConfig getConfiguration()
Get system configuration.
Definition: uav_system.h:192
UAVSystemConfig config_
UAV configuration parameters.
Definition: uav_system.h:30
Helper class to write html tables to text format.
Definition: html_utils.h:91
Builtin position controller.
Definition: builtin_controller.h:36
void setObject(ObjectT &object)
Store the object with base class as GenericObjectT.
Definition: type_map.h:27
static constexpr const char * red
Red color hex code.
Definition: html_utils.h:14