rclcpp  master
C++ ROS Client Library API
Public Member Functions | Static Public Member Functions | List of all members
rclcpp::Time Class Reference

#include <time.hpp>

Public Member Functions

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

Static Public Member Functions

static Time max ()
 Get the maximum representable value. More...
 

Constructor & Destructor Documentation

◆ Time() [1/5]

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

◆ Time() [2/5]

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

◆ Time() [3/5]

rclcpp::Time::Time ( const Time rhs)

Copy constructor.

◆ Time() [4/5]

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

◆ Time() [5/5]

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

Time constructor.

Parameters
time_pointrcl_time_point_t structure to copy

◆ ~Time()

virtual rclcpp::Time::~Time ( )
virtual

Time destructor.

Member Function Documentation

◆ operator builtin_interfaces::msg::Time()

rclcpp::Time::operator builtin_interfaces::msg::Time ( ) const

Return a builtin_interfaces::msg::Time object based.

◆ operator=() [1/2]

Time& rclcpp::Time::operator= ( const Time rhs)
Exceptions
std::runtime_errorif seconds are negative

◆ operator=() [2/2]

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

◆ operator==()

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

◆ operator!=()

bool rclcpp::Time::operator!= ( const rclcpp::Time rhs) const

◆ operator<()

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

◆ operator<=()

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

◆ operator>=()

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

◆ operator>()

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

◆ operator+()

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

◆ operator-() [1/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

◆ operator-() [2/2]

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

◆ operator+=()

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

◆ operator-=()

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

◆ nanoseconds()

rcl_time_point_value_t rclcpp::Time::nanoseconds ( ) const

Get the nanoseconds since epoch.

Returns
the nanoseconds since epoch as a rcl_time_point_value_t structure.

◆ max()

static Time rclcpp::Time::max ( )
static

Get the maximum representable value.

Returns
the maximum representable value

◆ 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.

◆ get_clock_type()

rcl_clock_type_t rclcpp::Time::get_clock_type ( ) const

Get the clock type.

Returns
the clock type

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