Skip to content

Commit

Permalink
Ignore local publications for ROS 2 subscriber (#146)
Browse files Browse the repository at this point in the history
- Note: Does not work with all rmw implementations (e.g.: FastRTPS)

Signed-off-by: Andrej Orsula <orsula.andrej@gmail.com>
  • Loading branch information
AndrejOrsula authored Apr 5, 2021
1 parent 9ddfa24 commit 889de82
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions ros_ign_bridge/src/factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

// include ROS 2
#include <rclcpp/rclcpp.hpp>
#include <rclcpp/subscription_options.hpp>

#include <functional>
#include <memory>
Expand Down Expand Up @@ -71,9 +72,12 @@ class Factory : public FactoryInterface
std::placeholders::_1, ign_pub,
ros_type_name_, ign_type_name_,
ros_node);
// Ignore messages that are published from this bridge.
auto options = rclcpp::SubscriptionOptions();
options.ignore_local_publications = true;
std::shared_ptr<rclcpp::Subscription<ROS_T>> subscription =
ros_node->create_subscription<ROS_T>(
topic_name, rclcpp::QoS(rclcpp::KeepLast(queue_size)), fn);
topic_name, rclcpp::QoS(rclcpp::KeepLast(queue_size)), fn, options);
return subscription;
}

Expand Down Expand Up @@ -112,7 +116,7 @@ class Factory : public FactoryInterface
ign_pub.Publish(ign_msg);
RCLCPP_INFO_ONCE(
ros_node->get_logger(),
"Passing message from ROS %s to Ignition %s (showing msg only once per type",
"Passing message from ROS %s to Ignition %s (showing msg only once per type)",
ros_type_name.c_str(), ign_type_name.c_str());
}

Expand Down

0 comments on commit 889de82

Please sign in to comment.