Time

To preserve the accuracy and allow for compatible serialization of message objects, anonymous wrappers for Time and Duration were introduced. These wrapper types are used for time and duration fields in received messages and the current time can be obtained using the Ros2.now() method of the Ros2 Singleton.

Example:

property var currentTime: Ros2.now()

Both wrapper types can be converted to QML/JavaScript Date objects using the toJSDate() method at the cost of micro- and nanosecond accuracy.

Please note that due to limitations in QML and JavaScript mathematical operations for Time and Duration are not possible.

API

class Time

Represents a point in time for a time source.

Properties:

  • seconds: Floating point value containing the seconds passed since epoch. Depending on the size of double, this may have significant precision loss. Use nanoseconds for precision.

  • nanoseconds: unsigned integer containing the nanoseconds since epoch.

  • clockType: The type of the time source. See Ros2ClockTypes

Public Functions

inline bool isZero() const

Whether the time represented by this instance is zero.

inline QDateTime toJSDate() const

A JS Date representing the value stored in this instance. Since JS Dates only have millisecond accuracy, information about microseconds and nanoseconds are lost. The time is always rounded down to prevent the JS Date from being in the future.

Properties

double seconds

The time in seconds (since 1970) as a decimal value. (Possible loss in precision)

quint64 nanoseconds

The time in nanoseconds (since 1970) as an unsigned integer.

quint32 clockType

The clock type of this time point. See Ros2ClockTypes.

class Duration

Represents a duration for a time source.

Properties:

  • seconds: Floating point value containing the seconds passed between two time points. Can be negative. Depending on the size of double, may have significant precision loss. Use nanoseconds if you need a precise measurement.

  • nanoseconds: Signed integer containing the nanoseconds that have passed between two timepoints.

Public Functions

inline bool isZero() const

Whether the duration represented by this instance is zero.

inline double toJSDuration() const

A JS duration representing the value stored in this instance. JS measures differences between two Dates as a (floating point) number of milliseconds.

Properties

double seconds

The time in seconds that has passed between two timepoints. (Possible loss in precision)

qint64 nanoseconds

The duration in nanoseconds.

enum qml_ros2_plugin::ros_clock_types::Ros2ClockTypes

Values:

enumerator Uninitialized

Uninitialized.

enumerator Ros

ROS time.

enumerator System

System time.

enumerator Steady

Steady clock time.