Time

To preserve the accuracy and allow for compatible serialization of message objects, custom Time and WallTime anonymous datatypes were introduced. This Time datatype is used for time fields in received messages and can be obtained using the Time singleton.

Example:

property var currentTime: Time.now()
property var currentWallTime: WallTime.now()

The Time singleton wraps most static methods of ros::Time whereas the instances obtained using either Time.now() or Time.create() contain the instance methods and properties for sec and nsec.

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

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

API

class qml_ros_plugin::Time : public TimeWrapper<ros::Time>

Represents a point in time of the robot or simulation.

Properties:

  • sec: unsigned integer containing the seconds passed since 1970

  • nsec: unsigned integer containing the nanoseconds since the last second

Public Functions

inline double toSec() const

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

inline quint64 toNSec() const

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

inline bool isZero() const

Whether the time represented by this instance is zero.

inline QVariant 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.

class qml_ros_plugin::WallTime : public TimeWrapper<ros::WallTime>

Represents a point in time of the current system.

Properties:

  • sec: unsigned integer containing the seconds passed since 1970

  • nsec: unsigned integer containing the nanoseconds since the last second

Public Functions

inline double toSec() const

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

inline quint64 toNSec() const

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

inline bool isZero() const

Whether the time represented by this instance is zero.

inline QVariant 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.

class qml_ros_plugin::TimeSingleton : public QObject

Public Functions

QVariant now()

Returns the ros::Time as Time. This can be either the simulation time or the system time.

Before the ros::Time got valid, this method returns a zero Time.

QVariant create(double t)

Creates a Time instance from the given time in seconds since 1970.

QVariant create(quint32 sec, quint32 nsec)

Creates a Time instance from the given time in seconds since 1970 and nanoseconds since the last full second.

bool isSimTime()

Whether the time obtained using now() is the simulation time.

bool isSystemTime()

Whether the time obtained using now() is the system time.

bool isValid()

Whether the time obtained with now() is currently valid.

class qml_ros_plugin::WallTimeSingleton : public QObject

Public Functions

QVariant now()

Returns the ros::WallTime as WallTime. This is always the system time.

QVariant create(double t)

Creates a WallTime instance from the given time in seconds since 1970.

QVariant create(quint32 sec, quint32 nsec)

Creates a WallTime instance from the given time in seconds since 1970 and nanoseconds since the last full second.