ROS 2 rclcpp + rcl - humble  humble
ROS 2 C++ Client Library with ROS Client Library
Public Member Functions | Protected Member Functions | List of all members
rclcpp::executors::StaticSingleThreadedExecutor Class Reference

Static executor implementation. More...

#include <rclcpp/executors/static_single_threaded_executor.hpp>

Inheritance diagram for rclcpp::executors::StaticSingleThreadedExecutor:
Inheritance graph
[legend]
Collaboration diagram for rclcpp::executors::StaticSingleThreadedExecutor:
Collaboration graph
[legend]

Public Member Functions

RCLCPP_PUBLIC StaticSingleThreadedExecutor (const rclcpp::ExecutorOptions &options=rclcpp::ExecutorOptions())
 Default constructor. See the default constructor for Executor.
 
virtual RCLCPP_PUBLIC ~StaticSingleThreadedExecutor ()
 Default destrcutor.
 
RCLCPP_PUBLIC void spin () override
 Static executor implementation of spin. More...
 
RCLCPP_PUBLIC void spin_some (std::chrono::nanoseconds max_duration=std::chrono::nanoseconds(0)) override
 Static executor implementation of spin some. More...
 
RCLCPP_PUBLIC void spin_all (std::chrono::nanoseconds max_duration) override
 Static executor implementation of spin all. More...
 
RCLCPP_PUBLIC void add_callback_group (rclcpp::CallbackGroup::SharedPtr group_ptr, rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr, bool notify=true) override
 Add a callback group to an executor. More...
 
RCLCPP_PUBLIC void remove_callback_group (rclcpp::CallbackGroup::SharedPtr group_ptr, bool notify=true) override
 Remove callback group from the executor. More...
 
RCLCPP_PUBLIC void add_node (rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr, bool notify=true) override
 Add a node to the executor. More...
 
RCLCPP_PUBLIC void add_node (std::shared_ptr< rclcpp::Node > node_ptr, bool notify=true) override
 Convenience function which takes Node and forwards NodeBaseInterface. More...
 
RCLCPP_PUBLIC void remove_node (rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr, bool notify=true) override
 Remove a node from the executor. More...
 
RCLCPP_PUBLIC void remove_node (std::shared_ptr< rclcpp::Node > node_ptr, bool notify=true) override
 Convenience function which takes Node and forwards NodeBaseInterface. More...
 
RCLCPP_PUBLIC std::vector< rclcpp::CallbackGroup::WeakPtr > get_all_callback_groups () override
 Get callback groups that belong to executor. More...
 
RCLCPP_PUBLIC std::vector< rclcpp::CallbackGroup::WeakPtr > get_manually_added_callback_groups () override
 Get callback groups that belong to executor. More...
 
RCLCPP_PUBLIC std::vector< rclcpp::CallbackGroup::WeakPtr > get_automatically_added_callback_groups_from_nodes () override
 Get callback groups that belong to executor. More...
 
- Public Member Functions inherited from rclcpp::Executor
RCLCPP_PUBLIC Executor (const rclcpp::ExecutorOptions &options=rclcpp::ExecutorOptions())
 Default constructor. More...
 
virtual RCLCPP_PUBLIC ~Executor ()
 Default destructor.
 
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.
 
RCLCPP_PUBLIC void spin_node_some (rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node)
 Add a node, complete all immediately available work, and remove the node. More...
 
RCLCPP_PUBLIC void spin_node_some (std::shared_ptr< rclcpp::Node > node)
 Convenience function which takes Node and forwards NodeBaseInterface.
 
virtual RCLCPP_PUBLIC void spin_once (std::chrono::nanoseconds timeout=std::chrono::nanoseconds(-1))
 
template<typename FutureT , typename TimeRepT = int64_t, typename TimeT = std::milli>
FutureReturnCode spin_until_future_complete (const FutureT &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...
 
RCLCPP_PUBLIC void cancel ()
 Cancel any running spin* function, causing it to return. More...
 
RCLCPP_PUBLIC void set_memory_strategy (memory_strategy::MemoryStrategy::SharedPtr memory_strategy)
 Support dynamic switching of the memory strategy. More...
 
RCLCPP_PUBLIC bool is_spinning ()
 Returns true if the executor is currently spinning. More...
 

Protected Member Functions

RCLCPP_PUBLIC bool execute_ready_executables (bool spin_once=false)
 Executes ready executables from wait set. More...
 
RCLCPP_PUBLIC void spin_some_impl (std::chrono::nanoseconds max_duration, bool exhaustive)
 
RCLCPP_PUBLIC void spin_once_impl (std::chrono::nanoseconds timeout) override
 
- Protected Member Functions inherited from rclcpp::Executor
RCLCPP_PUBLIC void spin_node_once_nanoseconds (rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node, std::chrono::nanoseconds timeout)
 
RCLCPP_PUBLIC void spin_some_impl (std::chrono::nanoseconds max_duration, bool exhaustive)
 
RCLCPP_PUBLIC void execute_any_executable (AnyExecutable &any_exec)
 Find the next available executable and do the work associated with it. More...
 
RCLCPP_PUBLIC void wait_for_work (std::chrono::nanoseconds timeout=std::chrono::nanoseconds(-1))
 
RCLCPP_PUBLIC rclcpp::node_interfaces::NodeBaseInterface::SharedPtr get_node_by_group (const WeakCallbackGroupsToNodesMap &weak_groups_to_nodes, rclcpp::CallbackGroup::SharedPtr group)
 
RCLCPP_PUBLIC bool has_node (const rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr, const WeakCallbackGroupsToNodesMap &weak_groups_to_nodes) const
 Return true if the node has been added to this executor. More...
 
RCLCPP_PUBLIC rclcpp::CallbackGroup::SharedPtr get_group_by_timer (rclcpp::TimerBase::SharedPtr timer)
 
virtual RCLCPP_PUBLIC void add_callback_group_to_map (rclcpp::CallbackGroup::SharedPtr group_ptr, rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr, WeakCallbackGroupsToNodesMap &weak_groups_to_nodes, bool notify=true) RCPPUTILS_TSA_REQUIRES(mutex_)
 Add a callback group to an executor. More...
 
virtual RCLCPP_PUBLIC void remove_callback_group_from_map (rclcpp::CallbackGroup::SharedPtr group_ptr, WeakCallbackGroupsToNodesMap &weak_groups_to_nodes, bool notify=true) RCPPUTILS_TSA_REQUIRES(mutex_)
 Remove a callback group from the executor. More...
 
RCLCPP_PUBLIC bool get_next_ready_executable (AnyExecutable &any_executable)
 
RCLCPP_PUBLIC bool get_next_ready_executable_from_map (AnyExecutable &any_executable, const WeakCallbackGroupsToNodesMap &weak_groups_to_nodes)
 
RCLCPP_PUBLIC bool get_next_executable (AnyExecutable &any_executable, std::chrono::nanoseconds timeout=std::chrono::nanoseconds(-1))
 
virtual RCLCPP_PUBLIC void add_callback_groups_from_nodes_associated_to_executor () RCPPUTILS_TSA_REQUIRES(mutex_)
 Add all callback groups that can be automatically added from associated nodes. More...
 
memory_strategy::MemoryStrategy::SharedPtr memory_strategy_ RCPPUTILS_TSA_PT_GUARDED_BY (mutex_)
 The memory strategy: an interface for handling user-defined memory allocation strategies.
 
WeakCallbackGroupsToGuardConditionsMap weak_groups_to_guard_conditions_ RCPPUTILS_TSA_GUARDED_BY (mutex_)
 maps callback groups to guard conditions
 
WeakCallbackGroupsToNodesMap weak_groups_associated_with_executor_to_nodes_ RCPPUTILS_TSA_GUARDED_BY (mutex_)
 maps callback groups associated to nodes
 
WeakCallbackGroupsToNodesMap weak_groups_to_nodes_associated_with_executor_ RCPPUTILS_TSA_GUARDED_BY (mutex_)
 maps callback groups to nodes associated with executor
 
WeakCallbackGroupsToNodesMap weak_groups_to_nodes_ RCPPUTILS_TSA_GUARDED_BY (mutex_)
 maps all callback groups to nodes
 
std::list< rclcpp::node_interfaces::NodeBaseInterface::WeakPtr > weak_nodes_ RCPPUTILS_TSA_GUARDED_BY (mutex_)
 nodes that are associated with the executor
 

Additional Inherited Members

- Protected Types inherited from rclcpp::Executor
typedef std::map< rclcpp::CallbackGroup::WeakPtr, const rclcpp::GuardCondition *, std::owner_less< rclcpp::CallbackGroup::WeakPtr > > WeakCallbackGroupsToGuardConditionsMap
 
- Static Protected Member Functions inherited from rclcpp::Executor
static RCLCPP_PUBLIC void execute_subscription (rclcpp::SubscriptionBase::SharedPtr subscription)
 
static RCLCPP_PUBLIC void execute_timer (rclcpp::TimerBase::SharedPtr timer)
 
static RCLCPP_PUBLIC void execute_service (rclcpp::ServiceBase::SharedPtr service)
 
static RCLCPP_PUBLIC void execute_client (rclcpp::ClientBase::SharedPtr client)
 
- Protected Attributes inherited from rclcpp::Executor
std::atomic_bool spinning
 Spinning state, used to prevent multi threaded calls to spin and to cancel blocking spins.
 
rclcpp::GuardCondition interrupt_guard_condition_
 Guard condition for signaling the rmw layer to wake up for special events.
 
std::shared_ptr< rclcpp::GuardConditionshutdown_guard_condition_
 
rcl_wait_set_t wait_set_ = rcl_get_zero_initialized_wait_set()
 Wait set for managing entities that the rmw layer waits on.
 
std::mutex mutex_
 
std::shared_ptr< rclcpp::Contextcontext_
 The context associated with this executor.
 
rclcpp::OnShutdownCallbackHandle shutdown_callback_handle_
 shutdown callback handle registered to Context
 

Detailed Description

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);

Definition at line 58 of file static_single_threaded_executor.hpp.

Member Function Documentation

◆ add_callback_group()

void StaticSingleThreadedExecutor::add_callback_group ( rclcpp::CallbackGroup::SharedPtr  group_ptr,
rclcpp::node_interfaces::NodeBaseInterface::SharedPtr  node_ptr,
bool  notify = true 
)
overridevirtual

Add a callback group to an executor.

See also
rclcpp::Executor::add_callback_group

Reimplemented from rclcpp::Executor.

Definition at line 134 of file static_single_threaded_executor.cpp.

References rclcpp::Executor::interrupt_guard_condition_, and rclcpp::GuardCondition::trigger().

Here is the call graph for this function:

◆ add_node() [1/2]

void StaticSingleThreadedExecutor::add_node ( rclcpp::node_interfaces::NodeBaseInterface::SharedPtr  node_ptr,
bool  notify = true 
)
overridevirtual

Add a node to the executor.

See also
rclcpp::Executor::add_node

Reimplemented from rclcpp::Executor.

Definition at line 147 of file static_single_threaded_executor.cpp.

References rclcpp::Executor::interrupt_guard_condition_, and rclcpp::GuardCondition::trigger().

Referenced by add_node().

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

◆ add_node() [2/2]

void StaticSingleThreadedExecutor::add_node ( std::shared_ptr< rclcpp::Node node_ptr,
bool  notify = true 
)
overridevirtual

Convenience function which takes Node and forwards NodeBaseInterface.

See also
rclcpp::StaticSingleThreadedExecutor::add_node

Reimplemented from rclcpp::Executor.

Definition at line 158 of file static_single_threaded_executor.cpp.

References add_node().

Here is the call graph for this function:

◆ execute_ready_executables()

bool StaticSingleThreadedExecutor::execute_ready_executables ( bool  spin_once = false)
protected

Executes ready executables from wait set.

Parameters
spin_onceif true executes only the first ready executable.
Returns
true if any executable was ready.

Definition at line 213 of file static_single_threaded_executor.cpp.

References rcl_wait_set_s::clients, rcl_wait_set_s::services, rcl_wait_set_s::size_of_clients, rcl_wait_set_s::size_of_services, rcl_wait_set_s::size_of_subscriptions, rcl_wait_set_s::size_of_timers, rcl_wait_set_s::subscriptions, rcl_wait_set_s::timers, and rclcpp::Executor::wait_set_.

Referenced by spin().

Here is the caller graph for this function:

◆ get_all_callback_groups()

std::vector< rclcpp::CallbackGroup::WeakPtr > StaticSingleThreadedExecutor::get_all_callback_groups ( )
overridevirtual

Get callback groups that belong to executor.

This function returns a vector of weak pointers that point to callback groups that were associated with the executor. The callback groups associated with this executor may have been added with add_callback_group, or added when a node was added to the executor with add_node, or automatically added when it created by a node already associated with this executor and the automatically_add_to_executor_with_node parameter was true.

Returns
a vector of weak pointers that point to callback groups that are associated with the executor

Reimplemented from rclcpp::Executor.

Definition at line 189 of file static_single_threaded_executor.cpp.

◆ get_automatically_added_callback_groups_from_nodes()

std::vector< rclcpp::CallbackGroup::WeakPtr > StaticSingleThreadedExecutor::get_automatically_added_callback_groups_from_nodes ( )
overridevirtual

Get callback groups that belong to executor.

See also
rclcpp::Executor::get_automatically_added_callback_groups_from_nodes()

Reimplemented from rclcpp::Executor.

Definition at line 201 of file static_single_threaded_executor.cpp.

◆ get_manually_added_callback_groups()

std::vector< rclcpp::CallbackGroup::WeakPtr > StaticSingleThreadedExecutor::get_manually_added_callback_groups ( )
overridevirtual

Get callback groups that belong to executor.

See also
rclcpp::Executor::get_manually_added_callback_groups()

Reimplemented from rclcpp::Executor.

Definition at line 195 of file static_single_threaded_executor.cpp.

◆ remove_callback_group()

void StaticSingleThreadedExecutor::remove_callback_group ( rclcpp::CallbackGroup::SharedPtr  group_ptr,
bool  notify = true 
)
overridevirtual

Remove callback group from the executor.

See also
rclcpp::Executor::remove_callback_group

Reimplemented from rclcpp::Executor.

Definition at line 164 of file static_single_threaded_executor.cpp.

References rclcpp::Executor::interrupt_guard_condition_, and rclcpp::GuardCondition::trigger().

Here is the call graph for this function:

◆ remove_node() [1/2]

void StaticSingleThreadedExecutor::remove_node ( rclcpp::node_interfaces::NodeBaseInterface::SharedPtr  node_ptr,
bool  notify = true 
)
overridevirtual

Remove a node from the executor.

See also
rclcpp::Executor::remove_node

Reimplemented from rclcpp::Executor.

Definition at line 175 of file static_single_threaded_executor.cpp.

References rclcpp::Executor::interrupt_guard_condition_, and rclcpp::GuardCondition::trigger().

Referenced by remove_node().

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

◆ remove_node() [2/2]

void StaticSingleThreadedExecutor::remove_node ( std::shared_ptr< rclcpp::Node node_ptr,
bool  notify = true 
)
overridevirtual

Convenience function which takes Node and forwards NodeBaseInterface.

See also
rclcpp::Executor::remove_node

Reimplemented from rclcpp::Executor.

Definition at line 207 of file static_single_threaded_executor.cpp.

References remove_node().

Here is the call graph for this function:

◆ spin()

void StaticSingleThreadedExecutor::spin ( )
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).

Exceptions
std::runtime_errorwhen spin() called while already spinning

Implements rclcpp::Executor.

Definition at line 42 of file static_single_threaded_executor.cpp.

References rclcpp::Executor::context_, execute_ready_executables(), rclcpp::ok(), rclcpp::Executor::spinning, and rclcpp::Executor::wait_set_.

Here is the call graph for this function:

◆ spin_all()

void StaticSingleThreadedExecutor::spin_all ( std::chrono::nanoseconds  max_duration)
overridevirtual

Static executor implementation of spin all.

This non-blocking function will execute entities until timeout (must be >= 0) or no more work available. If timeout is 0, potentially it blocks forever until no more work is available. If new entities get ready while executing work available, they will be executed as long as the timeout hasn't expired.

Example: while(condition) { spin_all(); sleep(); // User should have some sync work or // sleep to avoid a 100% CPU usage }

Reimplemented from rclcpp::Executor.

Definition at line 72 of file static_single_threaded_executor.cpp.

◆ spin_some()

void StaticSingleThreadedExecutor::spin_some ( std::chrono::nanoseconds  max_duration = std::chrono::nanoseconds(0))
overridevirtual

Static executor implementation of spin some.

This non-blocking function will execute entities that were ready when this API was called, until timeout or no more work available. Entities that got ready while executing work, won't be taken into account here.

Example: while(condition) { spin_some(); sleep(); // User should have some sync work or // sleep to avoid a 100% CPU usage }

Reimplemented from rclcpp::Executor.

Definition at line 61 of file static_single_threaded_executor.cpp.


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