rclcpp: '/clock' Topic cannot change each loop step time from simulation time

Bug report

Required Info:

  • Operating System:
  • Installation type:
  • Version or commit hash:
  • DDS implementation:
  • Client library (if applicable):

Steps to reproduce issue

In my node, i have publish topic ‘/clock’ and set use_sim_time:=true. Although these settings change the results of this->now(), there is no implementation in which the frequency of program loops is independent of the simulation period.

Expected behavior

In ros1-Melodic, the same setting, will realize this result: 20240517-224428 The first echo result is use_sim_time = false, and The second echo result is use_sim_time = true

Actual behavior

In ros2-foxy, humble also have these issue, like this: 20240517-230053 when i set publish topic ‘clock’ and set use_sim_time:=true, the this->get_clock()->now() or this->now() can get the sim time, but the topic pub frequenct same not change by these settings.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 1
  • Comments: 17

Most upvoted comments

I have been set use_sim_time=true https://design.ros2.org/articles/clock_and_time.html

use_sim_time is set on the node, but Rate object. with your example, as @Barry-Xu-2018 mentions, Rate is instantiated with system time as default, not simulation time. I think you need to set RCL_SYSTEM_TIME for Rate, the it can get the time from simulation clock.

this->get_clock()->now() or this->now() can get the sim time,

assuming that this is the Node. because the use_sim_time is set to true, clock belongs to node is now set to simulation clock. so that it can get simulation clock.

@wenxuanou Currently, the implementation in Humble cannot directly use the simulation clock.
I think you have to implement a new Rate based on a Clock with RCL_ROS_TIME (as I mentioned above).