From c29150e73d96d33bf5a6ad95ab947f0694a8b188 Mon Sep 17 00:00:00 2001 From: Skyler Medeiros Date: Wed, 8 Apr 2026 17:22:45 -0700 Subject: [PATCH 1/2] add callback group events executor component container Signed-off-by: Skyler Medeiros --- rclcpp_components/CMakeLists.txt | 6 +++ .../src/component_container_cbg.cpp | 42 +++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 rclcpp_components/src/component_container_cbg.cpp diff --git a/rclcpp_components/CMakeLists.txt b/rclcpp_components/CMakeLists.txt index 9fdcf55511..a22376e5ef 100644 --- a/rclcpp_components/CMakeLists.txt +++ b/rclcpp_components/CMakeLists.txt @@ -66,6 +66,12 @@ add_executable( ) target_link_libraries(component_container_event PRIVATE component_manager rclcpp::rclcpp) +add_executable( + component_container_cbg + src/component_container_cbg.cpp +) +target_link_libraries(component_container_cbg PRIVATE component_manager rclcpp::rclcpp) + set(node_main_template_install_dir "share/${PROJECT_NAME}") install(FILES src/node_main.cpp.in diff --git a/rclcpp_components/src/component_container_cbg.cpp b/rclcpp_components/src/component_container_cbg.cpp new file mode 100644 index 0000000000..51457cc893 --- /dev/null +++ b/rclcpp_components/src/component_container_cbg.cpp @@ -0,0 +1,42 @@ +// Copyright 2026 Open Source Robotics Foundation, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include + +#include "rclcpp/utilities.hpp" +#include "rclcpp/executors/events_cbg_executor/events_cbg_executor.hpp" + +#include "rclcpp_components/component_manager.hpp" + +int main(int argc, char * argv[]) +{ + /// Component container with an events executor. + rclcpp::init(argc, argv); + rclcpp::executors::EventsCBGExecutor::SharedPtr exec = nullptr; + + auto node = std::make_shared(); + + if (node->has_parameter("thread_num")) { + const auto thread_num = node->get_parameter("thread_num").as_int(); + exec = std::make_shared( + rclcpp::ExecutorOptions{}, thread_num); + } else { + exec = std::make_shared(); + } + node->set_executor(exec); + exec->add_node(node); + exec->spin(); + + return 0; +} From 98e22c4840d79a67638efc2e4e3e55fae7027b7d Mon Sep 17 00:00:00 2001 From: Skyler Medeiros Date: Wed, 8 Apr 2026 17:23:32 -0700 Subject: [PATCH 2/2] Add EventsExecutor and EventsCBGExecutor to isolated component container Signed-off-by: Skyler Medeiros --- .../src/component_container_isolated.cpp | 64 ++++++++++++++----- 1 file changed, 49 insertions(+), 15 deletions(-) diff --git a/rclcpp_components/src/component_container_isolated.cpp b/rclcpp_components/src/component_container_isolated.cpp index dbb4c134eb..48e1cecf91 100644 --- a/rclcpp_components/src/component_container_isolated.cpp +++ b/rclcpp_components/src/component_container_isolated.cpp @@ -13,41 +13,75 @@ // limitations under the License. #include -#include #include +#include #include "rclcpp/executors/single_threaded_executor.hpp" #include "rclcpp/executors/multi_threaded_executor.hpp" +#include "rclcpp/experimental/executors/events_executor/events_executor.hpp" +#include "rclcpp/executors/events_cbg_executor/events_cbg_executor.hpp" #include "rclcpp/utilities.hpp" #include "rclcpp_components/component_manager_isolated.hpp" int main(int argc, char * argv[]) { - /// Component container with dedicated single-threaded executors for each components. + /// Component container with dedicated executor for each component rclcpp::init(argc, argv); + // parse arguments - bool use_multi_threaded_executor{false}; + // valid entries: --executor-type single-threaded, --executor-type multi-threaded, --executor-type events std::vector args = rclcpp::remove_ros_arguments(argc, argv); - for (auto & arg : args) { - if (arg == std::string("--use_multi_threaded_executor")) { - use_multi_threaded_executor = true; + rclcpp::Node::SharedPtr node; + + std::string executor_type = "single-threaded"; // default + for (size_t i = 0; i < args.size(); ++i) { + if (args[i] == "--executor-type") { + if (i + 1 < args.size()) { + executor_type = args[i + 1]; + break; + } + } else if (args[i] == "--use_multi_threaded_executor") { // backward compatibility + RCLCPP_WARN(node->get_logger(), + "--use_multi_threaded_executor is deprecated, use --executor-type multi-threaded instead."); + executor_type = "multi-threaded"; } } + // create executor and component manager - auto exec = std::make_shared(); - rclcpp::Node::SharedPtr node; - if (use_multi_threaded_executor) { - using ComponentManagerIsolated = - rclcpp_components::ComponentManagerIsolated; + std::shared_ptr exec; + if (executor_type == "events") { + using executor = rclcpp::experimental::executors::EventsExecutor; + using ComponentManagerIsolated = rclcpp_components::ComponentManagerIsolated; + exec = std::make_shared(); node = std::make_shared(exec); - } else { - using ComponentManagerIsolated = - rclcpp_components::ComponentManagerIsolated; + } else if (executor_type == "cbg-single-threaded") { + using executor = rclcpp::executors::EventsCBGExecutor; + using ComponentManagerIsolated = rclcpp_components::ComponentManagerIsolated; + exec = std::make_shared(rclcpp::ExecutorOptions(), 1); + node = std::make_shared(exec); + } else if (executor_type == "cbg-multi-threaded") { + using executor = rclcpp::executors::EventsCBGExecutor; + using ComponentManagerIsolated = rclcpp_components::ComponentManagerIsolated; + exec = std::make_shared(); + node = std::make_shared(exec); + } else if (executor_type == "multi-threaded") { + using executor = rclcpp::executors::MultiThreadedExecutor; + using ComponentManagerIsolated = rclcpp_components::ComponentManagerIsolated; + exec = std::make_shared(); node = std::make_shared(exec); + } else if (executor_type == "single-threaded") { + using executor = rclcpp::executors::SingleThreadedExecutor; + using ComponentManagerIsolated = rclcpp_components::ComponentManagerIsolated; + exec = std::make_shared(); + node = std::make_shared(exec); + } else { + std::cerr << "Invalid executor type: " << executor_type << std::endl; + return 1; } + exec->add_node(node); exec->spin(); return 0; -} +} \ No newline at end of file