Skip to content

Commit

Permalink
[compat] auto spin in ROS2
Browse files Browse the repository at this point in the history
  • Loading branch information
sarthou committed Jan 24, 2024
1 parent 44633c0 commit 4a9b47b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
3 changes: 2 additions & 1 deletion include/ontologenius/compat/ros.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class Node
friend class Service;

template <typename T>
friend class Client;
friend class Client;

Node(Node& other) = delete;
Node(Node&& other) = delete;
Expand All @@ -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_;
Expand Down
8 changes: 5 additions & 3 deletions src/compat/ros.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

namespace ontologenius::compat::onto_ros
{

std::string node_name__;
std::string node_name__ = "OntoRos";

Node& Node::get()
{
Expand Down Expand Up @@ -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
}

Expand All @@ -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
}

}

0 comments on commit 4a9b47b

Please sign in to comment.