Rclex.Duration (Rclex (Experimental) v0.12.0)

Copy Markdown View Source

A signed duration, stored as nanoseconds.

ROS 2 messages typically carry durations as builtin_interfaces/msg/Duration. Use to_msg/1 and from_msg/1 to convert.

Summary

Functions

Add two durations.

Compare two durations; returns :lt, :eq, or :gt.

Build a Duration from a builtin_interfaces/msg/Duration-shaped struct or map.

Create a Duration from a number of seconds (may be fractional).

Multiply a duration by a numeric scalar.

Negate a duration.

Create a Duration from an integer number of nanoseconds.

Subtract one duration from another.

Convert to a Rclex.Pkgs.BuiltinInterfaces.Msg.Duration struct.

Total nanoseconds, possibly negative.

Duration in seconds (floating point).

Types

t()

@type t() :: %Rclex.Duration{nanoseconds: integer()}

Functions

add(duration1, duration2)

@spec add(t(), t()) :: t()

Add two durations.

compare(duration1, duration2)

@spec compare(t(), t()) :: :lt | :eq | :gt

Compare two durations; returns :lt, :eq, or :gt.

from_msg(map)

@spec from_msg(map()) :: t()

Build a Duration from a builtin_interfaces/msg/Duration-shaped struct or map.

from_seconds(seconds)

@spec from_seconds(number()) :: t()

Create a Duration from a number of seconds (may be fractional).

mul(duration, factor)

@spec mul(t(), number()) :: t()

Multiply a duration by a numeric scalar.

negate(duration)

@spec negate(t()) :: t()

Negate a duration.

new(nanoseconds)

@spec new(integer()) :: t()

Create a Duration from an integer number of nanoseconds.

sub(duration1, duration2)

@spec sub(t(), t()) :: t()

Subtract one duration from another.

to_msg(duration)

@spec to_msg(t()) :: struct()

Convert to a Rclex.Pkgs.BuiltinInterfaces.Msg.Duration struct.

to_nanoseconds(duration)

@spec to_nanoseconds(t()) :: integer()

Total nanoseconds, possibly negative.

to_seconds(duration)

@spec to_seconds(t()) :: float()

Duration in seconds (floating point).