ros_gz icon indicating copy to clipboard operation
ros_gz copied to clipboard

Support for `use_sim_time` = `false`

Open reinzor opened this issue 1 year ago • 11 comments

What are your thought about running the bridge with use_sim_time false? Would you be open for a PR like this: https://github.com/gazebosim/ros_gz/pull/545

Please give me your thoughts.

Thanks!

reinzor avatar May 07 '24 12:05 reinzor

Could you elaborate on the purpose for this? ros_gz is meant to be used with Gazebo, so I would think use_sim_time would always be true, but maybe there are other use cases?

azeey avatar May 07 '24 17:05 azeey

Sure, we have two reasons for this:

  • When running a gazebo instance in a hardware in the loop set-up, some other nodes in the ros2 graph require real timestamps in order to function
  • Subscribing to the /clock topic for each running node in our ros2 set-up, introduces a lot of CPU load, especially for the python processes. This is more related to the performance of ros2 but in some cases and on some platforms, we can only run proper simulations if we set use_sim_time to false.

reinzor avatar May 07 '24 18:05 reinzor

Any thoughts @azeey ?

reinzor avatar May 13 '24 17:05 reinzor

Those seem like good reasons to me. My only concern is that we don't break any existing users since use_sim_time is assumed to be true for ros_gz by default. Is there a way we can ensure that the parameter is true if not set explicitly by the user?

azeey avatar May 22 '24 19:05 azeey

Thanks for your reply @azeey , I don't think we can and I don't think we should modify the default node behavior:

https://github.com/ros2/rclcpp/blob/343b29b617b163ad72b9fe3f6441dd4ed3d3af09/rclcpp/src/rclcpp/time_source.cpp#L257

Here the parameter is set to false by default.

This line:

https://github.com/nobleo/ros_gz/blob/714660e86e9b4e7ff60c1ce46bbc43a54d8a6bd3/ros_gz_bridge/src/bridge_handle_gz_to_ros.cpp#L74

will simply ask the node whether the simulation time is active.

reinzor avatar May 23 '24 06:05 reinzor

Well, that would be a blocker then since it will likely break existing users. What about using additional parameter or environment variable to enable checking use_sim_time?

azeey avatar May 23 '24 22:05 azeey

What about adding indeed an additional parameter, e.g. use_wall_time that defaults to false and log a warning when it is conflicting with node->ros_time_is_active()? In order to supress this warning, the user should align these two parameters, either:

  • use_wall_time=true, use_sim_time=false
  • use_wall_time=false, use_sim_time=true

And in the implementation, we use the value of the use_wall_time_parameter. What do you think?

reinzor avatar May 24 '24 05:05 reinzor

Or make this new behavior default as per ROS2 Jazzy. As breaking changes are typically allowed between distros.

Timple avatar May 24 '24 13:05 Timple

ping @azeey

reinzor avatar Jun 05 '24 08:06 reinzor

The job of the bridge is to convert messages from Gazebo to ROS. It shouldn't really have its own concept of time. The timestamps are provided by Gazebo. Overwriting this timestamp with some other value should be an opt-in, so I would not be in favor of changing the current behavior. I would support adding a use_wall_time parameter, better yet, a override_timestamps_with_wall_time parameter. But I don't think it should give a warning in the default case, but your suggestion seems like it would, i.e, the default is override_timestamps_with_wall_time=false, use_sim_time=false. Do we really need to align the parameters? Can we not simply check override_timestamps_with_wall_time?

azeey avatar Jun 18 '24 17:06 azeey

For me just adding the override_timestamps_with_wall_time parameter is fine. Thanks for your elaborate reply. I will update my PR accordingly and publish it.

reinzor avatar Jun 19 '24 09:06 reinzor