Rclex.Clock (Rclex (Experimental) v0.12.0)

Copy Markdown View Source

GenServer wrapping an rcl_clock_t resource.

A clock is created with one of three types:

  • :system_time — wall-clock (CLOCK_REALTIME)
  • :steady_time — monotonic (CLOCK_MONOTONIC)
  • :ros_time — ROS time, which may be overridden by simulated time

When :ros_time is used and the time override is enabled (via enable_ros_time_override/1), now/1 returns the value most recently passed to set_ros_time_override/2. This is the mechanism behind use_sim_time — a /clock topic subscriber feeds messages into the override.

Clocks are usually started under the application's main supervision tree via Rclex.start_clock/1. They can be reused across many callers via the registered name.

Summary

Functions

Returns a specification to start this module under a supervisor.

Disable ROS time override; the clock falls back to system time.

Enable ROS time override on a :ros_time clock.

Return the clock's current time as a Rclex.Time.

Whether the clock is :ros_time and ROS time override is enabled.

Set the ROS time override value on a :ros_time clock.

Start a clock GenServer.

Stop the clock and release the underlying NIF resource.

Types

clock_type()

@type clock_type() :: Rclex.Time.clock_type()

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

clock_type(server \\ __MODULE__)

@spec clock_type(GenServer.server()) :: clock_type()

Return the configured clock_type/0.

disable_ros_time_override(server \\ __MODULE__)

@spec disable_ros_time_override(GenServer.server()) ::
  :ok | {:error, :clock_type_not_ros_time}

Disable ROS time override; the clock falls back to system time.

enable_ros_time_override(server \\ __MODULE__)

@spec enable_ros_time_override(GenServer.server()) ::
  :ok | {:error, :clock_type_not_ros_time}

Enable ROS time override on a :ros_time clock.

Returns {:error, :clock_type_not_ros_time} if the clock isn't :ros_time.

now(server \\ __MODULE__)

@spec now(GenServer.server()) :: Rclex.Time.t()

Return the clock's current time as a Rclex.Time.

ros_time_override_active?(server \\ __MODULE__)

@spec ros_time_override_active?(GenServer.server()) :: boolean()

Whether the clock is :ros_time and ROS time override is enabled.

When true, now/1 returns whatever was last set via set_ros_time_override/2.

set_ros_time_override(server \\ __MODULE__, time)

@spec set_ros_time_override(GenServer.server(), Rclex.Time.t() | integer()) ::
  :ok | {:error, :clock_type_not_ros_time}

Set the ROS time override value on a :ros_time clock.

The clock must already have override enabled via enable_ros_time_override/1.

start_link(opts \\ [])

@spec start_link(keyword()) :: GenServer.on_start()

Start a clock GenServer.

opts

  • :clock_type — one of :system_time (default), :steady_time, :ros_time.
  • :name — optional registered name. Defaults to Rclex.Clock.

stop(server \\ __MODULE__)

@spec stop(GenServer.server()) :: :ok

Stop the clock and release the underlying NIF resource.