From 779873008e6f977524e8d079bf5892cc437fb657 Mon Sep 17 00:00:00 2001 From: Tim Clephas Date: Mon, 27 May 2024 11:30:10 +0200 Subject: [PATCH 1/4] Add option for the events executor to the isolated component container Signed-off-by: Tim Clephas --- .../src/component_container_isolated.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/rclcpp_components/src/component_container_isolated.cpp b/rclcpp_components/src/component_container_isolated.cpp index dbb4c134eb..05ba25d63e 100644 --- a/rclcpp_components/src/component_container_isolated.cpp +++ b/rclcpp_components/src/component_container_isolated.cpp @@ -28,10 +28,15 @@ int main(int argc, char * argv[]) rclcpp::init(argc, argv); // parse arguments bool use_multi_threaded_executor{false}; + bool use_events_executor{false}; std::vector args = rclcpp::remove_ros_arguments(argc, argv); for (auto & arg : args) { - if (arg == std::string("--use_multi_threaded_executor")) { + if (arg == std::string("--use_multi_threaded_executor") || + arg == std::string("--use-multi-threaded-executor")) + { use_multi_threaded_executor = true; + } else if (arg == std::string("--use-events-executor")) { + use_events_executor = true; } } // create executor and component manager @@ -41,6 +46,10 @@ int main(int argc, char * argv[]) using ComponentManagerIsolated = rclcpp_components::ComponentManagerIsolated; node = std::make_shared(exec); + } else if (use_events_executor) { + using ComponentManagerIsolated = + rclcpp_components::ComponentManagerIsolated; + node = std::make_shared(exec); } else { using ComponentManagerIsolated = rclcpp_components::ComponentManagerIsolated; From 6f0fb6d92094d6a965ba6a6861a792418a573528 Mon Sep 17 00:00:00 2001 From: Tim Clephas Date: Mon, 24 Jun 2024 08:54:41 +0200 Subject: [PATCH 2/4] Parse '--executor-type' Signed-off-by: Tim Clephas --- .../src/component_container_isolated.cpp | 54 ++++++++++++------- 1 file changed, 34 insertions(+), 20 deletions(-) diff --git a/rclcpp_components/src/component_container_isolated.cpp b/rclcpp_components/src/component_container_isolated.cpp index 05ba25d63e..77eb51c423 100644 --- a/rclcpp_components/src/component_container_isolated.cpp +++ b/rclcpp_components/src/component_container_isolated.cpp @@ -13,8 +13,8 @@ // limitations under the License. #include -#include #include +#include #include "rclcpp/executors/single_threaded_executor.hpp" #include "rclcpp/executors/multi_threaded_executor.hpp" @@ -24,37 +24,51 @@ 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}; - bool use_events_executor{false}; + // valid entries: --executor-type single-threaded, --executor-type multi-threaded, --executor-type events + // --use-multi-threaded-executor and --use_multi_threaded_executor are kept for backward compatibility std::vector args = rclcpp::remove_ros_arguments(argc, argv); - for (auto & arg : args) { - if (arg == std::string("--use_multi_threaded_executor") || - arg == std::string("--use-multi-threaded-executor")) + + 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" || args[i] == "--use_multi_threaded_executor") { - use_multi_threaded_executor = true; - } else if (arg == std::string("--use-events-executor")) { - use_events_executor = true; + 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 if (use_events_executor) { - using ComponentManagerIsolated = - rclcpp_components::ComponentManagerIsolated; + } 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 { - using ComponentManagerIsolated = - rclcpp_components::ComponentManagerIsolated; + } 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(); From f508628f4ebaeab9dc67f6bd32239f6cbdda7c84 Mon Sep 17 00:00:00 2001 From: Tim Clephas Date: Tue, 25 Jun 2024 09:54:44 +0200 Subject: [PATCH 3/4] No need for backward compatibility on self introduced option Signed-off-by: Tim Clephas --- rclcpp_components/src/component_container_isolated.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/rclcpp_components/src/component_container_isolated.cpp b/rclcpp_components/src/component_container_isolated.cpp index 77eb51c423..5cc0ce0b9c 100644 --- a/rclcpp_components/src/component_container_isolated.cpp +++ b/rclcpp_components/src/component_container_isolated.cpp @@ -29,7 +29,6 @@ int main(int argc, char * argv[]) // parse arguments // valid entries: --executor-type single-threaded, --executor-type multi-threaded, --executor-type events - // --use-multi-threaded-executor and --use_multi_threaded_executor are kept for backward compatibility std::vector args = rclcpp::remove_ros_arguments(argc, argv); std::string executor_type = "single-threaded"; // default @@ -39,9 +38,7 @@ int main(int argc, char * argv[]) executor_type = args[i + 1]; break; } - } else if ( - args[i] == "--use-multi-threaded-executor" || args[i] == "--use_multi_threaded_executor") - { + } else if (args[i] == "--use_multi_threaded_executor") { // backward compatibility executor_type = "multi-threaded"; } } From a40b463a78ac490ea76b6c07c59d0be31f2bfdee Mon Sep 17 00:00:00 2001 From: Tim Clephas Date: Mon, 18 Aug 2025 10:11:10 +0200 Subject: [PATCH 4/4] Add deprecation log Signed-off-by: Tim Clephas --- rclcpp_components/src/component_container_isolated.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rclcpp_components/src/component_container_isolated.cpp b/rclcpp_components/src/component_container_isolated.cpp index 5cc0ce0b9c..3b4866c0fe 100644 --- a/rclcpp_components/src/component_container_isolated.cpp +++ b/rclcpp_components/src/component_container_isolated.cpp @@ -30,6 +30,7 @@ int main(int argc, char * argv[]) // parse arguments // valid entries: --executor-type single-threaded, --executor-type multi-threaded, --executor-type events std::vector args = rclcpp::remove_ros_arguments(argc, argv); + rclcpp::Node::SharedPtr node; std::string executor_type = "single-threaded"; // default for (size_t i = 0; i < args.size(); ++i) { @@ -39,12 +40,13 @@ int main(int argc, char * argv[]) 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 - rclcpp::Node::SharedPtr node; std::shared_ptr exec; if (executor_type == "events") { using executor = rclcpp::experimental::executors::EventsExecutor;