From bee1ee5033168082b51a557f8820d30beef8480f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Ag=C3=BCero?= Date: Fri, 7 Jun 2024 15:07:15 +0200 Subject: [PATCH] Use `ignoreLocalMessages` in the bridge (#559) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Ignore local messages Signed-off-by: Carlos Agüero --- ros_gz_bridge/src/factory.hpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/ros_gz_bridge/src/factory.hpp b/ros_gz_bridge/src/factory.hpp index 83e48351..9f32a7a7 100644 --- a/ros_gz_bridge/src/factory.hpp +++ b/ros_gz_bridge/src/factory.hpp @@ -22,6 +22,7 @@ #include #include +#include // include ROS 2 #include @@ -118,18 +119,16 @@ class Factory : public FactoryInterface rclcpp::PublisherBase::SharedPtr ros_pub, bool override_timestamps_with_wall_time) { - std::function subCb = - [this, ros_pub, override_timestamps_with_wall_time](const GZ_T & _msg, - const gz::transport::MessageInfo & _info) + std::function subCb = + [this, ros_pub, override_timestamps_with_wall_time](const GZ_T & _msg) { - // Ignore messages that are published from this bridge. - if (!_info.IntraProcess()) { - this->gz_callback(_msg, ros_pub, override_timestamps_with_wall_time); - } + this->gz_callback(_msg, ros_pub, override_timestamps_with_wall_time); }; - node->Subscribe(topic_name, subCb); + // Ignore messages that are published from this bridge. + gz::transport::SubscribeOptions opts; + opts.SetIgnoreLocalMessages(true); + node->Subscribe(topic_name, subCb, opts); } protected: