rclcpp
master
C++ ROS Client Library API
|
Coordinate the order and timing of available communication tasks. More...
#include <executor.hpp>
Public Member Functions | |
Executor (const ExecutorArgs &args=ExecutorArgs()) | |
Default constructor. More... | |
virtual | ~Executor () |
Default destructor. More... | |
virtual void | spin ()=0 |
Do work periodically as it becomes available to us. Blocking call, may block indefinitely. More... | |
virtual void | add_node (rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr, bool notify=true) |
Add a node to the executor. More... | |
virtual void | add_node (std::shared_ptr< rclcpp::Node > node_ptr, bool notify=true) |
Convenience function which takes Node and forwards NodeBaseInterface. More... | |
virtual void | remove_node (rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr, bool notify=true) |
Remove a node from the executor. More... | |
virtual void | remove_node (std::shared_ptr< rclcpp::Node > node_ptr, bool notify=true) |
Convenience function which takes Node and forwards NodeBaseInterface. More... | |
template<typename T = std::milli> | |
void | spin_node_once (rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node, std::chrono::duration< int64_t, T > timeout=std::chrono::duration< int64_t, T >(-1)) |
Add a node to executor, execute the next available unit of work, and remove the node. More... | |
template<typename NodeT = rclcpp::Node, typename T = std::milli> | |
void | spin_node_once (std::shared_ptr< NodeT > node, std::chrono::duration< int64_t, T > timeout=std::chrono::duration< int64_t, T >(-1)) |
Convenience function which takes Node and forwards NodeBaseInterface. More... | |
void | spin_node_some (rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node) |
Add a node, complete all immediately available work, and remove the node. More... | |
void | spin_node_some (std::shared_ptr< rclcpp::Node > node) |
Convenience function which takes Node and forwards NodeBaseInterface. More... | |
virtual void | spin_some (std::chrono::nanoseconds max_duration=std::chrono::nanoseconds(0)) |
Complete all available queued work without blocking. More... | |
virtual void | spin_once (std::chrono::nanoseconds timeout=std::chrono::nanoseconds(-1)) |
template<typename ResponseT , typename TimeT = std::milli> | |
FutureReturnCode | spin_until_future_complete (std::shared_future< ResponseT > &future, std::chrono::duration< int64_t, TimeT > timeout=std::chrono::duration< int64_t, TimeT >(-1)) |
Spin (blocking) until the future is complete, it times out waiting, or rclcpp is interrupted. More... | |
void | cancel () |
Cancel any running spin* function, causing it to return. More... | |
void | set_memory_strategy (memory_strategy::MemoryStrategy::SharedPtr memory_strategy) |
Support dynamic switching of the memory strategy. More... | |
Protected Member Functions | |
void | spin_node_once_nanoseconds (rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node, std::chrono::nanoseconds timeout) |
void | execute_any_executable (AnyExecutable &any_exec) |
Find the next available executable and do the work associated with it. More... | |
void | wait_for_work (std::chrono::nanoseconds timeout=std::chrono::nanoseconds(-1)) |
rclcpp::node_interfaces::NodeBaseInterface::SharedPtr | get_node_by_group (rclcpp::callback_group::CallbackGroup::SharedPtr group) |
rclcpp::callback_group::CallbackGroup::SharedPtr | get_group_by_timer (rclcpp::TimerBase::SharedPtr timer) |
void | get_next_timer (AnyExecutable &any_exec) |
bool | get_next_ready_executable (AnyExecutable &any_executable) |
bool | get_next_executable (AnyExecutable &any_executable, std::chrono::nanoseconds timeout=std::chrono::nanoseconds(-1)) |
Static Protected Member Functions | |
static void | execute_subscription (rclcpp::SubscriptionBase::SharedPtr subscription) |
static void | execute_intra_process_subscription (rclcpp::SubscriptionBase::SharedPtr subscription) |
static void | execute_timer (rclcpp::TimerBase::SharedPtr timer) |
static void | execute_service (rclcpp::ServiceBase::SharedPtr service) |
static void | execute_client (rclcpp::ClientBase::SharedPtr client) |
Protected Attributes | |
std::atomic_bool | spinning |
Spinning state, used to prevent multi threaded calls to spin and to cancel blocking spins. More... | |
rcl_guard_condition_t | interrupt_guard_condition_ = rcl_get_zero_initialized_guard_condition() |
Guard condition for signaling the rmw layer to wake up for special events. More... | |
rcl_wait_set_t | wait_set_ = rcl_get_zero_initialized_wait_set() |
Wait set for managing entities that the rmw layer waits on. More... | |
memory_strategy::MemoryStrategy::SharedPtr | memory_strategy_ |
The memory strategy: an interface for handling user-defined memory allocation strategies. More... | |
std::shared_ptr< rclcpp::Context > | context_ |
The context associated with this executor. More... | |
Coordinate the order and timing of available communication tasks.
Executor provides spin functions (including spin_node_once and spin_some). It coordinates the nodes and callback groups by looking for available work and completing it, based on the threading or concurrency scheme provided by the subclass implementation. An example of available work is executing a subscription callback, or a timer callback. The executor structure allows for a decoupling of the communication graph and the execution model. See SingleThreadedExecutor and MultiThreadedExecutor for examples of execution paradigms.
|
explicit |
Default constructor.
|
virtual |
Default destructor.
|
pure virtual |
Do work periodically as it becomes available to us. Blocking call, may block indefinitely.
Implemented in rclcpp::executors::MultiThreadedExecutor, and rclcpp::executors::SingleThreadedExecutor.
|
virtual |
Add a node to the executor.
An executor can have zero or more nodes which provide work during spin
functions.
[in] | node_ptr | Shared pointer to the node to be added. |
[in] | notify | True to trigger the interrupt guard condition during this function. If the executor is blocked at the rmw layer while waiting for work and it is notified that a new node was added, it will wake up. |
|
virtual |
Convenience function which takes Node and forwards NodeBaseInterface.
|
virtual |
Remove a node from the executor.
[in] | node_ptr | Shared pointer to the node to remove. |
[in] | notify | True to trigger the interrupt guard condition and wake up the executor. This is useful if the last node was removed from the executor while the executor was blocked waiting for work in another thread, because otherwise the executor would never be notified. |
|
virtual |
Convenience function which takes Node and forwards NodeBaseInterface.
|
inline |
Add a node to executor, execute the next available unit of work, and remove the node.
[in] | node | Shared pointer to the node to add. |
[in] | timeout | How long to wait for work to become available. Negative values cause spin_node_once to block indefinitely (the default behavior). A timeout of 0 causes this function to be non-blocking. |
|
inline |
Convenience function which takes Node and forwards NodeBaseInterface.
void rclcpp::executor::Executor::spin_node_some | ( | rclcpp::node_interfaces::NodeBaseInterface::SharedPtr | node | ) |
Add a node, complete all immediately available work, and remove the node.
[in] | node | Shared pointer to the node to add. |
void rclcpp::executor::Executor::spin_node_some | ( | std::shared_ptr< rclcpp::Node > | node | ) |
Convenience function which takes Node and forwards NodeBaseInterface.
|
virtual |
Complete all available queued work without blocking.
This function can be overridden. The default implementation is suitable for a single-threaded model of execution. Adding subscriptions, timers, services, etc. with blocking callbacks will cause this function to block (which may have unintended consequences).
[in] | max_duration | The maximum amount of time to spend executing work, or 0 for no limit. Note that spin_some() may take longer than this time as it only returns once max_duration has been exceeded. |
|
virtual |
|
inline |
Spin (blocking) until the future is complete, it times out waiting, or rclcpp is interrupted.
[in] | future | The future to wait on. If SUCCESS, the future is safe to access after this function. |
[in] | timeout | Optional timeout parameter, which gets passed to Executor::spin_node_once. -1 is block forever, 0 is non-blocking. If the time spent inside the blocking loop exceeds this timeout, return a TIMEOUT return code. |
SUCCESS
, INTERRUPTED
, or TIMEOUT
. void rclcpp::executor::Executor::cancel | ( | ) |
Cancel any running spin* function, causing it to return.
void rclcpp::executor::Executor::set_memory_strategy | ( | memory_strategy::MemoryStrategy::SharedPtr | memory_strategy | ) |
Support dynamic switching of the memory strategy.
Switching the memory strategy while the executor is spinning in another threading could have unintended consequences.
[in] | memory_strategy | Shared pointer to the memory strategy to set. |
|
protected |
|
protected |
Find the next available executable and do the work associated with it.
[in] | any_exec | Union structure that can hold any executable type (timer, subscription, service, client). |
|
staticprotected |
|
staticprotected |
|
staticprotected |
|
staticprotected |
|
staticprotected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
Spinning state, used to prevent multi threaded calls to spin and to cancel blocking spins.
|
protected |
Guard condition for signaling the rmw layer to wake up for special events.
|
protected |
Wait set for managing entities that the rmw layer waits on.
|
protected |
The memory strategy: an interface for handling user-defined memory allocation strategies.
|
protected |
The context associated with this executor.