From de3658a0e37379d78fd85b461c72138afc27b079 Mon Sep 17 00:00:00 2001 From: ashwinsushil Date: Mon, 27 Apr 2020 09:46:29 +0200 Subject: [PATCH] Add namespace to action and service client names To run multiple agents/robots, namespace of the node is appended to the client names for bt action node and bt service node. --- .../include/nav2_behavior_tree/bt_action_node.hpp | 6 ++++++ .../include/nav2_behavior_tree/bt_service_node.hpp | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/nav2_behavior_tree/include/nav2_behavior_tree/bt_action_node.hpp b/nav2_behavior_tree/include/nav2_behavior_tree/bt_action_node.hpp index c6e606bedb..25405ae0b1 100644 --- a/nav2_behavior_tree/include/nav2_behavior_tree/bt_action_node.hpp +++ b/nav2_behavior_tree/include/nav2_behavior_tree/bt_action_node.hpp @@ -36,6 +36,8 @@ class BtActionNode : public BT::ActionNodeBase : BT::ActionNodeBase(xml_tag_name, conf), action_name_(action_name) { node_ = config().blackboard->get("node"); + std::string node_namespace; + node_namespace = node_->get_namespace(); // Initialize the input and output messages goal_ = typename ActionT::Goal(); @@ -45,6 +47,10 @@ class BtActionNode : public BT::ActionNodeBase if (getInput("server_name", remapped_action_name)) { action_name_ = remapped_action_name; } + // Append namespace to the action name + if(node_namespace.c_str()) { + action_name_ = node_namespace + "/" + action_name_; + } createActionClient(action_name_); // Give the derive class a chance to do any initialization diff --git a/nav2_behavior_tree/include/nav2_behavior_tree/bt_service_node.hpp b/nav2_behavior_tree/include/nav2_behavior_tree/bt_service_node.hpp index f0cf0f21c9..1cf7d3f3e9 100644 --- a/nav2_behavior_tree/include/nav2_behavior_tree/bt_service_node.hpp +++ b/nav2_behavior_tree/include/nav2_behavior_tree/bt_service_node.hpp @@ -35,6 +35,8 @@ class BtServiceNode : public BT::SyncActionNode : BT::SyncActionNode(service_node_name, conf), service_node_name_(service_node_name) { node_ = config().blackboard->get("node"); + std::string node_namespace; + node_namespace = node_->get_namespace(); // Get the required items from the blackboard server_timeout_ = @@ -43,6 +45,10 @@ class BtServiceNode : public BT::SyncActionNode // Now that we have node_ to use, create the service client for this BT service getInput("service_name", service_name_); + // Append namespace to the action name + if(node_namespace.c_str()) { + service_name_ = node_namespace + "/" + service_name_; + } service_client_ = node_->create_client(service_name_); // Make sure the server is actually there before continuing