Skip to content

Commit

Permalink
Use ignoreLocalMessages in the bridge (gazebosim#559)
Browse files Browse the repository at this point in the history
* Ignore local messages

Signed-off-by: Carlos Agüero <[email protected]>
  • Loading branch information
caguero authored and Amronos committed Sep 18, 2024
1 parent 17a1469 commit bee1ee5
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions ros_gz_bridge/src/factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <type_traits>

#include <gz/transport/Node.hh>
#include <gz/transport/SubscribeOptions.hh>

// include ROS 2
#include <rclcpp/rclcpp.hpp>
Expand Down Expand Up @@ -118,18 +119,16 @@ class Factory : public FactoryInterface
rclcpp::PublisherBase::SharedPtr ros_pub,
bool override_timestamps_with_wall_time)
{
std::function<void(const GZ_T &,
const gz::transport::MessageInfo &)> subCb =
[this, ros_pub, override_timestamps_with_wall_time](const GZ_T & _msg,
const gz::transport::MessageInfo & _info)
std::function<void(const GZ_T &)> 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:
Expand Down

0 comments on commit bee1ee5

Please sign in to comment.