Skip to content

Adapting the clock rate

The Clock Publisher node publishes the current time as a ROS message of type rosgraph_msgs/Clock on the topic /clock. It allows to speed up or slow down the time by a factor clock_rate which can be set via a ROS parameter or argument to the launch file. You can either integrate the clock.launch in the launch file of your interest or launch it from a separate terminal.

Launch in a separate terminal

Terminal 1

roscore

Terminal 2

rosparam set use_sim_time true #in order to use the time published by this node.

roslaunch clock_publisher clock.launch clock_rate:=0.1

Terminal 3

Run whatever node you want to use the simulated time. E.g.

roslaunch crs_launch sim_single_car.launch

Launch from another launch file

This can be done in multiple ways, e.g.:

Launch file

In your launch file add the input argument

<arg name = "clock_rate"     default = "1"               doc = "Rate at which the simulated clock should run. 1 means real time, 0.5 means half speed, etc." />
and include clock.launch

<group if = "$(eval clock_rate != 1)">
        <param name="/use_sim_time" value="true" />
        <include file="$(find clock_publisher)launch/clock.launch">
            <arg name = "clock_rate"            value = "$(arg clock_rate)"/>
        </include>
</group>
Note that clock.launch only gets launched if we want to modify the clock_rate (clock_rate != 1)

Terminal 1

Launch the launch file above (e.g. sim_single_car.launch) with your desired clock_rate. E.g.

roslaunch crs_launch sim_single_car.launch clock_rate:=0.1