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 <rclcpp/rclcpp.hpp>
36 
37 namespace auterion {
42 class ParameterManager;
43 
47 class SDK {
48  public:
49  SDK(int argc, char** argv, const std::string& node_name);
50  ~SDK();
51 
58  _skip_flight_controller_connection_check = skip;
59  }
60 
61  void run();
62 
63  rclcpp::Node::SharedPtr defaultRosHandle() const { return _default_ros_node; }
64 
65  rclcpp::Time now() const { return _default_ros_node->now(); }
66 
67  void addNode(rclcpp::Node::SharedPtr node) { _executor->add_node(node); }
68  void removeNode(rclcpp::Node::SharedPtr node) { _executor->remove_node(node); }
69  const rclcpp::executors::SingleThreadedExecutor::UniquePtr& executor() const {
70  return _executor;
71  }
72 
83  template <typename T>
84  T getParameter(const std::string& name,
85  std::function<void(const T&)> on_change_callback = nullptr) {
86  static_assert(std::is_same<T, bool>::value || std::is_same<T, int64_t>::value ||
87  std::is_same<T, int>::value || std::is_same<T, float>::value ||
88  std::is_same<T, double>::value || std::is_same<T, std::string>::value ||
89  std::is_same<T, std::vector<bool>>::value ||
90  std::is_same<T, std::vector<int64_t>>::value ||
91  std::is_same<T, std::vector<int>>::value ||
92  std::is_same<T, std::vector<float>>::value ||
93  std::is_same<T, std::vector<double>>::value ||
94  std::is_same<T, std::vector<std::string>>::value,
95  "Unsupported parameter data type");
96  }
97 
98  private:
99  rclcpp::Node::SharedPtr _default_ros_node;
100  rclcpp::executors::SingleThreadedExecutor::UniquePtr _executor;
101  bool _skip_flight_controller_connection_check{false};
102  std::unique_ptr<ParameterManager> _parameter_manager;
103 };
104 
105 template <>
106 bool SDK::getParameter(const std::string& name,
107  std::function<void(const bool&)> on_change_callback);
108 template <>
109 int64_t SDK::getParameter(const std::string& name,
110  std::function<void(const int64_t&)> on_change_callback);
111 template <>
112 int SDK::getParameter(const std::string& name, std::function<void(const int&)> on_change_callback);
113 template <>
114 float SDK::getParameter(const std::string& name,
115  std::function<void(const float&)> on_change_callback);
116 template <>
117 double SDK::getParameter(const std::string& name,
118  std::function<void(const double&)> on_change_callback);
119 template <>
120 std::string SDK::getParameter(const std::string& name,
121  std::function<void(const std::string&)> on_change_callback);
122 template <>
123 std::vector<bool> SDK::getParameter(
124  const std::string& name, std::function<void(const std::vector<bool>&)> on_change_callback);
125 template <>
126 std::vector<int64_t> SDK::getParameter(
127  const std::string& name, std::function<void(const std::vector<int64_t>&)> on_change_callback);
128 template <>
129 std::vector<int> SDK::getParameter(const std::string& name,
130  std::function<void(const std::vector<int>&)> on_change_callback);
131 template <>
132 std::vector<float> SDK::getParameter(
133  const std::string& name, std::function<void(const std::vector<float>&)> on_change_callback);
134 template <>
135 std::vector<double> SDK::getParameter(
136  const std::string& name, std::function<void(const std::vector<double>&)> on_change_callback);
137 template <>
138 std::vector<std::string> SDK::getParameter(
139  const std::string& name,
140  std::function<void(const std::vector<std::string>&)> on_change_callback);
141 
143 } // namespace auterion
SDK execution class. All callbacks are called on the same thread.
Definition: auterion.hpp:47
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:84
void setSkipFlightControllerConnectionCheck(bool skip)
Definition: auterion.hpp:57