ROS 2 rclcpp + rcl - jazzy
jazzy
ROS 2 C++ Client Library with ROS Client Library
|
Classes | |
class | Impl |
Public Member Functions | |
RCLCPP_PUBLIC | Clock (rcl_clock_type_t clock_type=RCL_SYSTEM_TIME) |
Default c'tor. More... | |
RCLCPP_PUBLIC Time | now () const |
RCLCPP_PUBLIC bool | sleep_until (Time until, Context::SharedPtr context=contexts::get_global_default_context()) |
RCLCPP_PUBLIC bool | sleep_for (Duration rel_time, Context::SharedPtr context=contexts::get_global_default_context()) |
RCLCPP_PUBLIC bool | started () |
RCLCPP_PUBLIC bool | wait_until_started (Context::SharedPtr context=contexts::get_global_default_context()) |
RCLCPP_PUBLIC bool | wait_until_started (const rclcpp::Duration &timeout, Context::SharedPtr context=contexts::get_global_default_context(), const rclcpp::Duration &wait_tick_ns=rclcpp::Duration(0, static_cast< uint32_t >(1e7))) |
RCLCPP_PUBLIC bool | ros_time_is_active () |
RCLCPP_PUBLIC void | cancel_sleep_or_wait () |
RCLCPP_PUBLIC rcl_clock_t * | get_clock_handle () noexcept |
Return the rcl_clock_t clock handle. | |
RCLCPP_PUBLIC rcl_clock_type_t | get_clock_type () const noexcept |
RCLCPP_PUBLIC std::mutex & | get_clock_mutex () noexcept |
Get the clock's mutex. | |
RCLCPP_PUBLIC JumpHandler::SharedPtr | create_jump_callback (JumpHandler::pre_callback_t pre_callback, JumpHandler::post_callback_t post_callback, const rcl_jump_threshold_t &threshold) |
|
explicit |
Default c'tor.
Initializes the clock instance with the given clock_type.
WARNING Don't instantiate a clock using RCL_ROS_TIME directly, unless you really know what you are doing. By default no TimeSource is attached to a new clock. This will lead to the unexpected behavior, that your RCL_ROS_TIME will run always on system time. If you want a RCL_ROS_TIME use Node::get_clock(), or make sure to attach a TimeSource yourself.
clock_type | type of the clock. |
anything | rclcpp::exceptions::throw_from_rcl_error can throw. |
Definition at line 68 of file clock.cpp.
Referenced by wait_until_started().
void rclcpp::Clock::cancel_sleep_or_wait | ( | ) |
JumpHandler::SharedPtr rclcpp::Clock::create_jump_callback | ( | JumpHandler::pre_callback_t | pre_callback, |
JumpHandler::post_callback_t | post_callback, | ||
const rcl_jump_threshold_t & | threshold | ||
) |
These callback functions must remain valid as long as the returned shared pointer is valid.
Function will register callbacks to the callback queue. On time jump all callbacks will be executed whose threshold is greater then the time jump; The logic will first call selected pre_callbacks and then all selected post_callbacks.
Function is only applicable if the clock_type is RCL_ROS_TIME
pre_callback | Must be non-throwing |
post_callback | Must be non-throwing. |
threshold | Callbacks will be triggered if the time jump is greater then the threshold. |
anything | rclcpp::exceptions::throw_from_rcl_error can throw. |
std::bad_alloc | if the allocation of the JumpHandler fails. |
Definition at line 330 of file clock.cpp.
References rcl_clock_add_jump_callback(), and RCL_RET_OK.
Referenced by sleep_until().
Time rclcpp::Clock::now | ( | ) | const |
Returns current time from the time source specified by clock_type.
anything | rclcpp::exceptions::throw_from_rcl_error can throw. |
Definition at line 74 of file clock.cpp.
References rcl_time_point_s::nanoseconds, rcl_clock_get_now(), and RCL_RET_OK.
Referenced by sleep_for(), sleep_until(), and wait_until_started().
bool rclcpp::Clock::ros_time_is_active | ( | ) |
Returns the clock of the type RCL_ROS_TIME
is active.
anything | rclcpp::exceptions::throw_from_rcl_error can throw if the current clock does not have the clock_type RCL_ROS_TIME . |
Definition at line 278 of file clock.cpp.
References rcl_clock_valid(), rcl_is_enabled_ros_time_override(), and RCL_RET_OK.
Referenced by sleep_until().
bool rclcpp::Clock::sleep_for | ( | Duration | rel_time, |
Context::SharedPtr | context = contexts::get_global_default_context() |
||
) |
Sleep for a specified Duration.
Equivalent to
The function will return immediately if rel_time
is zero or negative.
rel_time | the length of time to sleep for. |
context | the rclcpp context the clock should use to check that ROS is still initialized. |
std::runtime_error | if the context is invalid |
Definition at line 207 of file clock.cpp.
References now(), and sleep_until().
Referenced by wait_until_started().
bool rclcpp::Clock::sleep_until | ( | Time | until, |
Context::SharedPtr | context = contexts::get_global_default_context() |
||
) |
Sleep until a specified Time, according to clock type.
Notes for RCL_ROS_TIME clock type:
until
pthread_cond_clockwait
, steady clocks may sleep using the system clock. If so, steady clock sleep times can be affected by system clock time jumps. Depending on the steady clock's epoch and resolution in comparison to the system clock's, an overflow when converting steady clock durations to system clock times may cause undefined behavior. For more info see these issues: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=41861 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58931until | absolute time according to current clock type to sleep until. |
context | the rclcpp context the clock should use to check that ROS is still initialized. |
until
is in the past until
is reached std::runtime_error | if the context is invalid |
std::runtime_error | if until has a different clock type from this clock |
Definition at line 97 of file clock.cpp.
References rcl_time_jump_s::clock_change, create_jump_callback(), rclcpp::Time::get_clock_type(), rcl_jump_threshold_s::min_backward, rcl_jump_threshold_s::min_forward, rcl_duration_s::nanoseconds, rclcpp::Duration::nanoseconds(), rclcpp::Time::nanoseconds(), now(), rcl_jump_threshold_s::on_clock_change, RCL_ROS_TIME, RCL_ROS_TIME_NO_CHANGE, RCL_STEADY_TIME, RCL_SYSTEM_TIME, and ros_time_is_active().
Referenced by sleep_for(), and wait_until_started().
bool rclcpp::Clock::started | ( | ) |
Check if the clock is started.
A started clock is a clock that reflects non-zero time. Typically a clock will be unstarted if it is using RCL_ROS_TIME with ROS time and nothing has been published on the clock topic yet.
std::runtime_error | if the clock is not rcl_clock_valid |
Definition at line 213 of file clock.cpp.
References get_clock_handle(), rcl_clock_time_started(), and rcl_clock_valid().
Referenced by wait_until_started().
bool rclcpp::Clock::wait_until_started | ( | const rclcpp::Duration & | timeout, |
Context::SharedPtr | context = contexts::get_global_default_context() , |
||
const rclcpp::Duration & | wait_tick_ns = rclcpp::Duration(0, static_cast<uint32_t>(1e7)) |
||
) |
Wait for clock to start, with timeout.
The timeout is waited in steady time.
\rclcpp::Clock::started
timeout | the maximum time to wait for. |
context | the context to wait in. |
wait_tick_ns | the time to wait between each iteration of the wait loop (in nanoseconds). |
std::runtime_error | if the context is invalid or clock is not rcl_clock_valid |
Definition at line 240 of file clock.cpp.
References Clock(), get_clock_handle(), now(), rcl_clock_valid(), RCL_STEADY_TIME, sleep_for(), and started().
bool rclcpp::Clock::wait_until_started | ( | Context::SharedPtr | context = contexts::get_global_default_context() | ) |
Wait until clock to start.
\rclcpp::Clock::started
context | the context to wait in |
std::runtime_error | if the context is invalid or clock is not rcl_clock_valid |
Definition at line 222 of file clock.cpp.
References get_clock_handle(), rcl_clock_valid(), sleep_until(), and started().