RclexTesting.DSL.Time (RclexTesting (Experimental) v0.1.0)

Copy Markdown View Source

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

advance_time(ms)

@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:

  1. Advances the internal sim-time counter.

  2. Sets the ROS time override on the scenario's :ros_time clock (so Rclex.Clock.now/1 returns the new time).

  3. Publishes a rosgraph_msgs/msg/Clock message on /clock (so any node started with use_sim_time:=true updates its internal clocks and any :ros_time timers fire as appropriate).

    advance_time(1_000) # advance 1 second advance_time(500) # advance another 500 ms

set_time(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

sim_time()

@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.