Skip to content

Commit

Permalink
Add name to CognitiveModule constructor
Browse files Browse the repository at this point in the history
Signed-off-by: Francisco Martín Rico <[email protected]>
  • Loading branch information
fmrico committed Oct 29, 2024
1 parent ae84210 commit a2015e4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
5 changes: 4 additions & 1 deletion cs4home_core/include/cs4home_core/CognitiveModule.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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_;
Expand Down
7 changes: 5 additions & 2 deletions cs4home_core/src/cs4home_core/CognitiveModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_);
Expand Down
4 changes: 2 additions & 2 deletions cs4home_core/test/cognitive_module_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit a2015e4

Please sign in to comment.