From 60cc8ce09dcf1745054c48f5f0a67d2bee4b47cf Mon Sep 17 00:00:00 2001 From: Tim Clephas Date: Mon, 27 May 2024 11:30:10 +0200 Subject: [PATCH 1/3] 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 96ba8b1a03..2ca9f2d141 100644 --- a/rclcpp_components/src/component_container_isolated.cpp +++ b/rclcpp_components/src/component_container_isolated.cpp @@ -26,10 +26,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 @@ -39,6 +44,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 ba7c6a1c0cb71546c94bae418db5b002b4e5762a Mon Sep 17 00:00:00 2001 From: Tim Clephas Date: Mon, 24 Jun 2024 08:54:41 +0200 Subject: [PATCH 2/3] 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 2ca9f2d141..fff342ec50 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/rclcpp.hpp" #include "rclcpp/utilities.hpp" @@ -22,37 +22,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 b2c64b0ba19ec40ec2a84cd4f8a8fc2453eafd88 Mon Sep 17 00:00:00 2001 From: Tim Clephas Date: Tue, 25 Jun 2024 09:54:44 +0200 Subject: [PATCH 3/3] 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 fff342ec50..ead319f0f6 100644 --- a/rclcpp_components/src/component_container_isolated.cpp +++ b/rclcpp_components/src/component_container_isolated.cpp @@ -27,7 +27,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 @@ -37,9 +36,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"; } }