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.

Please note that this is a Q_GADGET and not a QObject which means there is no signal emitted when properties change.

Public Functions

inline double seconds() const

Get the seconds since epoch as floating point including sub-seconds.

inline qint64 nanoseconds() const

Get the nanoseconds since epoch.

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.

inline quint32 clockType() const

The type of the time source. See Ros2ClockTypes.

Properties

qint32 sec

The time in seconds (since 1970) as an integer. Use seconds() for floating point value including sub-seconds.

quint32 nanosec

The time in nanoseconds relative to the current second (as unsigned integer). Use nanoseconds() for the full time in nanoseconds since epoch.

class Duration

Represents a duration for a time source.

Please note that this is a Q_GADGET and not a QObject which means there is no signal emitted when properties change.

Public Functions

inline double seconds() const

Get the seconds of the duration as floating point including sub-seconds.

inline qint64 nanoseconds() const

Get the full duration as nanosecond.

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

qint32 sec

The duration in seconds as an integer. Use seconds() for floating point value including sub-seconds.

quint32 nanosec

The time in nanoseconds relative to the current second (as unsigned integer). Use nanoseconds() for the full 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.