ros2_control: Update rate incorrect if using sim time

Describe the bug When the ‘use_sim_time’ parameter is set, the ros2_control_node’s main loop runs at a rate different then what is provided to the ‘update_rate’ parameter. In my case, update_rate is set to 100 Hz and the loop runs at ~2.5 kHz.

To Reproduce With a simulated robot and the /clock topic available Steps to reproduce the behavior:

  1. Set up the controller manager with the update_rate parameter set to 100 and the use_sim_time parameter set to true
  2. Set up a joint state broadcaster
  3. Run the sim and controllers
  4. run “ros2 topic hz /joint_states”

Expected behavior The /joint_states topic publishes at 100Hz or some number related to that and the real_time_factor of the sim

Environment (please complete the following information):

  • OS: Ubuntu 22.04
  • Version: Humble

I am able to get it to run at the correct rate if i modify https://github.com/ros-controls/ros2_control/blob/62a3d26fa2fa3c3b703f33c9a86fcada95ae955f/controller_manager/src/ros2_control_node.cpp#L65-L66 to std::chrono::steady_clock::time_point next_iteration_time = std::chrono::steady_clock::now(); which will obviously run at 100 Hz in real time. I am not sure if the intended behavior would be for the rate to be sim time instead, but steady time would make more sense than system time for real hardware anyway.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 16 (8 by maintainers)

Commits related to this issue

Most upvoted comments

I tried the example reported in this issue. Following the suggestion of @saikishor I’d also suggest to do this in a different node which can be hosted here or in topic_based_ros2_control. @krzychut have you figured out a solution already and want to contribute it with a PR? Maybe we should even throw an error if ros2_control_node is launched with use_sim_time. Or is there a usecase in doing so?