Skip to content

Commit

Permalink
Use ignoreLocalMessages in the bridge (#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 Jun 7, 2024
1 parent cadae1c commit 4c64bbe
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions ros_gz_bridge/src/factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <string>

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

// include ROS 2
#include <rclcpp/rclcpp.hpp>
Expand Down Expand Up @@ -105,17 +106,16 @@ class Factory : public FactoryInterface
size_t /*queue_size*/,
rclcpp::PublisherBase::SharedPtr ros_pub)
{
std::function<void(const GZ_T &,
const gz::transport::MessageInfo &)> subCb =
[this, ros_pub](const GZ_T & _msg, const gz::transport::MessageInfo & _info)
std::function<void(const GZ_T &)> subCb =
[this, ros_pub](const GZ_T & _msg)
{
// Ignore messages that are published from this bridge.
if (!_info.IntraProcess()) {
this->gz_callback(_msg, ros_pub);
}
this->gz_callback(_msg, ros_pub);
};

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 4c64bbe

Please sign in to comment.