ROS 2 rclcpp + rcl - kilted  kilted
ROS 2 C++ Client Library with ROS Client Library
Public Member Functions | Static Public Member Functions | List of all members
rclcpp::Time Class Reference

Public Member Functions

RCLCPP_PUBLIC Time (int32_t seconds, uint32_t nanoseconds, rcl_clock_type_t clock_type=RCL_SYSTEM_TIME)
 Time constructor. More...
 
RCLCPP_PUBLIC Time (int64_t nanoseconds=0, rcl_clock_type_t clock_type=RCL_SYSTEM_TIME)
 Time constructor. More...
 
RCLCPP_PUBLIC Time (const Time &rhs)
 Copy constructor.
 
RCLCPP_PUBLIC Time (Time &&rhs) noexcept
 Move constructor.
 
RCLCPP_PUBLIC Time (const builtin_interfaces::msg::Time &time_msg, rcl_clock_type_t clock_type=RCL_ROS_TIME)
 Time constructor. More...
 
RCLCPP_PUBLIC Time (const rcl_time_point_t &time_point)
 Time constructor. More...
 
virtual RCLCPP_PUBLIC ~Time ()
 Time destructor.
 
RCLCPP_PUBLIC operator builtin_interfaces::msg::Time () const
 Return a builtin_interfaces::msg::Time object based.
 
RCLCPP_PUBLIC Timeoperator= (const Time &rhs)
 
RCLCPP_PUBLIC Timeoperator= (const builtin_interfaces::msg::Time &time_msg)
 
RCLCPP_PUBLIC Timeoperator= (Time &&rhs) noexcept
 
RCLCPP_PUBLIC bool operator== (const rclcpp::Time &rhs) const
 
RCLCPP_PUBLIC bool operator!= (const rclcpp::Time &rhs) const
 
RCLCPP_PUBLIC bool operator< (const rclcpp::Time &rhs) const
 
RCLCPP_PUBLIC bool operator<= (const rclcpp::Time &rhs) const
 
RCLCPP_PUBLIC bool operator>= (const rclcpp::Time &rhs) const
 
RCLCPP_PUBLIC bool operator> (const rclcpp::Time &rhs) const
 
RCLCPP_PUBLIC Time operator+ (const rclcpp::Duration &rhs) const
 
RCLCPP_PUBLIC Duration operator- (const rclcpp::Time &rhs) const
 
RCLCPP_PUBLIC Time operator- (const rclcpp::Duration &rhs) const
 
RCLCPP_PUBLIC Timeoperator+= (const rclcpp::Duration &rhs)
 
RCLCPP_PUBLIC Timeoperator-= (const rclcpp::Duration &rhs)
 
RCLCPP_PUBLIC rcl_time_point_value_t nanoseconds () const
 Get the nanoseconds since epoch. More...
 
RCLCPP_PUBLIC double seconds () const
 Get the seconds since epoch. More...
 
RCLCPP_PUBLIC rcl_clock_type_t get_clock_type () const
 Get the clock type. More...
 

Static Public Member Functions

static RCLCPP_PUBLIC Time max (rcl_clock_type_t clock_type=RCL_SYSTEM_TIME)
 Get the maximum representable value. More...
 

Detailed Description

Definition at line 31 of file time.hpp.

Constructor & Destructor Documentation

◆ Time() [1/4]

rclcpp::Time::Time ( int32_t  seconds,
uint32_t  nanoseconds,
rcl_clock_type_t  clock_type = RCL_SYSTEM_TIME 
)

Time constructor.

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

Parameters
secondspart of the time in seconds since time epoch
nanosecondspart of the time in nanoseconds since time epoch
clock_typeclock type
Exceptions
std::runtime_errorif seconds are negative

Definition at line 49 of file time.cpp.

References rcl_time_point_s::nanoseconds, nanoseconds(), RCL_S_TO_NS, and seconds().

Referenced by max(), operator+(), operator-(), and operator=().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Time() [2/4]

rclcpp::Time::Time ( int64_t  nanoseconds = 0,
rcl_clock_type_t  clock_type = RCL_SYSTEM_TIME 
)
explicit

Time constructor.

Parameters
nanosecondssince time epoch
clock_typeclock type
Exceptions
std::runtime_errorif nanoseconds are negative

Definition at line 60 of file time.cpp.

References rcl_time_point_s::nanoseconds, and nanoseconds().

Here is the call graph for this function:

◆ Time() [3/4]

rclcpp::Time::Time ( const builtin_interfaces::msg::Time &  time_msg,
rcl_clock_type_t  clock_type = RCL_ROS_TIME 
)

Time constructor.

Parameters
time_msgbuiltin_interfaces time message to copy
clock_typeclock type
Exceptions
std::runtime_errorif seconds are negative

Definition at line 74 of file time.cpp.

References rcl_time_point_s::nanoseconds, and RCL_S_TO_NS.

◆ Time() [4/4]

rclcpp::Time::Time ( const rcl_time_point_t time_point)
explicit

Time constructor.

Parameters
time_pointrcl_time_point_t structure to copy

Definition at line 87 of file time.cpp.

Member Function Documentation

◆ get_clock_type()

rcl_clock_type_t rclcpp::Time::get_clock_type ( ) const

Get the clock type.

Returns
the clock type

Definition at line 228 of file time.cpp.

References rcl_time_point_s::clock_type.

Referenced by rclcpp::operator+(), and rclcpp::Clock::sleep_until().

Here is the caller graph for this function:

◆ max()

Time rclcpp::Time::max ( rcl_clock_type_t  clock_type = RCL_SYSTEM_TIME)
static

Get the maximum representable value.

Returns
the maximum representable value

Definition at line 282 of file time.cpp.

References Time().

Here is the call graph for this function:

◆ nanoseconds()

int64_t rclcpp::Time::nanoseconds ( ) const

Get the nanoseconds since epoch.

Returns
the nanoseconds since epoch as a rcl_time_point_value_t structure.

Definition at line 216 of file time.cpp.

References rcl_time_point_s::nanoseconds.

Referenced by rclcpp::topic_statistics::SubscriptionTopicStatistics::handle_message(), rclcpp::operator+(), operator+(), rclcpp::Clock::sleep_until(), and Time().

Here is the caller graph for this function:

◆ operator+()

Time rclcpp::Time::operator+ ( const rclcpp::Duration rhs) const
Exceptions
std::overflow_errorif addition leads to overflow

Definition at line 170 of file time.cpp.

References rclcpp::add_will_overflow(), rclcpp::add_will_underflow(), rclcpp::Duration::nanoseconds(), nanoseconds(), and Time().

Here is the call graph for this function:

◆ operator+=()

Time & rclcpp::Time::operator+= ( const rclcpp::Duration rhs)
Exceptions
std::overflow_errorif addition leads to overflow

Definition at line 246 of file time.cpp.

References rclcpp::add_will_overflow(), rclcpp::add_will_underflow(), rcl_time_point_s::nanoseconds, and rclcpp::Duration::nanoseconds().

Here is the call graph for this function:

◆ operator-() [1/2]

Time rclcpp::Time::operator- ( const rclcpp::Duration rhs) const
Exceptions
std::overflow_errorif addition leads to overflow

Definition at line 203 of file time.cpp.

References rcl_time_point_s::clock_type, rcl_time_point_s::nanoseconds, rclcpp::Duration::nanoseconds(), rclcpp::sub_will_overflow(), rclcpp::sub_will_underflow(), and Time().

Here is the call graph for this function:

◆ operator-() [2/2]

Duration rclcpp::Time::operator- ( const rclcpp::Time rhs) const
Exceptions
std::runtime_errorif the time sources are different
std::overflow_errorif addition leads to overflow

Definition at line 182 of file time.cpp.

References rcl_time_point_s::clock_type, rclcpp::Duration::from_nanoseconds(), rcl_time_point_s::nanoseconds, rclcpp::sub_will_overflow(), and rclcpp::sub_will_underflow().

Here is the call graph for this function:

◆ operator-=()

Time & rclcpp::Time::operator-= ( const rclcpp::Duration rhs)
Exceptions
std::overflow_errorif addition leads to overflow

Definition at line 264 of file time.cpp.

References rcl_time_point_s::nanoseconds, rclcpp::Duration::nanoseconds(), rclcpp::sub_will_overflow(), and rclcpp::sub_will_underflow().

Here is the call graph for this function:

◆ operator<()

bool rclcpp::Time::operator< ( const rclcpp::Time rhs) const
Exceptions
std::runtime_errorif the time sources are different

Definition at line 129 of file time.cpp.

References rcl_time_point_s::clock_type, and rcl_time_point_s::nanoseconds.

◆ operator<=()

bool rclcpp::Time::operator<= ( const rclcpp::Time rhs) const
Exceptions
std::runtime_errorif the time sources are different

Definition at line 139 of file time.cpp.

References rcl_time_point_s::clock_type, and rcl_time_point_s::nanoseconds.

◆ operator=() [1/3]

Time & rclcpp::Time::operator= ( const builtin_interfaces::msg::Time &  time_msg)

Assign Time from a builtin_interfaces::msg::Time instance. The clock_type will be reset to RCL_ROS_TIME. Equivalent to *this = Time(time_msg, RCL_ROS_TIME).

Exceptions
std::runtime_errorif seconds are negative

Definition at line 104 of file time.cpp.

References Time().

Here is the call graph for this function:

◆ operator=() [2/3]

Time & rclcpp::Time::operator= ( const Time rhs)
default

Copy assignment operator

Exceptions
std::runtime_errorif seconds are negative

◆ operator=() [3/3]

Time & rclcpp::Time::operator= ( Time &&  rhs)
defaultnoexcept

Move assignment operator

◆ operator==()

bool rclcpp::Time::operator== ( const rclcpp::Time rhs) const
Exceptions
std::runtime_errorif the time sources are different

Definition at line 114 of file time.cpp.

References rcl_time_point_s::clock_type, and rcl_time_point_s::nanoseconds.

◆ operator>()

bool rclcpp::Time::operator> ( const rclcpp::Time rhs) const
Exceptions
std::runtime_errorif the time sources are different

Definition at line 160 of file time.cpp.

References rcl_time_point_s::clock_type, and rcl_time_point_s::nanoseconds.

◆ operator>=()

bool rclcpp::Time::operator>= ( const rclcpp::Time rhs) const
Exceptions
std::runtime_errorif the time sources are different

Definition at line 150 of file time.cpp.

References rcl_time_point_s::clock_type, and rcl_time_point_s::nanoseconds.

◆ seconds()

double rclcpp::Time::seconds ( ) const

Get the seconds since epoch.

Warning
Depending on sizeof(double) there could be significant precision loss. When an exact time is required use nanoseconds() instead.
Returns
the seconds since epoch as a floating point number.

Definition at line 222 of file time.cpp.

References rcl_time_point_s::nanoseconds.

Referenced by Time().

Here is the caller graph for this function:

The documentation for this class was generated from the following files: