36#include <auterion_sdk/exception/exception.hpp>
38#include <rclcpp/rclcpp.hpp>
49class ParameterManager;
65 skip_flight_controller_connection_check = skip;
83 skip_message_compatibility_check = skip;
99 if (timeout.count() <= 0) {
101 "flight_controller_connection_timeout must be positive (got: " +
102 std::to_string(timeout.count()) +
"s)."};
104 flight_controller_connection_timeout = timeout;
108 void validate()
const {
109 if (skip_flight_controller_connection_check && !skip_message_compatibility_check) {
111 "Cannot check message compatibility if connection check is skipped. "
112 "Enable flight controller connection check, or disable message compatibility "
117 bool skip_flight_controller_connection_check{
false};
118 bool skip_message_compatibility_check{
true};
119 std::chrono::seconds flight_controller_connection_timeout{15};
135 SDK(
int argc,
char** argv,
const std::string& node_name);
139 [[deprecated(
"Use run(RunOptions) instead, this method will be removed in a future release.")]]
147 _skip_flight_controller_connection_check = skip;
152 rclcpp::Node::SharedPtr defaultRosHandle()
const {
return _default_ros_node; }
161 const std::thread::id executor_thread = _executor_thread.load();
162 return executor_thread != std::thread::id() &&
163 executor_thread != std::this_thread::get_id();
166 rclcpp::Time now()
const {
return _default_ros_node->now(); }
168 void addNode(rclcpp::Node::SharedPtr node) { _executor->add_node(node); }
169 void removeNode(rclcpp::Node::SharedPtr node) { _executor->remove_node(node); }
171 using ShutdownCallbackHandle = rclcpp::PreShutdownCallbackHandle;
183 void removeShutdownCallback(
const ShutdownCallbackHandle& handle);
191 const rclcpp::executors::SingleThreadedExecutor::UniquePtr& executor()
const {
196 template <
typename T>
197 static constexpr void verify_param() {
198 static_assert(std::is_same<T, bool>::value || std::is_same<T, int64_t>::value ||
199 std::is_same<T, int>::value || std::is_same<T, float>::value ||
200 std::is_same<T, double>::value || std::is_same<T, std::string>::value ||
201 std::is_same<T, std::vector<bool>>::value ||
202 std::is_same<T, std::vector<int64_t>>::value ||
203 std::is_same<T, std::vector<int>>::value ||
204 std::is_same<T, std::vector<float>>::value ||
205 std::is_same<T, std::vector<double>>::value ||
206 std::is_same<T, std::vector<std::string>>::value,
207 "Unsupported parameter data type");
221 template <
typename T>
223 std::function<
void(
const T&)> on_change_callback =
nullptr) {
237 template <
typename T>
240 setParameterValue(name, value, ParameterScope::App);
251 template <
typename T>
254 setParameterValue(full_name, value, ParameterScope::System);
258 using ParameterValue =
259 std::variant<bool, int64_t, int, float, double, std::string, std::vector<bool>,
260 std::vector<int64_t>, std::vector<int>, std::vector<float>,
261 std::vector<double>, std::vector<std::string>>;
262 enum class ParameterScope { App, System };
263 void setParameterValue(
const std::string& name,
const ParameterValue& value,
264 ParameterScope scope);
266 rclcpp::Node::SharedPtr _default_ros_node;
267 std::atomic<std::thread::id> _executor_thread{};
268 rclcpp::executors::SingleThreadedExecutor::UniquePtr _executor;
269 bool _skip_flight_controller_connection_check{
false};
270 std::unique_ptr<ParameterManager> _parameter_manager;
275 std::function<
void(
const bool&)> on_change_callback);
279 std::function<
void(
const int64_t&)> on_change_callback);
282int SDK::getParameter(
const std::string& name, std::function<
void(
const int&)> on_change_callback);
286 std::function<
void(
const float&)> on_change_callback);
290 std::function<
void(
const double&)> on_change_callback);
294 std::function<
void(
const std::string&)> on_change_callback);
298 const std::string& name, std::function<
void(
const std::vector<bool>&)> on_change_callback);
302 const std::string& name, std::function<
void(
const std::vector<int64_t>&)> on_change_callback);
306 std::function<
void(
const std::vector<int>&)> on_change_callback);
310 const std::string& name, std::function<
void(
const std::vector<float>&)> on_change_callback);
314 const std::string& name, std::function<
void(
const std::vector<double>&)> on_change_callback);
318 const std::string& name,
319 std::function<
void(
const std::vector<std::string>&)> on_change_callback);
Exception thrown for invalid arguments.
Definition exception.hpp:82
SDK execution class. All callbacks are called on the same thread.
Definition auterion.hpp:133
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:222
void requestShutdown(const std::string &reason)
Shut the app down: the shutdown callbacks run, and run() returns.
ShutdownCallbackHandle addShutdownCallback(std::function< void()> callback)
Register a callback for the app's shutdown (a signal, or requestShutdown())
void setParameter(const std::string &name, const T &value)
Set a parameter.
Definition auterion.hpp:238
bool canWaitForData() const
Whether the calling thread can wait for data the SDK receives.
Definition auterion.hpp:160
void setSkipFlightControllerConnectionCheck(bool skip)
Definition auterion.hpp:146
void setSystemParameter(const std::string &full_name, const T &value)
Set a parameter of another app or service.
Definition auterion.hpp:252
Options for SDK run() method.
Definition auterion.hpp:56
RunOptions & withSkipFlightControllerConnectionCheck(bool skip)
Skip the check for flight controller connection.
Definition auterion.hpp:64
RunOptions & withFlightControllerConnectionTimeout(std::chrono::seconds timeout)
Set the timeout for the flight controller connection check.
Definition auterion.hpp:98
RunOptions & withSkipMessageCompatibilityCheck(bool skip)
Skip the check for message compatibility.
Definition auterion.hpp:82