Skip to content

feat: Added lazy subscribe support for GZ image bridge#851

Open
TannerGilbert wants to merge 1 commit intogazebosim:ros2from
TannerGilbert:feat/lazy_subscribe_support_for_gz_image
Open

feat: Added lazy subscribe support for GZ image bridge#851
TannerGilbert wants to merge 1 commit intogazebosim:ros2from
TannerGilbert:feat/lazy_subscribe_support_for_gz_image

Conversation

@TannerGilbert
Copy link

🎉 New feature

Closes #752

Summary

Adds a lazy option to the ros_gz_image bridge similar to what already exists for the ros_gz_bridge. This can be quite important as cameras usually take a lot of resources that shouldn't be used up if there is no active subscriber.

Example command:

ros2 run ros_gz_image image_bridge /camera --ros-args -p lazy:=true

Example output:
No ROS subscribers => bridge doesn't subscribe to camera

Publishers [Address, Message Type]:
  tcp://172.17.0.1:40959, gz.msgs.Image
No subscribers on topic [/world/default/model/x500_lidar_and_camera_0/link/navigation_camera_link/sensor/navigation_camera/image]

ROS subscriber => bridge subcribes to camera:

Publishers [Address, Message Type]:
  tcp://172.17.0.1:40959, gz.msgs.Image
Subscribers [Address, Message Type]:
  tcp://172.17.0.1:37671, gz.msgs.Image

Test it

Create a world with a camera inside it. Then run:

ros2 run ros_gz_image image_bridge /camera --ros-args -p lazy:=true

If no subscriber exists gz topic -i -t /camera should return no subscriber. After subscribing with for example ros2 topic hz -w 10 /camera when reruning gz topic -i -t /camera there should be a subscriber visible.

Note: I tested on ROS2 Humble and therefore would already have a backport for this version.

Checklist

  • Signed all commits for DCO
  • Added a screen capture or video to the PR description that demonstrates the feature
  • Added tests
  • Added example and/or tutorial
  • Updated documentation (as needed)
  • Updated migration guide (as needed)
  • Consider updating Python bindings (if the library has them)
  • codecheck passed (See contributing)
  • All tests passed (See test coverage)
  • Updated Bazel files (if adding new files). Created an issue otherwise.
  • While waiting for a review on your PR, please help review another open pull request to support the maintainers
  • Was GenAI used to generate this PR? If so, make sure to add "Generated-by" to your commits. (See this policy for more info.)

Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining Signed-off-by and Generated-by messages.

Signed-off-by: Tanner, Gilbert <gilbertta@edu.aau.at>
Copy link
Collaborator

@ahcorde ahcorde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update documentation with the new parameters

std::string topic_;

/// \brief ROS node
std::shared_ptr<rclcpp::Node> node_;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't need to keep this, it's only used in the constructor


/// \brief Manage Gazebo subscription lifecycle based on ROS subscriber count.
/// Only active when lazy mode is enabled.
void Spin()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use here CheckSubscribers, the name is quite similar to rclcpp::spin which might generate some confusion

auto node_ = rclcpp::Node::make_shared("ros_gz_image");
node_->declare_parameter("qos", "default");
node_->declare_parameter("lazy", false);
node_->declare_parameter("subscription_heartbeat", 1000);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe 1 seconds by default is to much, 100ms?

@github-project-automation github-project-automation bot moved this from Inbox to In review in Core development Mar 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In review

Development

Successfully merging this pull request may close these issues.

ros_gz_image: Support for lazy subscribe

2 participants