How to force ROS to use system clock instead of simulated /clock for hardware-in-loop simulation

asked 2020-03-10 22:11:59 -0600

Rufus gravatar image

updated 2020-03-10 22:50:54 -0600

I'm hoping to do hardware-in-loop testing with my system partially simulated, and partially connected to real sensors / actuators.

Everything is running on 1 computer with 1 ROS master

I found a problem where part of my system was using simulated time and parts of it were using system time leading to errors such as Lookup would require extrapolation into the past. Requested time 108.740000000 but the earliest data is at time 1583895444.608573112 where 108 is the simulated time and 1583895444 is the system time.

I found that gazebo was publishing a /clock message which was giving the simulated time.

However, when I tried disabling it by setting

    <include file="$(find gazebo_ros)/launch/empty_world.launch">
        ...
        <arg name="use_sim_time" value="false"/>
        ...
    </include>

I still see gazebo publishing /clock.

I've also set

   <param name="/use_sim_time" value="false"/>

before launching my nodes but my nodes still use the simulated time instead of real time.

I also noticed a subtle difference between ros::Time::now() and ros::Time(0).

Using ros::Time::now() results in

Lookup would require extrapolation into the future.  Requested time <wall time> but the latest data is at time <sim time>

while using ros::Time(0) results in

Lookup would require extrapolation into the past.  Requested time <sim time> but the latest data is at time <wall time>

Why is that happening? What am I doing wrong? How do I force the entire system to use system clock?

Maybe related: https://github.com/ros2/rclcpp/pull/559

edit retag flag offensive close merge delete

Comments

re: difference between Time::now() and Time(0) with TF lookups: #q243179.

gvdhoorn gravatar image gvdhoorn  ( 2020-03-11 03:18:04 -0600 )edit