Control and inspect simulated ROS time for scenarios using use_sim_time.
In test-controlled mode (use_sim_time: true), use advance_time/1 and
set_time/1 to publish /clock updates. sim_time/0 reads the current
scenario time in either test-controlled or externally-driven mode.
Summary
Functions
Advance simulated time by ms milliseconds.
Set simulated time to an absolute value in milliseconds.
Return the current simulated time in milliseconds.
Functions
@spec advance_time(non_neg_integer()) :: :ok
Advance simulated time by ms milliseconds.
Requires the scenario to be started with use_sim_time: true. Does three
things atomically from the scenario's perspective:
Advances the internal sim-time counter.
Sets the ROS time override on the scenario's
:ros_timeclock (soRclex.Clock.now/1returns the new time).Publishes a
rosgraph_msgs/msg/Clockmessage on/clock(so any node started withuse_sim_time:=trueupdates its internal clocks and any:ros_timetimers fire as appropriate).advance_time(1_000) # advance 1 second advance_time(500) # advance another 500 ms
@spec set_time(non_neg_integer()) :: :ok
Set simulated time to an absolute value in milliseconds.
Requires the scenario to be started with use_sim_time: true. Jumps
directly to the specified time without incrementing.
Useful for skipping ahead to specific milestones or resetting time in multi-phase tests.
set_time(5_000) # jump to 5 seconds
@spec sim_time() :: non_neg_integer()
Return the current simulated time in milliseconds.
When use_sim_time: true, returns the test-controlled counter.
When use_sim_time: :external, returns the actual ROS time (from external
/clock publisher like Gazebo).
When use_sim_time: false, returns 0.