A point in time, paired with the clock type that produced it.
Stored as nanoseconds since the clock's epoch. The :clock_type field
matches the Rclex.Clock.clock_type/0 of the clock that produced the
time and is used to prevent meaningless arithmetic between incompatible
clocks (e.g. subtracting a steady-time Time from a system-time Time).
ROS 2 messages typically carry timestamps as builtin_interfaces/msg/Time.
Use to_msg/1 and from_msg/2 to convert.
Summary
Functions
Compare two Time values; returns :lt, :eq, or :gt.
Build a Time from a builtin_interfaces/msg/Time-shaped struct or map.
Create a Time from a number of seconds.
Create a Time from an integer number of nanoseconds.
Convert to a Rclex.Pkgs.BuiltinInterfaces.Msg.Time struct.
Total nanoseconds since the clock's epoch.
Time in seconds (floating point).
Types
@type clock_type() :: :system_time | :steady_time | :ros_time
@type t() :: %Rclex.Time{clock_type: clock_type(), nanoseconds: integer()}
Functions
@spec add(t(), Rclex.Duration.t()) :: t()
Compare two Time values; returns :lt, :eq, or :gt.
@spec from_msg(map(), clock_type()) :: t()
Build a Time from a builtin_interfaces/msg/Time-shaped struct or map.
@spec from_seconds(number(), clock_type()) :: t()
Create a Time from a number of seconds.
@spec new(integer(), clock_type()) :: t()
Create a Time from an integer number of nanoseconds.
@spec sub(t(), t() | Rclex.Duration.t()) :: Rclex.Duration.t() | t()
Subtract a Time or Duration from a Time.
Subtracting two Time values returns a Duration. Both must share the
same :clock_type, otherwise raises ArgumentError.
Convert to a Rclex.Pkgs.BuiltinInterfaces.Msg.Time struct.
Note: ROS message Time uses unsigned nanosec, so negative Time values
are not representable. Conversion of a negative Time raises.
Total nanoseconds since the clock's epoch.
Time in seconds (floating point).