Auterion App SDK
Auterion SDK is a library that can be used by AuterionOS apps to communicate with the system.
Loading...
Searching...
No Matches
gimbal.hpp
1/****************************************************************************
2 *
3 * Copyright 2025 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/system_state/system_state.hpp>
38#include <chrono>
39#include <iostream>
40#include <map>
41#include <thread>
42#include <vector>
43
44namespace auterion {
49class SDK;
50class GimbalImpl;
51
57 Eigen::Quaternionf q_flu;
58 Eigen::Quaternionf q_enu;
59};
60
71struct GimbalMode {
72 public:
77 enum class AxisMode {
78 WorldLock,
80 };
81
82 GimbalMode() = default;
83 GimbalMode(AxisMode roll_mode, AxisMode pitch_mode, AxisMode yaw_mode)
84 : roll(roll_mode), pitch(pitch_mode), yaw(yaw_mode) {}
85
86 std::string toString() const;
87
91};
92
98 public:
99 GimbalCapabilities() = default;
100
106 bool meetsRequirements(const GimbalCapabilities& requirements) const;
107
113 bool supportsMode(const GimbalMode& mode) const;
114
115 std::string toString() const;
116
117 GimbalCapabilities& canRetract() {
118 can_retract = true;
119 return *this;
120 }
121 GimbalCapabilities& canNeutral() {
122 can_neutral = true;
123 return *this;
124 }
125 GimbalCapabilities& canRoll() {
126 can_roll = true;
127 return *this;
128 }
129 GimbalCapabilities& canRollFollow() {
130 can_roll_follow = true;
131 return *this;
132 }
133 GimbalCapabilities& canRollLock() {
134 can_roll_lock = true;
135 return *this;
136 }
137 GimbalCapabilities& canPitch() {
138 can_pitch = true;
139 return *this;
140 }
141 GimbalCapabilities& canPitchFollow() {
142 can_pitch_follow = true;
143 return *this;
144 }
145 GimbalCapabilities& canPitchLock() {
146 can_pitch_lock = true;
147 return *this;
148 }
149 GimbalCapabilities& canYaw() {
150 can_yaw = true;
151 return *this;
152 }
153 GimbalCapabilities& canYawFollow() {
154 can_yaw_follow = true;
155 return *this;
156 }
157 GimbalCapabilities& canYawLock() {
158 can_yaw_lock = true;
159 return *this;
160 }
161 GimbalCapabilities& canInfiniteYaw() {
162 can_infinite_yaw = true;
163 return *this;
164 }
165 GimbalCapabilities& canPointLocationLocal() {
166 can_point_location_local = true;
167 return *this;
168 }
169 GimbalCapabilities& canPointLocationGlobal() {
170 can_point_location_global = true;
171 return *this;
172 }
173
174 GimbalCapabilities& RollRangeDeg(float min_deg, float max_deg) {
175 roll_min_deg = min_deg;
176 roll_max_deg = max_deg;
177 return *this;
178 }
179 GimbalCapabilities& PitchRangeDeg(float min_deg, float max_deg) {
180 pitch_min_deg = min_deg;
181 pitch_max_deg = max_deg;
182 return *this;
183 }
184 GimbalCapabilities& YawRangeDeg(float min_deg, float max_deg) {
185 yaw_min_deg = min_deg;
186 yaw_max_deg = max_deg;
187 return *this;
188 }
189
190 bool can_retract{false};
191 bool can_neutral{false};
192 bool can_roll{false};
193 bool can_roll_follow{false};
194 bool can_roll_lock{false};
195 bool can_pitch{false};
196 bool can_pitch_follow{false};
197 bool can_pitch_lock{false};
198 bool can_yaw{false};
199 bool can_yaw_follow{false};
200 bool can_yaw_lock{false};
201 bool can_infinite_yaw{false};
202 bool can_point_location_local{false};
203 bool can_point_location_global{false};
204
205 float roll_min_deg{0};
206 float roll_max_deg{0};
207 float pitch_min_deg{0};
208 float pitch_max_deg{0};
209 float yaw_min_deg{0};
210 float yaw_max_deg{0};
211};
212
221 public:
222 GimbalDescriptor() = default;
223 explicit GimbalDescriptor(const GimbalCapabilities& capabilities)
224 : capabilities(capabilities) {}
225 explicit GimbalDescriptor(const std::string& custom_name, const std::string& vendor_name,
226 const std::string& model_name, const GimbalCapabilities& capabilities)
227 : custom_name(custom_name),
228 vendor_name(vendor_name),
229 model_name(model_name),
230 capabilities(capabilities) {}
231
232 std::string custom_name{};
233 std::string vendor_name{};
234 std::string model_name{};
235 GimbalCapabilities capabilities{};
236
237 std::string toString() const;
238};
239
244class Gimbal {
245 public:
257 Gimbal(SDK& sdk, const std::function<bool(const GimbalDescriptor& candidate)>& find_callback);
258
276 Gimbal(SDK& sdk, const GimbalDescriptor& descriptor = GimbalDescriptor{})
277 : Gimbal(sdk, [&](const GimbalDescriptor& candidate) {
278 if (!descriptor.custom_name.empty()) {
279 return descriptor.custom_name == candidate.custom_name;
280 }
281 if (!descriptor.model_name.empty() || !descriptor.vendor_name.empty()) {
282 return descriptor.model_name == candidate.model_name &&
283 descriptor.vendor_name == candidate.vendor_name;
284 }
285 return candidate.capabilities.meetsRequirements(descriptor.capabilities);
286 }) {}
287
288 ~Gimbal() = default;
289
297 void setGimbalMode(const GimbalMode& gimbal_mode);
298
306 bool isInControl() const;
307
316 bool takeControl(const bool force_takeover = false);
317
322
329 void setRateControl(const float roll_rate_rad_s, const float pitch_rate_rad_s,
330 const float yaw_rate_rad_s) const;
331
339 void setAttitudeControl(const Eigen::Quaternionf& q) const;
340
350 void setAttitudeControl(const float roll_deg, const float pitch_deg, const float yaw_deg) const;
351
356 void setRoiLocation(const auterion::GlobalPosition& position) const;
357
361 void setRoiLocationNone() const;
362
367 void subscribeAttitude(std::function<void(const GimbalAttitude&)> callback);
368
369 private:
370 std::shared_ptr<GimbalImpl> _impl;
371};
372
373} // namespace auterion
Gimbal control class.
Definition gimbal.hpp:244
bool isInControl() const
Check control of the gimbal.
void setAttitudeControl(const float roll_deg, const float pitch_deg, const float yaw_deg) const
Set attitude control using Euler angles.
void setRoiLocationNone() const
Clear Region of Interest (ROI) location.
void setRateControl(const float roll_rate_rad_s, const float pitch_rate_rad_s, const float yaw_rate_rad_s) const
Set rate control.
bool takeControl(const bool force_takeover=false)
Take control of the gimbal.
void subscribeAttitude(std::function< void(const GimbalAttitude &)> callback)
Subscribe to gimbal attitude updates.
void setRoiLocation(const auterion::GlobalPosition &position) const
Set Region of Interest (ROI) location.
void setAttitudeControl(const Eigen::Quaternionf &q) const
Set attitude control using quaternion.
void setGimbalMode(const GimbalMode &gimbal_mode)
Sets gimbal mode.
Gimbal(SDK &sdk, const GimbalDescriptor &descriptor=GimbalDescriptor{})
Constructs a gimbal object based on a descriptor.
Definition gimbal.hpp:276
Gimbal(SDK &sdk, const std::function< bool(const GimbalDescriptor &candidate)> &find_callback)
Constructs a gimbal object based on a selection function.
void releaseControl()
Release control of the gimbal.
SDK execution class. All callbacks are called on the same thread.
Definition auterion.hpp:97
AxisMode
Enum defining the axis modes.
Definition gimbal.hpp:77
@ VehicleFollow
Axis follows the vehicle's motion.
@ WorldLock
Axis maintains a fixed world orientation.
Represents the attitude of a gimbal.
Definition gimbal.hpp:56
Represents the capabilities of a gimbal.
Definition gimbal.hpp:97
bool meetsRequirements(const GimbalCapabilities &requirements) const
Check if the given requirements are met by the current capabilities.
float roll_min_deg
Minimal roll range (degrees)
Definition gimbal.hpp:205
bool supportsMode(const GimbalMode &mode) const
Check if a given gimbal mode is supported by the current capabilities.
float yaw_min_deg
Minimal yaw range (degrees)
Definition gimbal.hpp:209
float roll_max_deg
Maximal roll range (degrees)
Definition gimbal.hpp:206
float pitch_max_deg
Maximal pitch range (degrees)
Definition gimbal.hpp:208
float pitch_min_deg
Minimal pitch range (degrees)
Definition gimbal.hpp:207
float yaw_max_deg
Maximal yaw range (degrees)
Definition gimbal.hpp:210
Describes a gimbal object.
Definition gimbal.hpp:220
Represents the gimbal mode with different axis settings.
Definition gimbal.hpp:71
Represents global position using latitude, longitude, and altitude.
Definition system_state.hpp:88