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:
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:
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
use_sim_timeis set on the node, butRateobject. with your example, as @Barry-Xu-2018 mentions,Rateis instantiated with system time as default, not simulation time. I think you need to setRCL_SYSTEM_TIMEforRate, the it can get the time from simulation clock.assuming that
thisis theNode. because theuse_sim_timeis 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
Ratebased on a Clock with RCL_ROS_TIME (as I mentioned above).Please note that rclcpp::Rate use
RCL_SYSTEM_TIMEin default. Do you change it ?https://github.com/ros2/rclcpp/blob/348e22a48641bf2622f81e562ad3cb7bf910a183/rclcpp/include/rclcpp/rate.hpp#L133-L146