From 09e45fc8176095719e6818db2b04b5dcc151cab7 Mon Sep 17 00:00:00 2001
From: Paul Beuchat <beuchatp@control.ee.ethz.ch>
Date: Tue, 24 Apr 2018 10:01:22 +0200
Subject: [PATCH] Updated Parameter Service to work with new namespace
 conventions

---
 .../src/d_fall_pps/include/ParameterService.h |  2 +-
 .../src/d_fall_pps/src/ParameterService.cpp   | 29 ++++++++++++-------
 2 files changed, 19 insertions(+), 12 deletions(-)

diff --git a/pps_ws/src/d_fall_pps/include/ParameterService.h b/pps_ws/src/d_fall_pps/include/ParameterService.h
index e17c7e5e..087c1850 100644
--- a/pps_ws/src/d_fall_pps/include/ParameterService.h
+++ b/pps_ws/src/d_fall_pps/include/ParameterService.h
@@ -107,7 +107,7 @@ std::string my_agentID = "000";
 ros::Publisher controllerYamlReadyForFetchPublihser;
 
 
-std::string m_ros_namespace;
+std::string m_base_namespace;
 
 ros::Subscriber requestLoadControllerYamlSubscriber_agent_to_self;
 
diff --git a/pps_ws/src/d_fall_pps/src/ParameterService.cpp b/pps_ws/src/d_fall_pps/src/ParameterService.cpp
index 47d06a9e..80a86239 100755
--- a/pps_ws/src/d_fall_pps/src/ParameterService.cpp
+++ b/pps_ws/src/d_fall_pps/src/ParameterService.cpp
@@ -98,22 +98,22 @@ void requestLoadControllerYamlCallback(const std_msgs::Int32& msg)
     if ( (controller_to_load_yaml==LOAD_YAML_SAFE_CONTROLLER_COORDINATOR) && (my_type==TYPE_COORDINATOR) )
     {
         // Re-load the parameters of the safe controller:
-        cmd = "rosparam load " + d_fall_pps_path + "/param/SafeController.yaml " + m_ros_namespace + "/SafeController";
+        cmd = "rosparam load " + d_fall_pps_path + "/param/SafeController.yaml " + m_base_namespace + "/SafeController";
     }
     else if ( (controller_to_load_yaml==LOAD_YAML_SAFE_CONTROLLER_AGENT) && (my_type==TYPE_AGENT) )
     {
         // Re-load the parameters of the safe controller:
-        cmd = "rosparam load " + d_fall_pps_path + "/param/SafeController.yaml " + m_ros_namespace + "/SafeController";
+        cmd = "rosparam load " + d_fall_pps_path + "/param/SafeController.yaml " + m_base_namespace + "/SafeController";
     }
     else if ( (controller_to_load_yaml==LOAD_YAML_DEMO_CONTROLLER_COORDINATOR) && (my_type==TYPE_COORDINATOR) )
     {
         // Re-load the parameters of the demo controller:
-        cmd = "rosparam load " + d_fall_pps_path + "/param/DemoController.yaml " + m_ros_namespace + "/DemoController";
+        cmd = "rosparam load " + d_fall_pps_path + "/param/DemoController.yaml " + m_base_namespace + "/DemoController";
     }
     else if ( (controller_to_load_yaml==LOAD_YAML_DEMO_CONTROLLER_AGENT) && (my_type==TYPE_AGENT) )
     {
         // Re-load the parameters of the demo controller:
-        cmd = "rosparam load " + d_fall_pps_path + "/param/DemoController.yaml " + m_ros_namespace + "/DemoController";
+        cmd = "rosparam load " + d_fall_pps_path + "/param/DemoController.yaml " + m_base_namespace + "/DemoController";
     }
     else
     {
@@ -200,6 +200,11 @@ int main(int argc, char* argv[])
     // the "~" indcates that "self" is the node handle assigned to this variable.
     ros::NodeHandle nodeHandle("~");
 
+    // Get the namespace of this "ParameterService" node
+    std::string m_namespace = ros::this_node::getNamespace();
+    ROS_INFO_STREAM("For ParameterService, ros::this_node::getNamespace() =  " << m_namespace);
+
+
 
     // Get the value of the "type" parameter into a local string variable
     std::string type_string;
@@ -222,7 +227,7 @@ int main(int argc, char* argv[])
     {
         // Set "my_type" to the value indicating that it is invlid
         my_type = TYPE_INVALID;
-        ROS_ERROR("The retrieve type parameter was no recognised.");
+        ROS_ERROR("The 'type' parameter retrieved was not recognised.");
     }
 
 
@@ -244,9 +249,10 @@ int main(int argc, char* argv[])
     {
         case TYPE_AGENT:
         {
-            //m_ros_namespace = ros::this_node::getNamespace();
-            m_ros_namespace = "/agent" + my_agentID + '/' + "ParameterService";
-            ROS_INFO_STREAM("This Paramter Sercice will load .yaml file parameters into the 'base' namespace: " << m_ros_namespace);
+            //m_base_namespace = ros::this_node::getNamespace();
+            //m_base_namespace = "/agent" + my_agentID + '/' + "ParameterService";
+            m_base_namespace = m_namespace + '/' + "ParameterService";
+            ROS_INFO_STREAM("This Paramter Sercice will load .yaml file parameters into the 'base' namespace: " << m_base_namespace);
             break;
         }
 
@@ -254,9 +260,10 @@ int main(int argc, char* argv[])
         // > The master GUI
         case TYPE_COORDINATOR:
         {
-            //m_ros_namespace = ros::this_node::getNamespace();
-            m_ros_namespace = "/ParameterService";
-            ROS_INFO_STREAM("This Paramter Sercice will load .yaml file parameters into the 'base' namespace: " << m_ros_namespace);
+            //m_base_namespace = ros::this_node::getNamespace();
+            //m_base_namespace = "/ParameterService";
+            m_base_namespace = m_namespace + '/' + "ParameterService";
+            ROS_INFO_STREAM("This Paramter Sercice will load .yaml file parameters into the 'base' namespace: " << m_base_namespace);
             break;
         }
 
-- 
GitLab