Auterion App SDK
Auterion SDK is a library that can be used by AuterionOS apps to communicate with the system.
auterion.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 <auterion_sdk/exception/exception.hpp>
36 #include <rclcpp/rclcpp.hpp>
37 
38 namespace auterion {
43 class ParameterManager;
44 
50 struct RunOptions {
59  skip_flight_controller_connection_check = skip;
60  return *this;
61  }
62 
77  skip_message_compatibility_check = skip;
78  return *this;
79  }
80 
81  void validate() const {
82  if (skip_flight_controller_connection_check && !skip_message_compatibility_check) {
84  "Cannot check message compatibility if connection check is skipped. "
85  "Enable flight controller connection check, or disable message compatibility "
86  "check.");
87  }
88  }
89 
90  bool skip_flight_controller_connection_check{false};
91  bool skip_message_compatibility_check{true};
92 };
93 
97 class SDK {
98  public:
99  SDK(int argc, char** argv, const std::string& node_name);
100  ~SDK();
101 
102  [[deprecated("Use run(RunOptions) instead, this method will be removed in a future release.")]]
108  void
110  _skip_flight_controller_connection_check = skip;
111  }
112 
113  void run(RunOptions options = RunOptions());
114 
115  rclcpp::Node::SharedPtr defaultRosHandle() const { return _default_ros_node; }
116 
117  rclcpp::Time now() const { return _default_ros_node->now(); }
118 
119  void addNode(rclcpp::Node::SharedPtr node) { _executor->add_node(node); }
120  void removeNode(rclcpp::Node::SharedPtr node) { _executor->remove_node(node); }
121  const rclcpp::executors::SingleThreadedExecutor::UniquePtr& executor() const {
122  return _executor;
123  }
124 
135  template <typename T>
136  T getParameter(const std::string& name,
137  std::function<void(const T&)> on_change_callback = nullptr) {
138  static_assert(std::is_same<T, bool>::value || std::is_same<T, int64_t>::value ||
139  std::is_same<T, int>::value || std::is_same<T, float>::value ||
140  std::is_same<T, double>::value || std::is_same<T, std::string>::value ||
141  std::is_same<T, std::vector<bool>>::value ||
142  std::is_same<T, std::vector<int64_t>>::value ||
143  std::is_same<T, std::vector<int>>::value ||
144  std::is_same<T, std::vector<float>>::value ||
145  std::is_same<T, std::vector<double>>::value ||
146  std::is_same<T, std::vector<std::string>>::value,
147  "Unsupported parameter data type");
148  }
149 
150  private:
151  rclcpp::Node::SharedPtr _default_ros_node;
152  rclcpp::executors::SingleThreadedExecutor::UniquePtr _executor;
153  bool _skip_flight_controller_connection_check{false}; // deprecating, use RunOptions
154  std::unique_ptr<ParameterManager> _parameter_manager;
155 };
156 
157 template <>
158 bool SDK::getParameter(const std::string& name,
159  std::function<void(const bool&)> on_change_callback);
160 template <>
161 int64_t SDK::getParameter(const std::string& name,
162  std::function<void(const int64_t&)> on_change_callback);
163 template <>
164 int SDK::getParameter(const std::string& name, std::function<void(const int&)> on_change_callback);
165 template <>
166 float SDK::getParameter(const std::string& name,
167  std::function<void(const float&)> on_change_callback);
168 template <>
169 double SDK::getParameter(const std::string& name,
170  std::function<void(const double&)> on_change_callback);
171 template <>
172 std::string SDK::getParameter(const std::string& name,
173  std::function<void(const std::string&)> on_change_callback);
174 template <>
175 std::vector<bool> SDK::getParameter(
176  const std::string& name, std::function<void(const std::vector<bool>&)> on_change_callback);
177 template <>
178 std::vector<int64_t> SDK::getParameter(
179  const std::string& name, std::function<void(const std::vector<int64_t>&)> on_change_callback);
180 template <>
181 std::vector<int> SDK::getParameter(const std::string& name,
182  std::function<void(const std::vector<int>&)> on_change_callback);
183 template <>
184 std::vector<float> SDK::getParameter(
185  const std::string& name, std::function<void(const std::vector<float>&)> on_change_callback);
186 template <>
187 std::vector<double> SDK::getParameter(
188  const std::string& name, std::function<void(const std::vector<double>&)> on_change_callback);
189 template <>
190 std::vector<std::string> SDK::getParameter(
191  const std::string& name,
192  std::function<void(const std::vector<std::string>&)> on_change_callback);
193 
195 } // namespace auterion
Exception thrown for invalid arguments.
Definition: exception.hpp:82
SDK execution class. All callbacks are called on the same thread.
Definition: auterion.hpp:97
T getParameter(const std::string &name, std::function< void(const T &)> on_change_callback=nullptr)
Get a parameter value and optionally register a callback for changes.
Definition: auterion.hpp:136
void setSkipFlightControllerConnectionCheck(bool skip)
Definition: auterion.hpp:109
Options for SDK run() method.
Definition: auterion.hpp:50
RunOptions & withSkipMessageCompatibilityCheck(bool skip)
Skip the check for message compatibility.
Definition: auterion.hpp:76
RunOptions & withSkipFlightControllerConnectionCheck(bool skip)
Skip the check for flight controller connection.
Definition: auterion.hpp:58