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 QoS profile of existing publishers (if available) when creating new publishers #184

Merged
merged 1 commit into from
Mar 8, 2023
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
10 changes: 9 additions & 1 deletion ros2_foxglove_bridge/src/ros2_foxglove_bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,15 @@ class FoxgloveBridge : public rclcpp::Node {
// Create a new topic advertisement
const auto& topicName = advertisement.topic;
const auto& topicType = advertisement.schemaName;
rclcpp::QoS qos{rclcpp::QoSInitialization::from_rmw(rmw_qos_profile_default)};

// Lookup if there are other publishers for that topic. If that's the case, we use a matching
// QoS profile.
const auto otherPublishers = get_publishers_info_by_topic(topicName);
const rclcpp::QoS qos =
otherPublishers.empty()
? rclcpp::QoS(rclcpp::QoSInitialization::from_rmw(rmw_qos_profile_default))
: otherPublishers.front().qos_profile();

rclcpp::PublisherOptions publisherOptions{};
publisherOptions.callback_group = _clientPublishCallbackGroup;
auto publisher = this->create_generic_publisher(topicName, topicType, qos, publisherOptions);
Expand Down