Auterion App SDK
Auterion SDK is a library that can be used by AuterionOS apps to communicate with the system.
local_frame_goto_control.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 <eigen3/Eigen/Eigen>
36 #include <functional>
37 #include <memory>
38 #include <variant>
39 
40 #include "../../auterion.hpp"
41 
42 namespace auterion {
43 namespace multicopter {
54  public:
55  float max_horizontal_speed_m_s = 5.f;
56  float max_vertical_speed_m_s = 2.f;
57  float max_heading_rate_rad_s = 1.f;
58 
59  GotoControlLimits() = default;
60 
61  GotoControlLimits(const float max_horizontal_speed_m_s_, const float max_vertical_speed_m_s_,
62  const float max_heading_rate_rad_s_)
63  : max_horizontal_speed_m_s(max_horizontal_speed_m_s_),
64  max_vertical_speed_m_s(max_vertical_speed_m_s_),
65  max_heading_rate_rad_s(max_heading_rate_rad_s_) {}
66 
67  GotoControlLimits& withMaxHorizontalSpeed(const float max_horizontal_speed_m_s_) {
68  this->max_horizontal_speed_m_s = max_horizontal_speed_m_s_;
69  return *this;
70  }
71 
72  GotoControlLimits& withMaxVerticalSpeed(const float max_vertical_speed_m_s_) {
73  this->max_vertical_speed_m_s = max_vertical_speed_m_s_;
74  return *this;
75  }
76 
77  GotoControlLimits& withMaxHeadingRate(const float max_heading_rate_rad_s_) {
78  this->max_heading_rate_rad_s = max_heading_rate_rad_s_;
79  return *this;
80  }
81 };
82 
89  private:
90  Eigen::Vector3f _local_position_enu = {NAN, NAN, NAN};
91  float _heading_rad = NAN;
92  GotoControlLimits _limits{NAN, NAN, NAN};
93 
94  public:
98  class Config {
99  public:
100  Config(const GotoControlLimits& limits = GotoControlLimits()) : _default_limits(limits) {}
101 
102  inline GotoControlLimits getDefaultLimits() const { return _default_limits; }
103 
104  private:
105  GotoControlLimits _default_limits;
106  };
107 
108  LocalFrameGotoSetpoint() = default;
109 
110  LocalFrameGotoSetpoint(const Eigen::Vector3f& local_position_enu, const float heading_rad = NAN)
111  : _local_position_enu(local_position_enu), _heading_rad(heading_rad) {}
112 
113  LocalFrameGotoSetpoint(const Eigen::Vector2f& local_position_en, const float heading_rad = NAN)
114  : _local_position_enu({local_position_en.x(), local_position_en.y(), NAN}),
115  _heading_rad(heading_rad) {}
116 
117  inline Eigen::Vector3f getPosition() const { return _local_position_enu; }
118 
119  inline float getHeading() const { return _heading_rad; }
120 
121  inline GotoControlLimits getLimits() const { return _limits; }
122 
123  LocalFrameGotoSetpoint& withPosition(const Eigen::Vector3f& local_position_enu) {
124  _local_position_enu = local_position_enu;
125  return *this;
126  }
127 
128  LocalFrameGotoSetpoint& withPosition(const Eigen::Vector2f& local_position_en) {
129  _local_position_enu.x() = local_position_en.x();
130  _local_position_enu.y() = local_position_en.y();
131  return *this;
132  }
133 
134  LocalFrameGotoSetpoint& withHeading(const float heading_rad) {
135  _heading_rad = heading_rad;
136  return *this;
137  }
138 
139  LocalFrameGotoSetpoint& withAltitude(const float z) {
140  _local_position_enu.z() = z;
141  return *this;
142  }
143 
144  LocalFrameGotoSetpoint& withSpeedControlLimit(const GotoControlLimits& limits) {
145  _limits = limits;
146  return *this;
147  }
148 
149  LocalFrameGotoSetpoint& withMaxHorizontalSpeed(const float max_horizontal_speed_m_s_) {
150  _limits.withMaxHorizontalSpeed(max_horizontal_speed_m_s_);
151  return *this;
152  }
153 
154  LocalFrameGotoSetpoint& withMaxVerticalSpeed(const float max_vertical_speed_m_s_) {
155  _limits.withMaxVerticalSpeed(max_vertical_speed_m_s_);
156  return *this;
157  }
158 
159  LocalFrameGotoSetpoint& withMaxHeadingRate(const float max_heading_rate_rad_s_) {
160  _limits.withMaxHeadingRate(max_heading_rate_rad_s_);
161  return *this;
162  }
163 };
164 
166 } // namespace multicopter
167 } // namespace auterion
Sets controller's default speed limits for local goto setpoint.
Definition: local_frame_goto_control.hpp:98
Represents a setpoint for controlling the local frame position and heading.
Definition: local_frame_goto_control.hpp:88
Represents the desired speed limit of the vehicle when controlled with a goto setpoint.
Definition: local_frame_goto_control.hpp:53