rclcpp
master
C++ ROS Client Library API
|
Static executor implementation. More...
#include <static_single_threaded_executor.hpp>
Public Member Functions | |
StaticSingleThreadedExecutor (const rclcpp::ExecutorOptions &options=rclcpp::ExecutorOptions()) | |
Default constructor. See the default constructor for Executor. More... | |
virtual | ~StaticSingleThreadedExecutor () |
Default destrcutor. More... | |
void | spin () override |
Static executor implementation of spin. More... | |
void | add_node (rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr, bool notify=true) override |
Add a node to the executor. More... | |
void | add_node (std::shared_ptr< rclcpp::Node > node_ptr, bool notify=true) override |
Convenience function which takes Node and forwards NodeBaseInterface. More... | |
void | remove_node (rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr, bool notify=true) override |
Remove a node from the executor. More... | |
void | remove_node (std::shared_ptr< rclcpp::Node > node_ptr, bool notify=true) override |
Convenience function which takes Node and forwards NodeBaseInterface. More... | |
template<typename ResponseT , typename TimeRepT = int64_t, typename TimeT = std::milli> | |
rclcpp::FutureReturnCode | spin_until_future_complete (std::shared_future< ResponseT > &future, std::chrono::duration< TimeRepT, TimeT > timeout=std::chrono::duration< TimeRepT, TimeT >(-1)) |
Spin (blocking) until the future is complete, it times out waiting, or rclcpp is interrupted. More... | |
![]() | |
Executor (const rclcpp::ExecutorOptions &options=rclcpp::ExecutorOptions()) | |
Default constructor. More... | |
virtual | ~Executor () |
Default destructor. More... | |
template<typename RepT = int64_t, typename T = std::milli> | |
void | spin_node_once (rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node, std::chrono::duration< RepT, T > timeout=std::chrono::duration< RepT, 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 RepT = int64_t, typename T = std::milli> | |
void | spin_node_once (std::shared_ptr< NodeT > node, std::chrono::duration< RepT, T > timeout=std::chrono::duration< RepT, 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 TimeRepT = int64_t, typename TimeT = std::milli> | |
FutureReturnCode | spin_until_future_complete (const std::shared_future< ResponseT > &future, std::chrono::duration< TimeRepT, TimeT > timeout=std::chrono::duration< TimeRepT, 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 | execute_ready_executables () |
Check which executables in ExecutableList struct are ready from wait_set and execute them. More... | |
![]() | |
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::CallbackGroup::SharedPtr group) |
rclcpp::CallbackGroup::SharedPtr | get_group_by_timer (rclcpp::TimerBase::SharedPtr timer) |
bool | get_next_ready_executable (AnyExecutable &any_executable) |
bool | get_next_executable (AnyExecutable &any_executable, std::chrono::nanoseconds timeout=std::chrono::nanoseconds(-1)) |
Additional Inherited Members | |
![]() | |
static void | execute_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) |
![]() | |
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... | |
std::mutex | memory_strategy_mutex_ |
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... | |
std::list< rclcpp::node_interfaces::NodeBaseInterface::WeakPtr > | weak_nodes_ |
std::list< const rcl_guard_condition_t * > | guard_conditions_ |
Static executor implementation.
This executor is a static version of the original single threaded executor. It's static because it doesn't reconstruct the executable list for every iteration. All nodes, callbackgroups, timers, subscriptions etc. are created before spin() is called, and modified only when an entity is added/removed to/from a node.
To run this executor instead of SingleThreadedExecutor replace: rclcpp::executors::SingleThreadedExecutor exec; by rclcpp::executors::StaticSingleThreadedExecutor exec; in your source code and spin node(s) in the following way: exec.add_node(node); exec.spin(); exec.remove_node(node);
|
explicit |
Default constructor. See the default constructor for Executor.
|
virtual |
Default destrcutor.
|
overridevirtual |
Static executor implementation of spin.
This function will block until work comes in, execute it, and keep blocking. It will only be interrupted by a CTRL-C (managed by the global signal handler).
std::runtime_error | when spin() called while already spinning |
Implements rclcpp::Executor.
|
overridevirtual |
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. |
std::runtime_error | if node was already added or if rcl_trigger_guard_condition return an error |
Reimplemented from rclcpp::Executor.
|
overridevirtual |
Convenience function which takes Node and forwards NodeBaseInterface.
std::runtime_error | if node was already added or if rcl_trigger_guard_condition returns an error |
Reimplemented from rclcpp::Executor.
|
overridevirtual |
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. |
std::runtime_error | if rcl_trigger_guard_condition returns an error |
Reimplemented from rclcpp::Executor.
|
overridevirtual |
Convenience function which takes Node and forwards NodeBaseInterface.
std::runtime_error | if rcl_trigger_guard_condition returns an error |
Reimplemented from rclcpp::Executor.
|
inline |
Spin (blocking) until the future is complete, it times out waiting, or rclcpp is interrupted.
[in] | future | The future to wait on. If this function returns SUCCESS, the future can be accessed without blocking (though it may still throw an exception). |
[in] | timeout | Optional timeout parameter, which gets passed to Executor::execute_ready_executables. -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
.Example usage: rclcpp::executors::StaticSingleThreadedExecutor exec; // ... other part of code like creating node // define future exec.add_node(node); exec.spin_until_future_complete(future);
|
protected |
Check which executables in ExecutableList struct are ready from wait_set and execute them.
[in] | exec_list | Structure that can hold subscriptionbases, timerbases, etc |
[in] | timeout | Optional timeout parameter. |