Auterion App SDK
Auterion SDK is a library that can be used by AuterionOS apps to communicate with the system.
Loading...
Searching...
No Matches
mode.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 <auterion_sdk/auterion.hpp>
37#include <auterion_sdk/control/control.hpp>
38#include <functional>
39#include <memory>
40#include <variant>
41
42namespace auterion {
51 public:
55 struct PX4Mode {
56 using ID = uint8_t;
57 static const ID kModeIDInvalid;
58
59 static const ID kModeIDPosctl;
60 static const ID kModeIDTakeoff;
61 static const ID kModeIDDescend;
62 static const ID kModeIDLand;
63 static const ID kModeIDRtl;
64 static const ID kModeIDPrecisionLand;
65 };
66
70
71 bool needs_angular_velocity{false};
72 bool needs_attitude{false};
73 bool needs_local_altitude{false};
74 bool needs_local_position{false};
75 bool needs_local_position_relaxed{false};
76 bool needs_global_position{false};
77 bool needs_valid_mission{false};
78 bool needs_valid_home{false};
79 bool needs_manual_control_input{false};
80 bool can_prevent_arming{false};
81 bool user_selectable{true};
82
83 ModeConfiguration merge(const ModeConfiguration& other) const {
84 ModeConfiguration config = *this;
85 config.needs_angular_velocity =
86 config.needs_angular_velocity || other.needs_angular_velocity;
87 config.needs_attitude = config.needs_attitude || other.needs_attitude;
88 config.needs_local_altitude = config.needs_local_altitude || other.needs_local_altitude;
89 config.needs_local_position = config.needs_local_position || other.needs_local_position;
90 config.needs_local_position_relaxed =
91 config.needs_local_position_relaxed || other.needs_local_position_relaxed;
92 config.needs_global_position = config.needs_global_position || other.needs_global_position;
93 config.needs_valid_mission = config.needs_valid_mission || other.needs_valid_mission;
94 config.needs_valid_home = config.needs_valid_home || other.needs_valid_home;
95 config.needs_manual_control_input =
96 config.needs_manual_control_input || other.needs_manual_control_input;
97 config.can_prevent_arming = config.can_prevent_arming || other.can_prevent_arming;
98 config.user_selectable = config.user_selectable || other.user_selectable;
99 return config;
100 }
101
108 ModeConfiguration& replacesPX4Mode(PX4Mode::ID px4_mode_id) {
109 replace_px4_mode = px4_mode_id;
110 return *this;
111 }
112
113 ModeConfiguration& needsAngularVelocity(bool needs = true) {
114 needs_angular_velocity = needs;
115 return *this;
116 }
117
118 ModeConfiguration& needsAttitude(bool needs = true) {
119 needs_attitude = needs;
120 return *this;
121 }
122
123 ModeConfiguration& needsLocalAltitude(bool needs = true) {
124 needs_local_altitude = needs;
125 return *this;
126 }
127
128 ModeConfiguration& needsLocalPosition(bool needs = true) {
129 needs_local_position = needs;
130 return *this;
131 }
132
133 ModeConfiguration& needsLocalPositionRelaxed(bool needs = true) {
134 needs_local_position_relaxed = needs;
135 return *this;
136 }
137
138 ModeConfiguration& needsGlobalPosition(bool needs = true) {
139 needs_global_position = needs;
140 return *this;
141 }
142
143 ModeConfiguration& needsValidMission(bool needs = true) {
144 needs_valid_mission = needs;
145 return *this;
146 }
147
148 ModeConfiguration& needsValidHome(bool needs = true) {
149 needs_valid_home = needs;
150 return *this;
151 }
152
153 ModeConfiguration& needsManualControlInput(bool needs = true) {
154 needs_manual_control_input = needs;
155 return *this;
156 }
157
158 ModeConfiguration& canPreventArming(bool can = true) {
159 can_prevent_arming = can;
160 return *this;
161 }
162
163 ModeConfiguration& userSelectable(bool selectable = true) {
164 user_selectable = selectable;
165 return *this;
166 }
167};
168
169class ModeImpl;
170
176 float roll_input_normalized;
177 float pitch_input_normalized;
178 float yaw_input_normalized;
179 float throttle_input_normalized;
180
181 float aux1_input_normalized;
182 float aux2_input_normalized;
183 float aux3_input_normalized;
184 float aux4_input_normalized;
185 float aux5_input_normalized;
186 float aux6_input_normalized;
187
188 bool valid;
189};
190
228class Mode {
229 private:
230 std::shared_ptr<ModeImpl> _impl;
231
232 public:
242 Mode(SDK& sdk, const std::string& mode_name, const std::vector<ModalityConfig>& controls,
244
245 ~Mode() = default;
246
252 void onActivate(const std::function<void()>& callback);
253
259 void onDeactivate(const std::function<void()>& callback);
260
272 void onUpdateSetpoint(const std::function<Setpoint(float)>& callback);
273
274 [[nodiscard]] auterion::ManualControlInput lastManualControlInput() const;
275};
276
278} // namespace auterion
Configuration flags for specifying mode requirements and capabilities.
Definition mode.hpp:50
PX4Mode::ID replace_px4_mode
Definition mode.hpp:67
ModeConfiguration & replacesPX4Mode(PX4Mode::ID px4_mode_id)
Configures a Mode to replace an existing PX4 mode.
Definition mode.hpp:108
Defines a mode to control the vehicle using a (set) of setpoint types.
Definition mode.hpp:228
void onDeactivate(const std::function< void()> &callback)
Sets a callback function to be called when the mode is deactivated.
Mode(SDK &sdk, const std::string &mode_name, const std::vector< ModalityConfig > &controls, ModeConfiguration config=ModeConfiguration{})
Constructor to initialize a mode.
void onActivate(const std::function< void()> &callback)
Sets a callback function to be called when the mode is activated.
void onUpdateSetpoint(const std::function< Setpoint(float)> &callback)
Sets a callback function to be called at periodically at the update frequency of the mode.
SDK execution class. All callbacks are called on the same thread.
Definition auterion.hpp:97
std::variant< RateSetpoint, AttitudeSetpoint, multicopter::LocalFrameDynamicsSetpoint, multicopter::BodyFrameDynamicsSetpoint, multicopter::LocalFrameGotoSetpoint, multicopter::GlobalFrameGotoSetpoint, fixedwing::DynamicsSetpoint, vtol::TransitionSetpoint > Setpoint
Type alias for representing various types of setpoints.
Definition control.hpp:70
Represents manual input from a controller including normalized control signals and validity flag.
Definition mode.hpp:175
Struct storing PX4 mode IDs.
Definition mode.hpp:55
static const ID kModeIDRtl
PX4 RTL mode.
Definition mode.hpp:63
static const ID kModeIDPrecisionLand
PX4 Precision Land mode.
Definition mode.hpp:64
static const ID kModeIDLand
PX4 Land mode.
Definition mode.hpp:62
static const ID kModeIDInvalid
Invalid mode, will not replace any PX4 mode.
Definition mode.hpp:57
static const ID kModeIDDescend
PX4 Descend mode.
Definition mode.hpp:61
static const ID kModeIDTakeoff
PX4 Takeoff mode.
Definition mode.hpp:60
static const ID kModeIDPosctl
PX4 Position mode.
Definition mode.hpp:59