From a2015e41ebcf21f76534904b53f88b77485e73d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francisco=20Mart=C3=ADn=20Rico?= Date: Tue, 29 Oct 2024 06:23:39 +0100 Subject: [PATCH] Add name to CognitiveModule constructor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Francisco Martín Rico --- cs4home_core/include/cs4home_core/CognitiveModule.hpp | 5 ++++- cs4home_core/src/cs4home_core/CognitiveModule.cpp | 7 +++++-- cs4home_core/test/cognitive_module_test.cpp | 4 ++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/cs4home_core/include/cs4home_core/CognitiveModule.hpp b/cs4home_core/include/cs4home_core/CognitiveModule.hpp index c54173d..8d2efb4 100644 --- a/cs4home_core/include/cs4home_core/CognitiveModule.hpp +++ b/cs4home_core/include/cs4home_core/CognitiveModule.hpp @@ -41,7 +41,9 @@ class CognitiveModule : public rclcpp_lifecycle::LifecycleNode using CallbackReturnT = rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn; - explicit CognitiveModule(const rclcpp::NodeOptions & options = rclcpp::NodeOptions()); + explicit CognitiveModule( + const std::string & name, + const rclcpp::NodeOptions & options = rclcpp::NodeOptions()); CallbackReturnT on_configure(const rclcpp_lifecycle::State & state); CallbackReturnT on_activate(const rclcpp_lifecycle::State & state); @@ -57,6 +59,7 @@ class CognitiveModule : public rclcpp_lifecycle::LifecycleNode Meta::SharedPtr meta_; Coupling::SharedPtr coupling_; + std::string name_; std::string core_name_; std::string afferent_name_; std::string efferent_name_; diff --git a/cs4home_core/src/cs4home_core/CognitiveModule.cpp b/cs4home_core/src/cs4home_core/CognitiveModule.cpp index 21d7306..3288eda 100644 --- a/cs4home_core/src/cs4home_core/CognitiveModule.cpp +++ b/cs4home_core/src/cs4home_core/CognitiveModule.cpp @@ -17,8 +17,11 @@ namespace cs4home_core { -CognitiveModule::CognitiveModule(const rclcpp::NodeOptions & options) -: LifecycleNode("cognitive_module", options) +CognitiveModule::CognitiveModule( + const std::string & name, + const rclcpp::NodeOptions & options) +: LifecycleNode(name, options), + name_(name) { declare_parameter("core", core_name_); declare_parameter("afferent", afferent_name_); diff --git a/cs4home_core/test/cognitive_module_test.cpp b/cs4home_core/test/cognitive_module_test.cpp index 9c918f7..0fe27be 100644 --- a/cs4home_core/test/cognitive_module_test.cpp +++ b/cs4home_core/test/cognitive_module_test.cpp @@ -316,9 +316,9 @@ TEST(cognitive_module_test, startup_simple) rclcpp::NodeOptions options; options.arguments( - {"--ros-args", "-r", "__node:=cognitive_module_1", "--params-file", config_file}); + {"--ros-args", "--params-file", config_file}); - auto cm1 = cs4home_core::CognitiveModule::make_shared(options); + auto cm1 = cs4home_core::CognitiveModule::make_shared("cognitive_module_1", options); ASSERT_EQ(std::string(cm1->get_name()), "cognitive_module_1"); auto params = cm1->list_parameters({}, 0);