Open fengzhongsu opened 1 month ago
How do you create timer to publish messages ?
create_wall_timer or create_timer
Simulate time doesn't affect create_wall_timer.
您好,我已受到您的来信
How do you create timer to publish messages ? create_wall_timer or create_timer Simulate time doesn't affect create_wall_timer.
Hi, Barry. In simulation, i used rclcpp::Rate loop_rate(ctrl_freq); And In a
while(rclcpp::ok()) { rclcpp::spin_some(mynode); //my program loop_rate.sleep(); }
Please note that rclcpp::Rate use RCL_SYSTEM_TIME
in default. Do you change it ?
Please note that rclcpp::Rate use
RCL_SYSTEM_TIME
in default. Do you change it ?
I have been set use_sim_time=true https://design.ros2.org/articles/clock_and_time.html
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.
As fujitatomoya said,you should modify code on creating Rate.
rclcpp::Rate loop_rate(ctrl_freq, std::make_shared
As fujitatomoya said,you should modify code on creating Rate.
rclcpp::Rate loop_rate(ctrl_freq, std::make_shared(RCL_ROS_TIME)); I have tried add this code. But have some error in IDE, my ros2 version is foxy error: no matching function for call to ‘make_shared(rcl_clock_type_t)’ 268 | rclcpp::Rate loop_rate(ctrl_freq, std::make_shared(RCL_ROS_TIME));
I have tried add this code. But have some error in IDE, my ros2 version is foxy
Foxy is already E.O.L, can you use humble
or later instead?
For Foxy, you should create a Clock with RCL_ROS_TIME
Create a new "Rate" like with above Clock.
BTW, foxy is EOL. So it's best to upgrade to the Humble or Iron version.
Bug report
Required Info:
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.