Auterion App SDK
Auterion SDK is a library that can be used by AuterionOS apps to communicate with the system.
Loading...
Searching...
No Matches
system_state.hpp
1/****************************************************************************
2 *
3 * Copyright 2023 Auterion AG. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice, this
9 * list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 *
15 * 3. Neither the name of the copyright holder nor the names of its contributors
16 * may be used to endorse or promote products derived from this software without
17 * specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 *
31 ****************************************************************************/
32
33#pragma once
34
35#include <Eigen/Eigen>
36#include <memory>
37#include <optional>
38
39namespace auterion {
44enum class SubscriptionType {
45 LOCAL_POSITION,
46 GLOBAL_POSITION,
47 ATTITUDE,
48 ANGULAR_RATES,
49 ODOMETRY,
50 ARMED,
51 SYSTEM_ID,
52 HOME_POSITION,
53 BATTERY,
54 VTOL_STATE,
55 MANUAL_INPUT,
56 LAND_DETECTED,
57 WIND,
58 AIRSPEED,
59 NAVIGATION_STATE,
60 RC_INPUT
61};
62
84
92 double latitude_deg;
101 inline Eigen::Vector3d toEigenVector() const {
102 return Eigen::Vector3d{latitude_deg, longitude_deg, altitude_amsl_m};
103 }
104};
105
112struct Odometry {
113 Eigen::Quaternionf attitude;
114 Eigen::Vector3f angular_velocity;
115 Eigen::Vector3f position;
116 Eigen::Vector3f velocity;
117};
118
130
148
156 float voltage_v;
157 float current_a;
160 float remaining;
163 Eigen::VectorXf cell_voltage_v;
164};
165
172 UNDEFINED,
173 TRANSITION_TO_FIXED_WING,
174 TRANSITION_TO_MULTICOPTER,
175 MULTICOPTER,
176 FIXED_WING
177};
178
186 float roll;
187 float pitch;
188 float yaw;
189 float throttle;
191 Eigen::Matrix<float, 6, 1> aux;
195 bool valid;
196};
197
206 uint8_t nav_state;
208};
209
216struct RcInput {
217 bool failsafe;
218 bool lost;
219};
220
228 bool landed;
230};
231
238struct Wind {
241 std::optional<float> variance_north;
243 std::optional<float> variance_east;
245};
246
253struct Airspeed {
254 std::optional<float>
256 std::optional<float> calibrated_airspeed_m_s;
258 std::optional<float> true_airspeed_m_s;
259};
260
262class SDK;
263
264template <SubscriptionType S, typename DataType>
265class SubscriptionImpl;
266
267class SystemStateImpl;
269
279template <SubscriptionType S, typename DataType>
281 public:
282 Subscription(const std::shared_ptr<SubscriptionImpl<S, DataType>>& impl);
283
292 void onUpdate(std::function<void(DataType)> callback);
293
302 void subscribe(std::function<void(DataType)> callback);
303
309 DataType last() const;
310
316 bool isLastValid() const;
317
318 private:
319 std::shared_ptr<SubscriptionImpl<S, DataType>> _impl;
320};
321
353 public:
354 SystemState(SDK& sdk);
355 ~SystemState() = default;
356
373
374 SystemState& subscribeLocalPosition(std::function<void(LocalPosition)> callback = nullptr) {
375 localPosition().subscribe(callback);
376 return *this;
377 }
378
379 SystemState& subscribeGlobalPosition(std::function<void(GlobalPosition)> callback = nullptr) {
380 globalPosition().subscribe(callback);
381 return *this;
382 }
383
384 SystemState& subscribeAttitude(std::function<void(Eigen::Quaternionf)> callback = nullptr) {
385 attitude().subscribe(callback);
386 return *this;
387 }
388
389 SystemState& subscribeOdometry(std::function<void(Odometry)> callback = nullptr) {
390 odometry().subscribe(callback);
391 return *this;
392 }
393
394 SystemState& subscribeAngularRates(std::function<void(AngularRates)> callback = nullptr) {
395 angularRates().subscribe(callback);
396 return *this;
397 }
398
399 SystemState& subscribeArmed(std::function<void(bool)> callback = nullptr) {
400 armed().subscribe(callback);
401 return *this;
402 }
403
404 SystemState& subscribeSystemId(std::function<void(uint8_t)> callback = nullptr) {
405 systemId().subscribe(callback);
406 return *this;
407 }
408
409 SystemState& subscribeHomePosition(std::function<void(HomePosition)> callback = nullptr) {
410 homePosition().subscribe(callback);
411 return *this;
412 }
413
414 SystemState& subscribeBattery(std::function<void(BatteryStatus)> callback = nullptr) {
415 battery().subscribe(callback);
416 return *this;
417 }
418
419 SystemState& subscribeVtolState(std::function<void(VtolState)> callback = nullptr) {
420 vtolState().subscribe(callback);
421 return *this;
422 }
423
424 SystemState& subscribeManualInput(std::function<void(ManualInput)> callback = nullptr) {
425 manualInput().subscribe(callback);
426 return *this;
427 }
428
429 SystemState& subscribeLandDetected(std::function<void(LandDetected)> callback = nullptr) {
430 landDetected().subscribe(callback);
431 return *this;
432 }
433
434 SystemState& subscribeWind(std::function<void(Wind)> callback = nullptr) {
435 wind().subscribe(callback);
436 return *this;
437 }
438
439 SystemState& subscribeAirspeed(std::function<void(Airspeed)> callback = nullptr) {
440 airspeed().subscribe(callback);
441 return *this;
442 }
443
444 SystemState& subscribeNavigationState(std::function<void(NavigationState)> callback = nullptr) {
445 navigationState().subscribe(callback);
446 return *this;
447 }
448
449 SystemState& subscribeRcInput(std::function<void(RcInput)> callback = nullptr) {
450 rcInput().subscribe(callback);
451 return *this;
452 }
453
454 private:
455 std::shared_ptr<SystemStateImpl> _impl;
456};
457
459} // namespace auterion
SDK execution class. All callbacks are called on the same thread.
Definition auterion.hpp:133
A template class for managing subscriptions to data coming from the vehicle.
Definition system_state.hpp:280
void subscribe(std::function< void(DataType)> callback)
Activates the subscription process and registers a callback function if provided.
bool isLastValid() const
Checks if the last received data is valid.
DataType last() const
Retrieves the last received data.
void onUpdate(std::function< void(DataType)> callback)
Regsiters a callback function to be called when the data is updated.
Provides access to the system's state, including flight controller telemetry.
Definition system_state.hpp:352
VtolState
Represents the VTOL state.
Definition system_state.hpp:171
Represents validated airspeed.
Definition system_state.hpp:253
std::optional< float > true_airspeed_m_s
Definition system_state.hpp:258
std::optional< float > calibrated_airspeed_m_s
Definition system_state.hpp:256
std::optional< float > indicated_airspeed_m_s
Definition system_state.hpp:255
Represents angular rates and accelerations in the FLU body frame.
Definition system_state.hpp:125
Eigen::Vector3f angular_acceleration_flu_rad_s
Definition system_state.hpp:127
Eigen::Vector3f angular_velocity_flu_rad_s
Definition system_state.hpp:126
Represents the status of the battery.
Definition system_state.hpp:155
float discharged_mah
Definition system_state.hpp:159
float remaining
Definition system_state.hpp:160
float voltage_v
Definition system_state.hpp:156
int cell_count
Definition system_state.hpp:162
Eigen::VectorXf cell_voltage_v
Definition system_state.hpp:163
float current_a
Definition system_state.hpp:157
Represents global position using latitude, longitude, and altitude.
Definition system_state.hpp:91
double longitude_deg
Definition system_state.hpp:93
Eigen::Vector3d toEigenVector() const
Converts the global position to an Eigen vector.
Definition system_state.hpp:101
double altitude_amsl_m
Definition system_state.hpp:94
double latitude_deg
Definition system_state.hpp:92
Represents the home position in both local ENU and global coordinates.
Definition system_state.hpp:137
bool was_set_manually
Definition system_state.hpp:146
double yaw
Definition system_state.hpp:140
bool global_position_valid
Definition system_state.hpp:143
bool local_position_valid
Definition system_state.hpp:144
bool altitude_valid
Definition system_state.hpp:142
Eigen::Vector3f local_position_enu_m
Definition system_state.hpp:138
GlobalPosition global_position
Definition system_state.hpp:139
Represents landed state of the vehicle.
Definition system_state.hpp:227
bool in_descend
Definition system_state.hpp:229
Represents local position, velocity, and acceleration in the ENU coordinate system.
Definition system_state.hpp:69
bool horizontal_position_valid
Definition system_state.hpp:78
bool horizontal_velocity_valid
Definition system_state.hpp:80
bool vertical_velocity_valid
Definition system_state.hpp:81
double heading
Definition system_state.hpp:74
Eigen::Vector3f velocity_enu_m
Definition system_state.hpp:71
Eigen::Vector3f acceleration_enu_m
Definition system_state.hpp:72
Eigen::Vector3f position_enu_m
Definition system_state.hpp:70
bool dist_bottom_valid
Definition system_state.hpp:82
bool vertical_position_valid
Definition system_state.hpp:79
double unaided_heading
Definition system_state.hpp:75
Represents manual input from a user.
Definition system_state.hpp:185
float pitch
Definition system_state.hpp:187
float roll
Definition system_state.hpp:186
Eigen::Matrix< float, 6, 1 > aux
Definition system_state.hpp:191
float throttle
Definition system_state.hpp:189
bool sticks_moving
Definition system_state.hpp:193
float yaw
Definition system_state.hpp:188
bool valid
Definition system_state.hpp:195
The vehicle's navigation state (flight mode)
Definition system_state.hpp:204
bool external_mode
Definition system_state.hpp:207
uint8_t nav_state
Definition system_state.hpp:206
Represents odometry data including attitude and angular rates.
Definition system_state.hpp:112
Eigen::Vector3f velocity
Definition system_state.hpp:116
Eigen::Vector3f position
Definition system_state.hpp:115
Eigen::Vector3f angular_velocity
Definition system_state.hpp:114
Eigen::Quaternionf attitude
Definition system_state.hpp:113
The state of the RC receiver's link.
Definition system_state.hpp:216
bool failsafe
Definition system_state.hpp:217
bool lost
Definition system_state.hpp:218
Represents wind speed and direction.
Definition system_state.hpp:238
float windspeed_north
Definition system_state.hpp:239
std::optional< float > variance_east
Definition system_state.hpp:243
float windspeed_east
Definition system_state.hpp:240
std::optional< float > variance_north
Definition system_state.hpp:241