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.
Return the configured clock_type/0.
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
@type clock_type() :: Rclex.Time.clock_type()
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec clock_type(GenServer.server()) :: clock_type()
Return the configured clock_type/0.
@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.
@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.
@spec now(GenServer.server()) :: Rclex.Time.t()
Return the clock's current time as a Rclex.Time.
@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.
@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.
@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 toRclex.Clock.
@spec stop(GenServer.server()) :: :ok
Stop the clock and release the underlying NIF resource.