onboardsdk
Loading...
Searching...
No Matches
Drone.hpp
1#pragma once
2#include <eventpp/callbacklist.h>
3
4#include <memory>
5#include <optional>
6#include <string>
7
8#include "DroneError.hpp"
9#include "imu/ThreadedMPU9250.hpp"
10#include "logging/Logger.hpp"
11#include "observer/PioneerObserver.hpp"
12#include "pmu/NonBlockingPMU.hpp"
13#include "pmu/TcpPmu.hpp"
14#include "sensors/FactoryPressureSensor.hpp"
15#include "sensors/PressureSensor.hpp"
16#include "thrust_allocation/ControlForce.hpp"
17#include "thrust_allocation/PioneerAllocator.hpp"
18#include "tilt/ITiltControl.hpp"
19
20namespace blunux::drone {
21
30class Drone : public logging::Logger<Drone> {
31 public:
32 explicit Drone(std::array<std::shared_ptr<imu::IImu>, 2> imu,
33 std::shared_ptr<pmu::IPMU> pmu,
34 std::shared_ptr<tilt::ITiltControl> tilt_controller);
35
41 void set_light(float intensity);
42
49
55 float get_light() const;
56
62 float get_depth(bool wait_for_data = true) const;
63
69 float get_water_temperature(bool wait_for_data = true) const;
70
76 std::string get_blunux_version() const;
77
83 std::string get_model_name() const;
84
90 blueye::protocol::Model get_model() const;
91
98
106 imu::ImuData get_imu_raw(unsigned int n) const;
107
114
122 imu::ImuSelfTest imu_self_test(unsigned int n) const;
123
129 sensors::DepthSelfTestResult depth_self_test() const;
130
137 std::optional<float> get_battery_percentage(bool wait_for_data = true) const;
144 std::optional<std::string> get_battery_type(bool wait_for_data = true) const;
145
146 void add_pressure_callback(std::function<void(const Pressure&)> cb);
147 void add_temperature_callback(std::function<void(const Temperature&)> cb);
148 void add_error_callback(std::function<void(const DroneError&)> cb);
149
150 std::shared_ptr<tilt::ITiltControl> tilt() {
151 return std::dynamic_pointer_cast<tilt::ITiltControl>(tilt_controller);
152 }
153
154 std::shared_ptr<observer::ICompassCalibration> compass_calibration() {
155 return observer->compass_calibration();
156 }
157
158 std::shared_ptr<pmu::IPMUCallbacks> pmu_callbacks() {
159 return std::dynamic_pointer_cast<pmu::IPMUCallbacks>(pmu);
160 }
161
162 std::shared_ptr<observer::IObserverState> observer_state() {
163 return std::dynamic_pointer_cast<observer::IObserverState>(observer);
164 }
165
172 void set_fluid_density(double density) {
173 if (optional_pressure_sensor.has_value()) {
174 optional_pressure_sensor.value()->set_fluid_density(density);
175 }
176 }
177
183 double get_fluid_density() const {
184 return optional_pressure_sensor.has_value()
185 ? optional_pressure_sensor.value()->get_fluid_density()
186 : 1000;
187 }
188
193 blueye::protocol::PressureSensorType get_depth_sensor_type() const {
194 return optional_pressure_sensor.has_value()
195 ? optional_pressure_sensor.value()->get_sensor_type()
196 : blueye::protocol::PRESSURE_SENSOR_TYPE_UNSPECIFIED;
197 }
198
199 void clear_callbacks();
200
201 protected:
202 const std::array<std::shared_ptr<imu::IImu>, 2> imu;
203
204 const std::shared_ptr<pmu::IPMU> pmu;
205
206 std::shared_ptr<observer::PioneerObserver> observer;
207
208 private:
209 std::optional<std::unique_ptr<sensors::PressureSensor>>
210 optional_pressure_sensor =
211 sensors::FactoryPressureSensor::create_sensor();
212
213 // TODO(Johannes) lock
214 std::optional<blunux::sensors::Pressure> pressure;
215 std::optional<blunux::sensors::Temperature> temperature;
216
217 // Eigen::Vector4d control_force;
218
219 std::shared_ptr<tilt::ITiltControl> tilt_controller;
220
221 eventpp::CallbackList<void(const Pressure&)> callbacks_pressure;
222 eventpp::CallbackList<void(const Temperature&)> callbacks_temperature;
223 eventpp::CallbackList<void(const DroneError&)> callbacks_error;
224};
225
226} // namespace blunux::drone
Class representing a drone.
Definition Drone.hpp:30
float get_depth(bool wait_for_data=true) const
Get the depth.
imu::ImuData get_imu_raw(unsigned int n) const
Get the raw IMU data of IMU.
std::string get_blunux_version() const
Get the Blunux version.
imu::ImuData get_imu() const
Get the calibrated IMU data.
void set_fluid_density(double density)
Set the fluid density to change between saltwater and freshwater for the depth output.
Definition Drone.hpp:172
void set_indicator(blunux::pmu::IndicatorsSetpoint indicators)
Enable/diable the indicators on the light board.
double get_fluid_density() const
Get the fluid density.
Definition Drone.hpp:183
float get_light() const
Get the current light intensity.
sensors::DepthSelfTestResult depth_self_test() const
Get the depth self test result.
imu::ImuSelfTest imu_self_test(unsigned int n) const
Get the IMU self test result.
float get_water_temperature(bool wait_for_data=true) const
Get the water temperature.
void set_light(float intensity)
Sets intensity of the drone lights.
blueye::protocol::PressureSensorType get_depth_sensor_type() const
Get the depth sensor type.
Definition Drone.hpp:193
std::string get_model_name() const
Get the model name.
pmu::IndicatorsSetpoint get_indicator() const
Get the indicator status.
std::optional< std::string > get_battery_type(bool wait_for_data=true) const
Get the battery type.
std::optional< float > get_battery_percentage(bool wait_for_data=true) const
Get the battery percentage.
blueye::protocol::Model get_model() const
Get the drone Model.
Structure representing IMU data.
Definition ImuData.hpp:13
Structure representing IMU self-test results.
Definition ImuSelfTest.hpp:18
Structure representing setpoint values for indicators.
Definition IndicatorsSetpoint.hpp:13