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 <cstdint>
37#include <memory>
38#include <optional>
39
40namespace auterion {
45enum class SubscriptionType {
46 LOCAL_POSITION,
47 GLOBAL_POSITION,
48 ATTITUDE,
49 ANGULAR_RATES,
50 ODOMETRY,
51 ARMED,
52 SYSTEM_ID,
53 HOME_POSITION,
54 BATTERY,
55 VTOL_STATE,
56 MANUAL_INPUT,
57 LAND_DETECTED,
58 WIND,
59 AIRSPEED,
60 NAVIGATION_STATE,
61 RC_INPUT
62};
63
85
93 double latitude_deg;
102 inline Eigen::Vector3d toEigenVector() const {
103 return Eigen::Vector3d{latitude_deg, longitude_deg, altitude_amsl_m};
104 }
105};
106
113struct Odometry {
114 Eigen::Quaternionf attitude;
115 Eigen::Vector3f angular_velocity;
116 Eigen::Vector3f position;
117 Eigen::Vector3f velocity;
120};
121
133
151
159 float voltage_v;
160 float current_a;
163 float remaining;
166 Eigen::VectorXf cell_voltage_v;
167};
168
175 UNDEFINED,
176 TRANSITION_TO_FIXED_WING,
177 TRANSITION_TO_MULTICOPTER,
178 MULTICOPTER,
179 FIXED_WING
180};
181
189 float roll;
190 float pitch;
191 float yaw;
192 float throttle;
194 Eigen::Matrix<float, 6, 1> aux;
198 bool valid;
199};
200
209 uint8_t nav_state;
211};
212
219struct RcInput {
220 bool failsafe;
221 bool lost;
222};
223
231 bool landed;
233};
234
241struct Wind {
244 std::optional<float> variance_north;
246 std::optional<float> variance_east;
248};
249
256struct Airspeed {
257 std::optional<float>
259 std::optional<float> calibrated_airspeed_m_s;
261 std::optional<float> true_airspeed_m_s;
262};
263
265class SDK;
266
267template <SubscriptionType S, typename DataType>
268class SubscriptionImpl;
269
270class SystemStateImpl;
272
282template <SubscriptionType S, typename DataType>
284 public:
285 Subscription(const std::shared_ptr<SubscriptionImpl<S, DataType>>& impl);
286
295 void onUpdate(std::function<void(DataType)> callback);
296
305 void subscribe(std::function<void(DataType)> callback);
306
312 DataType last() const;
313
319 bool isLastValid() const;
320
321 private:
322 std::shared_ptr<SubscriptionImpl<S, DataType>> _impl;
323};
324
356 public:
357 SystemState(SDK& sdk);
358 ~SystemState() = default;
359
376
377 SystemState& subscribeLocalPosition(std::function<void(LocalPosition)> callback = nullptr) {
378 localPosition().subscribe(callback);
379 return *this;
380 }
381
382 SystemState& subscribeGlobalPosition(std::function<void(GlobalPosition)> callback = nullptr) {
383 globalPosition().subscribe(callback);
384 return *this;
385 }
386
387 SystemState& subscribeAttitude(std::function<void(Eigen::Quaternionf)> callback = nullptr) {
388 attitude().subscribe(callback);
389 return *this;
390 }
391
392 SystemState& subscribeOdometry(std::function<void(Odometry)> callback = nullptr) {
393 odometry().subscribe(callback);
394 return *this;
395 }
396
397 SystemState& subscribeAngularRates(std::function<void(AngularRates)> callback = nullptr) {
398 angularRates().subscribe(callback);
399 return *this;
400 }
401
402 SystemState& subscribeArmed(std::function<void(bool)> callback = nullptr) {
403 armed().subscribe(callback);
404 return *this;
405 }
406
407 SystemState& subscribeSystemId(std::function<void(uint8_t)> callback = nullptr) {
408 systemId().subscribe(callback);
409 return *this;
410 }
411
412 SystemState& subscribeHomePosition(std::function<void(HomePosition)> callback = nullptr) {
413 homePosition().subscribe(callback);
414 return *this;
415 }
416
417 SystemState& subscribeBattery(std::function<void(BatteryStatus)> callback = nullptr) {
418 battery().subscribe(callback);
419 return *this;
420 }
421
422 SystemState& subscribeVtolState(std::function<void(VtolState)> callback = nullptr) {
423 vtolState().subscribe(callback);
424 return *this;
425 }
426
427 SystemState& subscribeManualInput(std::function<void(ManualInput)> callback = nullptr) {
428 manualInput().subscribe(callback);
429 return *this;
430 }
431
432 SystemState& subscribeLandDetected(std::function<void(LandDetected)> callback = nullptr) {
433 landDetected().subscribe(callback);
434 return *this;
435 }
436
437 SystemState& subscribeWind(std::function<void(Wind)> callback = nullptr) {
438 wind().subscribe(callback);
439 return *this;
440 }
441
442 SystemState& subscribeAirspeed(std::function<void(Airspeed)> callback = nullptr) {
443 airspeed().subscribe(callback);
444 return *this;
445 }
446
447 SystemState& subscribeNavigationState(std::function<void(NavigationState)> callback = nullptr) {
448 navigationState().subscribe(callback);
449 return *this;
450 }
451
452 SystemState& subscribeRcInput(std::function<void(RcInput)> callback = nullptr) {
453 rcInput().subscribe(callback);
454 return *this;
455 }
456
457 private:
458 std::shared_ptr<SystemStateImpl> _impl;
459};
460
462} // 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:283
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:355
VtolState
Represents the VTOL state.
Definition system_state.hpp:174
Represents validated airspeed.
Definition system_state.hpp:256
std::optional< float > true_airspeed_m_s
Definition system_state.hpp:261
std::optional< float > calibrated_airspeed_m_s
Definition system_state.hpp:259
std::optional< float > indicated_airspeed_m_s
Definition system_state.hpp:258
Represents angular rates and accelerations in the FLU body frame.
Definition system_state.hpp:128
Eigen::Vector3f angular_acceleration_flu_rad_s
Definition system_state.hpp:130
Eigen::Vector3f angular_velocity_flu_rad_s
Definition system_state.hpp:129
Represents the status of the battery.
Definition system_state.hpp:158
float discharged_mah
Definition system_state.hpp:162
float remaining
Definition system_state.hpp:163
float voltage_v
Definition system_state.hpp:159
int cell_count
Definition system_state.hpp:165
Eigen::VectorXf cell_voltage_v
Definition system_state.hpp:166
float current_a
Definition system_state.hpp:160
Represents global position using latitude, longitude, and altitude.
Definition system_state.hpp:92
double longitude_deg
Definition system_state.hpp:94
Eigen::Vector3d toEigenVector() const
Converts the global position to an Eigen vector.
Definition system_state.hpp:102
double altitude_amsl_m
Definition system_state.hpp:95
double latitude_deg
Definition system_state.hpp:93
Represents the home position in both local ENU and global coordinates.
Definition system_state.hpp:140
bool was_set_manually
Definition system_state.hpp:149
double yaw
Definition system_state.hpp:143
bool global_position_valid
Definition system_state.hpp:146
bool local_position_valid
Definition system_state.hpp:147
bool altitude_valid
Definition system_state.hpp:145
Eigen::Vector3f local_position_enu_m
Definition system_state.hpp:141
GlobalPosition global_position
Definition system_state.hpp:142
Represents landed state of the vehicle.
Definition system_state.hpp:230
bool in_descend
Definition system_state.hpp:232
Represents local position, velocity, and acceleration in the ENU coordinate system.
Definition system_state.hpp:70
bool horizontal_position_valid
Definition system_state.hpp:79
bool horizontal_velocity_valid
Definition system_state.hpp:81
bool vertical_velocity_valid
Definition system_state.hpp:82
double heading
Definition system_state.hpp:75
Eigen::Vector3f velocity_enu_m
Definition system_state.hpp:72
Eigen::Vector3f acceleration_enu_m
Definition system_state.hpp:73
Eigen::Vector3f position_enu_m
Definition system_state.hpp:71
bool dist_bottom_valid
Definition system_state.hpp:83
bool vertical_position_valid
Definition system_state.hpp:80
double unaided_heading
Definition system_state.hpp:76
Represents manual input from a user.
Definition system_state.hpp:188
float pitch
Definition system_state.hpp:190
float roll
Definition system_state.hpp:189
Eigen::Matrix< float, 6, 1 > aux
Definition system_state.hpp:194
float throttle
Definition system_state.hpp:192
bool sticks_moving
Definition system_state.hpp:196
float yaw
Definition system_state.hpp:191
bool valid
Definition system_state.hpp:198
The vehicle's navigation state (flight mode)
Definition system_state.hpp:207
bool external_mode
Definition system_state.hpp:210
uint8_t nav_state
Definition system_state.hpp:209
Represents odometry data including attitude and angular rates.
Definition system_state.hpp:113
Eigen::Vector3f velocity
Definition system_state.hpp:117
uint64_t timestamp_sample_us
Definition system_state.hpp:118
Eigen::Vector3f position
Definition system_state.hpp:116
Eigen::Vector3f angular_velocity
Definition system_state.hpp:115
Eigen::Quaternionf attitude
Definition system_state.hpp:114
The state of the RC receiver's link.
Definition system_state.hpp:219
bool failsafe
Definition system_state.hpp:220
bool lost
Definition system_state.hpp:221
Represents wind speed and direction.
Definition system_state.hpp:241
float windspeed_north
Definition system_state.hpp:242
std::optional< float > variance_east
Definition system_state.hpp:246
float windspeed_east
Definition system_state.hpp:243
std::optional< float > variance_north
Definition system_state.hpp:244