synchros2.time module

synchros2.time.as_proper_duration(duration: int | float | timedelta | rclpy.duration.Duration) rclpy.duration.Duration[source]

Convert duration to a proper, standardized Duration object.

For conversion, the following rules apply: - if an int or a float is provided, it is assumed to be a duration expressed in seconds. - if a timedelta is provided, timedelta.total_seconds() are used. - if a Duration is provided, it is returned as is.

Parameters:

duration – the duration to be converted.

Returns:

an standardized Duration object representing the given duration.

Raises:

ValueError – if the given duration is not of a supported type.

synchros2.time.as_proper_time(time: int | float | datetime | rclpy.time.Time) rclpy.time.Time[source]

Convert time to a proper, standardized Time object.

For conversion, the following rules apply: - if an int or a float is provided, it is assumed to be a timestamp expressed in seconds. - if a datetime is provided, its UTC datetime.timestamp() is used. - if a Duration is provided, it is returned as is.

Parameters:

time – the time to be converted.

Returns:

an standardized Time object in ROS time, representing the given time.

Raises:

ValueError – if the given time is not of a supported type.