Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ros2] Fix message duplication caused by bidirectional bridge (not for all rmw implementations) #146

Merged
merged 1 commit into from
Apr 5, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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