Class Duration

Class Documentation

class Duration

Public Functions

Duration(int32_t seconds, uint32_t nanoseconds)

Duration constructor.

Initializes the time values for seconds and nanoseconds individually. Large values for nsecs are wrapped automatically with the remainder added to secs. Both inputs must be integers. Seconds can be negative.

Parameters:
  • seconds – time in seconds

  • nanoseconds – time in nanoseconds

explicit Duration(std::chrono::nanoseconds nanoseconds)

Construct duration from the specified std::chrono::nanoseconds.

template<class Rep, class Period>
inline Duration(const std::chrono::duration<Rep, Period> &duration)
Duration(const builtin_interfaces::msg::Duration &duration_msg)
explicit Duration(const rcl_duration_t &duration)

Time constructor.

Parameters:

duration – rcl_duration_t structure to copy.

Duration(const Duration &rhs)
virtual ~Duration() = default
operator builtin_interfaces::msg::Duration() const
Duration &operator=(const Duration &rhs)
Duration &operator=(const builtin_interfaces::msg::Duration &duration_msg)
bool operator==(const rclcpp::Duration &rhs) const
bool operator!=(const rclcpp::Duration &rhs) const
bool operator<(const rclcpp::Duration &rhs) const
bool operator<=(const rclcpp::Duration &rhs) const
bool operator>=(const rclcpp::Duration &rhs) const
bool operator>(const rclcpp::Duration &rhs) const
Duration operator+(const rclcpp::Duration &rhs) const
Duration operator-(const rclcpp::Duration &rhs) const
Duration operator*(double scale) const
rcl_duration_value_t nanoseconds() const

Get duration in nanosecods.

Returns:

the duration in nanoseconds as a rcl_duration_value_t.

double seconds() const

Get duration in seconds.

Warning

Depending on sizeof(double) there could be significant precision loss. When an exact time is required use nanoseconds() instead.

Returns:

the duration in seconds as a floating point number.

template<class DurationT>
inline DurationT to_chrono() const

Convert Duration into a std::chrono::Duration.

rmw_time_t to_rmw_time() const

Convert Duration into rmw_time_t.

Public Static Functions

static Duration max()

Get the maximum representable value.

Returns:

the maximum representable value

static Duration from_seconds(double seconds)

Create a duration object from a floating point number representing seconds.

static Duration from_nanoseconds(rcl_duration_value_t nanoseconds)

Create a duration object from an integer number representing nanoseconds.

static Duration from_rmw_time(rmw_time_t duration)