From 4a9b47b936a4d68286c49b471ce58594125ea777 Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Wed, 24 Jan 2024 11:21:19 +0100 Subject: [PATCH] [compat] auto spin in ROS2 --- include/ontologenius/compat/ros.h | 3 ++- src/compat/ros.cpp | 8 +++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/include/ontologenius/compat/ros.h b/include/ontologenius/compat/ros.h index ed2003b3..535db53e 100644 --- a/include/ontologenius/compat/ros.h +++ b/include/ontologenius/compat/ros.h @@ -189,7 +189,7 @@ class Node friend class Service; template - friend class Client; + friend class Client; Node(Node& other) = delete; Node(Node&& other) = delete; @@ -215,6 +215,7 @@ class Node ros::CallbackQueue callback_queue_; #elif ONTO_ROS_VERSION == 2 rclcpp::Node::SharedPtr handle_; + std::thread ros_thread_; #endif bool running_; diff --git a/src/compat/ros.cpp b/src/compat/ros.cpp index 4b13d824..b5e9a45f 100644 --- a/src/compat/ros.cpp +++ b/src/compat/ros.cpp @@ -2,8 +2,7 @@ namespace ontologenius::compat::onto_ros { - -std::string node_name__; +std::string node_name__ = "OntoRos"; Node& Node::get() { @@ -45,7 +44,7 @@ void Node::spin() #if ONTO_ROS_VERSION == 1 ros::spin(); #elif ONTO_ROS_VERSION == 2 - rclcpp::spin(handle_); + //rclcpp::spin(handle_); #endif } @@ -65,6 +64,9 @@ Node::Node(const std::string& node_name) : name_(node_name), running_(true) { // todo: should we put something here? +#if ONTO_ROS_VERSION == 2 + ros_thread_ = std::thread([this](){rclcpp::spin(handle_);}); +#endif } } \ No newline at end of file