-
Notifications
You must be signed in to change notification settings - Fork 782
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
ros2: Only subscribe to /gazebo/performance_metrics when necessary #1205
ros2: Only subscribe to /gazebo/performance_metrics when necessary #1205
Conversation
This reduces duplication of the version checking logic for performance metrics in gazebo. Signed-off-by: Steve Peters <scpeters@openrobotics.org>
We are currently subscribing to the /gazebo/performance_metrics topic even if there are no subscribers to the ROS topic forwarding this data. This changes gazebo_ros_init to only subscribe to the gazebo topic if there are any subscribers to the corresponding ROS topic. While advertiser callbacks are used in ROS 1 but are not yet in ROS2, here we use polling in the GazeboRosInitPrivate::PublishSimTime callback to check for subscribers since it is called for each Gazebo time step. This also helps workaround the deadlock documented in ros-simulation#1175 and gazebosim/gazebo-classic#2902. Signed-off-by: Steve Peters <scpeters@openrobotics.org>
gazebo_ros/src/gazebo_ros_init.cpp
Outdated
@@ -33,6 +33,13 @@ | |||
#include <memory> | |||
#include <string> | |||
|
|||
#ifndef GAZEBO_ROS_HAS_PERFORMANCE_METRICS | |||
#if (GAZEBO_MAJOR_VERSION == 11 && GAZEBO_MINOR_VERSION > 1) || \ | |||
(GAZEBO_MAJOR_VERSION == 9 && GAZEBO_MINOR_VERSION > 14) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uncrustify doesn't like my indentation here
--- src/gazebo_ros_init.cpp
+++ src/gazebo_ros_init.cpp.uncrustify
@@ -38 +38 @@
- (GAZEBO_MAJOR_VERSION == 9 && GAZEBO_MINOR_VERSION > 14)
+ (GAZEBO_MAJOR_VERSION == 9 && GAZEBO_MINOR_VERSION > 14)
I think it looks better like this, but it's not a big deal. Is it allowed to tell uncrustify to ignore this line, or should I just make the change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For indentation, I think you can use
// *INDENT-OFF*
#if (GAZEBO_MAJOR_VERSION == 11 && GAZEBO_MINOR_VERSION > 1) || \
(GAZEBO_MAJOR_VERSION == 9 && GAZEBO_MINOR_VERSION > 14)
// *INDENT-ON*
But subjectively, I would just do what uncrustify says to avoid the extra "INDENT" directives. I don't feel strongly one way or the other.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I ended up going with 3a875ea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I vote for the uncrustify version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with green CI
Signed-off-by: Steve Peters <scpeters@openrobotics.org>
just one test failure that looks like the flaky test in #1169 I'll go ahead and merge |
…1205) We are currently subscribing to the /gazebo/performance_metrics topic even if there are no subscribers to the ROS topic forwarding this data. This changes gazebo_ros_init to only subscribe to the gazebo topic if there are any subscribers to the corresponding ROS topic. While advertiser callbacks are used in ROS 1 but are not yet in ROS2, here we use polling in the GazeboRosInitPrivate::PublishSimTime callback to check for subscribers since it is called for each Gazebo time step. This also helps workaround the deadlock documented in #1175 and gazebosim/gazebo-classic#2902. This also adds a macro to reduce duplication of the version checking logic. Signed-off-by: Steve Peters <scpeters@openrobotics.org>
…1205) We are currently subscribing to the /gazebo/performance_metrics topic even if there are no subscribers to the ROS topic forwarding this data. This changes gazebo_ros_init to only subscribe to the gazebo topic if there are any subscribers to the corresponding ROS topic. While advertiser callbacks are used in ROS 1 but are not yet in ROS2, here we use polling in the GazeboRosInitPrivate::PublishSimTime callback to check for subscribers since it is called for each Gazebo time step. This also helps workaround the deadlock documented in #1175 and gazebosim/gazebo-classic#2902. This also adds a macro to reduce duplication of the version checking logic. Signed-off-by: Steve Peters <scpeters@openrobotics.org>
This is similar to #1202 and #1203 targeting
ros2
with polling instead of advertiser callbacks.We are currently subscribing to the
/gazebo/performance_metrics
topic even if there are no subscribers to the ROS topic forwarding this data. This changesgazebo_ros_init
to only subscribe to the gazebo topic if there are any subscribers to the corresponding ROS topic. While advertiser callbacks are used in ROS 1 but are not yet in ROS2, here we use polling in theGazeboRosInitPrivate::PublishSimTime
callback to check for subscribers since it is called for each Gazebotime step.
This also helps workaround the deadlock documented in #1175 and gazebosim/gazebo-classic#2902.
I've also added the
GAZEBO_ROS_HAS_PERFORMANCE_METRICS
macro to de-duplicate the gazebo version checking logic.