rclcpp
master
C++ ROS Client Library API
|
Go to the documentation of this file.
15 #ifndef RCLCPP__EXECUTOR_HPP_
16 #define RCLCPP__EXECUTOR_HPP_
48 typedef std::map<rclcpp::CallbackGroup::WeakPtr,
49 rclcpp::node_interfaces::NodeBaseInterface::WeakPtr,
106 rclcpp::CallbackGroup::SharedPtr group_ptr,
107 rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr,
177 rclcpp::CallbackGroup::SharedPtr group_ptr,
201 add_node(rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr,
bool notify =
true);
229 remove_node(rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr,
bool notify =
true);
246 template<
typename RepT =
int64_t,
typename T = std::milli>
249 rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node,
254 std::chrono::duration_cast<std::chrono::nanoseconds>(timeout)
259 template<
typename NodeT = rclcpp::Node,
typename RepT =
int64_t,
typename T = std::milli>
266 node->get_node_base_interface(),
267 std::chrono::duration_cast<std::chrono::nanoseconds>(timeout)
277 spin_node_some(rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node);
330 template<
typename FutureT,
typename TimeRepT =
int64_t,
typename TimeT = std::milli>
333 const FutureT & future,
342 if (status == std::future_status::ready) {
350 end_time += timeout_ns;
355 throw std::runtime_error(
"spin_until_future_complete() called while already spinning");
364 if (status == std::future_status::ready) {
373 if (now >= end_time) {
377 timeout_left = std::chrono::duration_cast<std::chrono::nanoseconds>(end_time - now);
408 rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node,
428 rclcpp::SubscriptionBase::SharedPtr subscription);
450 rclcpp::node_interfaces::NodeBaseInterface::SharedPtr
453 rclcpp::CallbackGroup::SharedPtr group);
463 const rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr,
467 rclcpp::CallbackGroup::SharedPtr
477 rclcpp::CallbackGroup::SharedPtr group_ptr,
478 rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr,
480 bool notify =
true) RCPPUTILS_TSA_REQUIRES(
mutex_);
491 bool notify = true) RCPPUTILS_TSA_REQUIRES(
mutex_);
539 memory_strategy::MemoryStrategy::SharedPtr
551 typedef
std::map<
rclcpp::node_interfaces::NodeBaseInterface::WeakPtr,
553 std::owner_less<
rclcpp::node_interfaces::NodeBaseInterface::WeakPtr>>
573 std::list<
rclcpp::node_interfaces::NodeBaseInterface::WeakPtr>
582 #endif // RCLCPP__EXECUTOR_HPP_
virtual void spin_some(std::chrono::nanoseconds max_duration=std::chrono::nanoseconds(0))
Collect work once and execute all available work, optionally within a duration.
A condition that can be waited on in a single wait set and asynchronously triggered.
Definition: guard_condition.hpp:31
void spin_node_once_nanoseconds(rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node, std::chrono::nanoseconds timeout)
FutureReturnCode
Return codes to be used with spin_until_future_complete.
Definition: future_return_code.hpp:33
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.
Definition: executor.hpp:248
virtual 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.
#define RCLCPP_DISABLE_COPY(...)
Definition: macros.hpp:26
rcl_guard_condition_t interrupt_guard_condition_
Guard condition for signaling the rmw layer to wake up for special events.
Definition: executor.hpp:528
virtual void spin_once(std::chrono::nanoseconds timeout=std::chrono::nanoseconds(-1))
static void execute_client(rclcpp::ClientBase::SharedPtr client)
virtual void spin()=0
Do work periodically as it becomes available to us. Blocking call, may block indefinitely.
virtual 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.
std::map< rclcpp::CallbackGroup::WeakPtr, rclcpp::node_interfaces::NodeBaseInterface::WeakPtr, std::owner_less< rclcpp::CallbackGroup::WeakPtr > > WeakCallbackGroupsToNodesMap
Definition: executor.hpp:50
void execute_any_executable(AnyExecutable &any_exec)
Find the next available executable and do the work associated with it.
Coordinate the order and timing of available communication tasks.
Definition: executor.hpp:65
Definition: context.hpp:51
virtual std::vector< rclcpp::CallbackGroup::WeakPtr > get_manually_added_callback_groups()
Get callback groups that belong to executor.
void cancel()
Cancel any running spin* function, causing it to return.
bool ok(rclcpp::Context::SharedPtr context=nullptr)
Check rclcpp's status.
This header provides the get_node_base_interface() template function.
Definition: allocator_common.hpp:24
#define RCLCPP_PUBLIC
Definition: visibility_control.hpp:50
WeakNodesToGuardConditionsMap weak_nodes_to_guard_conditions_ RCPPUTILS_TSA_GUARDED_BY(mutex_)
maps nodes to guard conditions
rclcpp::CallbackGroup::SharedPtr get_group_by_timer(rclcpp::TimerBase::SharedPtr timer)
static void execute_timer(rclcpp::TimerBase::SharedPtr timer)
memory_strategy::MemoryStrategy::SharedPtr memory_strategy_ RCPPUTILS_TSA_PT_GUARDED_BY(mutex_)
The memory strategy: an interface for handling user-defined memory allocation strategies.
bool get_next_ready_executable_from_map(AnyExecutable &any_executable, const WeakCallbackGroupsToNodesMap &weak_groups_to_nodes)
Node is the single point of entry for creating publishers and subscribers.
Definition: node.hpp:77
static void execute_service(rclcpp::ServiceBase::SharedPtr service)
Options to be passed to the executor constructor.
Definition: executor_options.hpp:28
rclcpp::OnShutdownCallbackHandle shutdown_callback_handle_
shutdown callback handle registered to Context
Definition: executor.hpp:577
virtual void remove_node(rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr, bool notify=true)
Remove a node from the executor.
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.
Definition: executor.hpp:332
void wait_for_work(std::chrono::nanoseconds timeout=std::chrono::nanoseconds(-1))
virtual ~Executor()
Default destructor.
Definition: any_executable.hpp:33
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.
Definition: executor.hpp:261
#define RCLCPP_SCOPE_EXIT(code)
Definition: scope_exit.hpp:49
virtual void add_node(rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr, bool notify=true)
Add a node to the executor.
bool get_next_executable(AnyExecutable &any_executable, std::chrono::nanoseconds timeout=std::chrono::nanoseconds(-1))
virtual std::vector< rclcpp::CallbackGroup::WeakPtr > get_all_callback_groups()
Get callback groups that belong to executor.
Executor(const rclcpp::ExecutorOptions &options=rclcpp::ExecutorOptions())
Default constructor.
rclcpp::node_interfaces::NodeBaseInterface::SharedPtr get_node_by_group(const WeakCallbackGroupsToNodesMap &weak_groups_to_nodes, rclcpp::CallbackGroup::SharedPtr group)
void set_memory_strategy(memory_strategy::MemoryStrategy::SharedPtr memory_strategy)
Support dynamic switching of the memory strategy.
bool get_next_ready_executable(AnyExecutable &any_executable)
Context which encapsulates shared state between nodes and other similar entities.
Definition: context.hpp:68
rcl_wait_set_t wait_set_
Wait set for managing entities that the rmw layer waits on.
Definition: executor.hpp:533
virtual void add_callback_group(rclcpp::CallbackGroup::SharedPtr group_ptr, rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr, bool notify=true)
Add a callback group to an executor.
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.
void spin_some_impl(std::chrono::nanoseconds max_duration, bool exhaustive)
virtual std::vector< rclcpp::CallbackGroup::WeakPtr > get_automatically_added_callback_groups_from_nodes()
Get callback groups that belong to executor.
virtual void remove_callback_group(rclcpp::CallbackGroup::SharedPtr group_ptr, bool notify=true)
Remove a callback group from the executor.
std::mutex mutex_
Definition: executor.hpp:536
#define RCLCPP_SMART_PTR_DEFINITIONS_NOT_COPYABLE(...)
Definition: macros.hpp:51
std::shared_ptr< rclcpp::GuardCondition > shutdown_guard_condition_
Definition: executor.hpp:530
Definition: callback_group.hpp:49
void spin_node_some(rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node)
Add a node, complete all immediately available work, and remove the node.
virtual 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.
std::atomic_bool spinning
Spinning state, used to prevent multi threaded calls to spin and to cancel blocking spins.
Definition: executor.hpp:525
virtual void spin_all(std::chrono::nanoseconds max_duration)
Collect and execute work repeatedly within a duration or until no more work is available.
std::shared_ptr< rclcpp::Context > context_
The context associated with this executor.
Definition: executor.hpp:543
virtual void spin_once_impl(std::chrono::nanoseconds timeout)
static void execute_subscription(rclcpp::SubscriptionBase::SharedPtr subscription)