-
Notifications
You must be signed in to change notification settings - Fork 502
Add 'executor_type' parameter to ComponentManager and deprecate redundant component containers #3055
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: rolling
Are you sure you want to change the base?
Add 'executor_type' parameter to ComponentManager and deprecate redundant component containers #3055
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -90,6 +90,20 @@ class ComponentManager : public rclcpp::Node | |
| using ComponentResource = std::pair<std::string, std::string>; | ||
|
|
||
| /// Default constructor | ||
| /** | ||
| * Initializes the component manager. It creates the services: load node, unload node | ||
| * and list nodes. Initialize executor after construction using set_executor. | ||
| * | ||
| * \param executor the executor which will spin the node. | ||
| * \param node_name the name of the node that the data originates from. | ||
| * \param node_options additional options to control creation of the node. | ||
| */ | ||
| RCLCPP_COMPONENTS_PUBLIC | ||
| ComponentManager( | ||
| std::string node_name = "ComponentManager", | ||
| const rclcpp::NodeOptions & node_options = rclcpp::NodeOptions()); | ||
|
Comment on lines
+93
to
+104
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you tell me why this new ctor is required to add? |
||
|
|
||
| /// Constructor with executor | ||
| /** | ||
| * Initializes the component manager. It creates the services: load node, unload node | ||
| * and list nodes. | ||
|
|
@@ -100,12 +114,9 @@ class ComponentManager : public rclcpp::Node | |
| */ | ||
| RCLCPP_COMPONENTS_PUBLIC | ||
| ComponentManager( | ||
| std::weak_ptr<rclcpp::Executor> executor = | ||
| std::weak_ptr<rclcpp::executors::MultiThreadedExecutor>(), | ||
| std::weak_ptr<rclcpp::Executor> executor, | ||
| std::string node_name = "ComponentManager", | ||
| const rclcpp::NodeOptions & node_options = rclcpp::NodeOptions() | ||
| .start_parameter_services(false) | ||
| .start_parameter_event_publisher(false)); | ||
| const rclcpp::NodeOptions & node_options = rclcpp::NodeOptions()); | ||
|
Comment on lines
-103
to
+119
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this breaks the API/ABI, we should deprecate the ctor 1st before breaking changes. see https://docs.ros.org/en/rolling/The-ROS2-Project/Contributing/Developer-Guide.html#deprecation-strategy
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tbh, I did not understand the default value for the which is covered with this constructor, or do something like: which is covered with the other constructor I added. Am I right? |
||
|
|
||
| RCLCPP_COMPONENTS_PUBLIC | ||
| virtual ~ComponentManager(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,12 +19,22 @@ | |
|
|
||
| #include "rclcpp_components/component_manager.hpp" | ||
|
|
||
| [[deprecated("component_container_event is deprecated and will be removed " | ||
| "in the next version. Use 'ros2 run rclcpp_components " | ||
| "component_container --ros-args -p executor_type:=EventsExecutor' " | ||
| "instead.")]] | ||
| int main(int argc, char * argv[]) | ||
| { | ||
| /// Component container with an events executor. | ||
| rclcpp::init(argc, argv); | ||
| auto exec = std::make_shared<rclcpp::experimental::executors::EventsExecutor>(); | ||
| auto node = std::make_shared<rclcpp_components::ComponentManager>(exec); | ||
|
|
||
| RCLCPP_WARN(node->get_logger(), | ||
| "component_container_event is depracated and will be removed " | ||
| "in the next version. use 'ros2 run rclcpp_components " | ||
| "component_container --ros-args -p executor_type:=EventsExecutor'."); | ||
|
|
||
|
Comment on lines
+32
to
+37
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we instead use
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just tried that, it showed nothing when I used |
||
| exec->add_node(node); | ||
| exec->spin(); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,11 +46,9 @@ namespace rclcpp_components | |
| { | ||
|
|
||
| ComponentManager::ComponentManager( | ||
| std::weak_ptr<rclcpp::Executor> executor, | ||
| std::string node_name, | ||
| const rclcpp::NodeOptions & node_options) | ||
| : Node(std::move(node_name), node_options), | ||
| executor_(executor) | ||
| : Node(std::move(node_name), node_options) | ||
| { | ||
| loadNode_srv_ = create_service<LoadNode>( | ||
| "~/_container/load_node", | ||
|
|
@@ -75,6 +73,22 @@ ComponentManager::ComponentManager( | |
| this->declare_parameter( | ||
| "thread_num", static_cast<int64_t>(std::thread::hardware_concurrency()), desc); | ||
| } | ||
|
|
||
| rcl_interfaces::msg::ParameterDescriptor exec_type_desc{}; | ||
| exec_type_desc.description = "Type of executor used for ComponentManager"; | ||
| exec_type_desc.type = rclcpp::PARAMETER_STRING; | ||
| // The value is changed only within set_executor. It cannot be changed externally. | ||
| exec_type_desc.read_only = true; | ||
| this->declare_parameter("executor_type", "No Executor", exec_type_desc); | ||
|
Comment on lines
+77
to
+82
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why we need to do this including
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm sorry I don't quite understand this. Are you asking about the comment I added here, or the changes I made to |
||
| } | ||
|
|
||
| ComponentManager::ComponentManager( | ||
| std::weak_ptr<rclcpp::Executor> executor, | ||
| std::string node_name, | ||
| const rclcpp::NodeOptions & node_options) | ||
| : ComponentManager::ComponentManager(node_name, node_options) | ||
| { | ||
| this->set_executor(executor); | ||
| } | ||
|
|
||
| ComponentManager::~ComponentManager() | ||
|
|
@@ -243,6 +257,10 @@ void | |
| ComponentManager::set_executor(const std::weak_ptr<rclcpp::Executor> executor) | ||
| { | ||
| executor_ = executor; | ||
| if (auto exec = executor_.lock()) { | ||
| rclcpp::Parameter exec_type("executor_type", exec->get_class_name()); | ||
| auto result = this->set_parameter(exec_type); | ||
| } | ||
| } | ||
|
|
||
| void | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i really do not understand why this needs to be added? even if needed, can we use
typeidinstead?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any executor can be used as the underlying executor for
ComponentContainer. So even if a user-defined executor is used forComponentContainer, the value ofexecutor_typeshould be updated to reflect that.tbh, I didn't like the
get_class_name()approach either. But I was afraid that the value oftypeid(exec).name()would be mangled. I wasn't sure what to do :)