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

Use ignoreLocalMessages in the bridge #559

Merged
merged 5 commits into from
Jun 7, 2024
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
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