From 24f5990ae68ae683d34004f8bff863dbf36f907b Mon Sep 17 00:00:00 2001 From: Paul Beuchat <beuchatp@control.ee.ethz.ch> Date: Mon, 23 Apr 2018 16:25:48 +0200 Subject: [PATCH] Started to update namespace conventions to new standards --- .../GUI_Qt/studentGUI/src/MainWindow.cpp | 4 +- pps_ws/src/d_fall_pps/include/PPSClient.h | 4 +- .../src/d_fall_pps/include/ParameterService.h | 2 +- pps_ws/src/d_fall_pps/launch/Agent.launch | 81 +++++++++++++++++++ pps_ws/src/d_fall_pps/launch/Config.sh | 3 +- pps_ws/src/d_fall_pps/launch/Student.launch | 34 -------- .../d_fall_pps/src/DemoControllerService.cpp | 13 +-- pps_ws/src/d_fall_pps/src/PPSClient.cpp | 8 +- .../src/d_fall_pps/src/ParameterService.cpp | 2 +- 9 files changed, 101 insertions(+), 50 deletions(-) create mode 100755 pps_ws/src/d_fall_pps/launch/Agent.launch delete mode 100755 pps_ws/src/d_fall_pps/launch/Student.launch diff --git a/pps_ws/src/d_fall_pps/GUI_Qt/studentGUI/src/MainWindow.cpp b/pps_ws/src/d_fall_pps/GUI_Qt/studentGUI/src/MainWindow.cpp index 78ad4d1f..5a0b12c8 100644 --- a/pps_ws/src/d_fall_pps/GUI_Qt/studentGUI/src/MainWindow.cpp +++ b/pps_ws/src/d_fall_pps/GUI_Qt/studentGUI/src/MainWindow.cpp @@ -108,9 +108,9 @@ MainWindow::MainWindow(int argc, char **argv, QWidget *parent) : requestLoadControllerYaml_from_my_GUI_Subscriber = nodeHandle.subscribe("/my_GUI/requestLoadControllerYaml", 1, &MainWindow::requestLoadControllerYaml_from_my_GUI_Callback, this); // First get student ID - if(!nh_PPSClient.getParam("studentID", m_student_id)) + if(!nh_PPSClient.getParam("agentID", m_student_id)) { - ROS_ERROR("Failed to get studentID"); + ROS_ERROR("Failed to get agentID"); } // Then, Central manager diff --git a/pps_ws/src/d_fall_pps/include/PPSClient.h b/pps_ws/src/d_fall_pps/include/PPSClient.h index e1d84a0f..af825cf4 100644 --- a/pps_ws/src/d_fall_pps/include/PPSClient.h +++ b/pps_ws/src/d_fall_pps/include/PPSClient.h @@ -136,8 +136,8 @@ using namespace d_fall_pps; // V A A R R III A A BBBB LLLLL EEEEE SSSS // ---------------------------------------------------------------------------------- -// "studentID", gives namespace and identifier in CentralManagerService -int studentID; +// "agentID", gives namespace and identifier in CentralManagerService +int agentID; // The safe controller specified in the ClientConfig.yaml, is considered stable ros::ServiceClient safeController; diff --git a/pps_ws/src/d_fall_pps/include/ParameterService.h b/pps_ws/src/d_fall_pps/include/ParameterService.h index 136f5c04..e17c7e5e 100644 --- a/pps_ws/src/d_fall_pps/include/ParameterService.h +++ b/pps_ws/src/d_fall_pps/include/ParameterService.h @@ -100,7 +100,7 @@ int my_type = 0; // The ID of this agent, i.e., the ID of this computer in the case that this computer is // and agent -int my_agentID = 0; +std::string my_agentID = "000"; // Publisher that notifies the relevant nodes when the YAML paramters have been loaded // from file into ram/cache, and hence are ready to be fetched diff --git a/pps_ws/src/d_fall_pps/launch/Agent.launch b/pps_ws/src/d_fall_pps/launch/Agent.launch new file mode 100755 index 00000000..76a2068c --- /dev/null +++ b/pps_ws/src/d_fall_pps/launch/Agent.launch @@ -0,0 +1,81 @@ +<launch> + + <!-- INPUT ARGUMENT OF THE AGENT's ID --> + <arg name="agentid" default="$(optenv DFALL_DEFAULT_ID)" /> + + <!-- Example of how to use the value in agentid --> + <!-- <param name="param" value="$(arg agentid)"/> --> + + <group ns="agent$(arg agentid)"> + + <!-- CRAZY RADIO --> + <node + pkg = "d_fall_pps" + name = "CrazyRadio" + output = "screen" + type = "CrazyRadio.py" + > + <rosparam command="load" file="$(find d_fall_pps)/param/ClientConfig.yaml" /> + </node> + + <!-- PPS CLIENT --> + <node + pkg = "d_fall_pps" + name = "PPSClient" + output = "screen" + type = "PPSClient" + > + <rosparam command="load" file="$(find d_fall_pps)/param/ClientConfig.yaml" /> + <param name="agentID" value="$(arg agentid)" /> + </node> + + <!-- SAFE CONTROLLER --> + <node + pkg = "d_fall_pps" + name = "SafeControllerService" + output = "screen" + type = "SafeControllerService" + > + </node> + + <!-- DEMO CONTROLLER --> + <node + pkg = "d_fall_pps" + name = "DemoControllerService" + output = "screen" + type = "DemoControllerService" + > + </node> + + <!-- PARAMETER SERVICE --> + <node + pkg = "d_fall_pps" + name = "ParameterService" + output = "screen" + type = "ParameterService" + > + <param name="type" type="str" value="agent" /> + <param name="agentID" type="str" value="$(arg agentid)" /> + <rosparam + command = "load" + file = "$(find d_fall_pps)/param/SafeController.yaml" + ns = "SafeController" + /> + <rosparam + command = "load" + file = "$(find d_fall_pps)/param/DemoController.yaml" + ns = "DemoController" + /> + </node> + + <!-- AGENT GUI (aka. the "student GUI") --> + <node + pkg = "d_fall_pps" + name = "student_GUI" + output = "screen" + type = "student_GUI"> + </node> + + </group> + +</launch> diff --git a/pps_ws/src/d_fall_pps/launch/Config.sh b/pps_ws/src/d_fall_pps/launch/Config.sh index ef8a0e84..dd140357 100755 --- a/pps_ws/src/d_fall_pps/launch/Config.sh +++ b/pps_ws/src/d_fall_pps/launch/Config.sh @@ -1,4 +1,5 @@ export ROS_MASTER_URI=http://teacher:11311 export ROS_IP=$(hostname -I | awk '{print $1;}') -export ROS_NAMESPACE=$(cat /etc/StudentID) +export DFALL_DEFAULT_ID=$(cat /etc/dfall_default_id) +export ROS_NAMESPACE='dfall' diff --git a/pps_ws/src/d_fall_pps/launch/Student.launch b/pps_ws/src/d_fall_pps/launch/Student.launch deleted file mode 100755 index 925b7489..00000000 --- a/pps_ws/src/d_fall_pps/launch/Student.launch +++ /dev/null @@ -1,34 +0,0 @@ -<launch> - - <!-- CRAZY RADIO --> - <node pkg="d_fall_pps" name="CrazyRadio" output="screen" type="CrazyRadio.py"> - <rosparam command="load" file="$(find d_fall_pps)/param/ClientConfig.yaml" /> - </node> - - <!-- PPS CLIENT --> - <node pkg="d_fall_pps" name="PPSClient" output="screen" type="PPSClient"> - <rosparam command="load" file="$(find d_fall_pps)/param/ClientConfig.yaml" /> - <param name="studentID" value="$(optenv ROS_NAMESPACE)" /> - </node> - - <!-- SAFE CONTROLLER --> - <node pkg="d_fall_pps" name="SafeControllerService" output="screen" type="SafeControllerService"> - </node> - - <!-- DEMO CONTROLLER --> - <node pkg="d_fall_pps" name="DemoControllerService" output="screen" type="DemoControllerService"> - </node> - - <!-- PARAMETER SERVICE --> - <node pkg="d_fall_pps" name="ParameterService" output="screen" type="ParameterService"> - <param name="type" type="str" value="agent" /> - <param name="agentID" value="$(optenv ROS_NAMESPACE)" /> - <rosparam command="load" file="$(find d_fall_pps)/param/SafeController.yaml" ns="SafeController" /> - <rosparam command="load" file="$(find d_fall_pps)/param/DemoController.yaml" ns="DemoController" /> - </node> - - <!-- AGENT GUI (aka. the "student GUI") --> - <node pkg="d_fall_pps" name="student_GUI" output="screen" type="student_GUI"> - </node> - -</launch> diff --git a/pps_ws/src/d_fall_pps/src/DemoControllerService.cpp b/pps_ws/src/d_fall_pps/src/DemoControllerService.cpp index 4c196ea5..fe84d4f1 100644 --- a/pps_ws/src/d_fall_pps/src/DemoControllerService.cpp +++ b/pps_ws/src/d_fall_pps/src/DemoControllerService.cpp @@ -1789,6 +1789,10 @@ 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 "DemoControllerService" node + std::string m_namespace = ros::this_node::getNamespace(); + ROS_INFO_STREAM("For DemoController, ros::this_node::getNamespace() = " << m_namespace); + // Get the agent ID as the "ROS_NAMESPACE" this computer. // NOTES: // > If you look at the "Student.launch" file in the "launch" folder, you will see @@ -1797,15 +1801,14 @@ int main(int argc, char* argv[]) { // This line of code adds a parameter named "studentID" to the "PPSClient" // > Thus, to get access to this "studentID" paremeter, we first need to get a handle // to the "PPSClient" node within which this controller service is nested. - // Get the namespace of this "DemoControllerService" node - std::string m_namespace = ros::this_node::getNamespace(); + // Get the handle to the "PPSClient" node ros::NodeHandle PPSClient_nodeHandle(m_namespace + "/PPSClient"); // Get the value of the "studentID" parameter into the instance variable "my_agentID" - if(!PPSClient_nodeHandle.getParam("studentID", my_agentID)) + if(!PPSClient_nodeHandle.getParam("agentID", my_agentID)) { // Throw an error if the student ID parameter could not be obtained - ROS_ERROR("Failed to get studentID from PPSClient"); + ROS_ERROR("Failed to get agentID from PPSClient"); } @@ -1856,7 +1859,7 @@ int main(int argc, char* argv[]) { // PRINT OUT SOME INFORMATION // Let the user know what namespaces are being used for linking to the parameter service - ROS_INFO_STREAM("The namespace string for accessing the Paramter Services are:"); + ROS_INFO_STREAM("For DemoController: the namespace strings for accessing the Paramter Services are:"); ROS_INFO_STREAM("namespace_to_own_agent_parameter_service = " << namespace_to_own_agent_parameter_service); ROS_INFO_STREAM("namespace_to_coordinator_parameter_service = " << namespace_to_coordinator_parameter_service); diff --git a/pps_ws/src/d_fall_pps/src/PPSClient.cpp b/pps_ws/src/d_fall_pps/src/PPSClient.cpp index 95a3e186..b37c498c 100755 --- a/pps_ws/src/d_fall_pps/src/PPSClient.cpp +++ b/pps_ws/src/d_fall_pps/src/PPSClient.cpp @@ -359,8 +359,8 @@ void viconCallback(const ViconData& viconData) { void loadCrazyflieContext() { CMQuery contextCall; - contextCall.request.studentID = studentID; - ROS_INFO_STREAM("StudentID:" << studentID); + contextCall.request.studentID = agentID; + ROS_INFO_STREAM("AgentID:" << agentID); CrazyflieContext new_context; @@ -574,8 +574,8 @@ void fetchYamlParametersForSafeController(ros::NodeHandle& nodeHandle) // > Load the paramters from the Client Config YAML file void fetchClientConfigParameters(ros::NodeHandle& nodeHandle) { - if(!nodeHandle.getParam("studentID", studentID)) { - ROS_ERROR("Failed to get studentID"); + if(!nodeHandle.getParam("agentID", agentID)) { + ROS_ERROR("Failed to get agentID"); } if(!nodeHandle.getParam("strictSafety", strictSafety)) { ROS_ERROR("Failed to get strictSafety param"); diff --git a/pps_ws/src/d_fall_pps/src/ParameterService.cpp b/pps_ws/src/d_fall_pps/src/ParameterService.cpp index 0919d765..47d06a9e 100755 --- a/pps_ws/src/d_fall_pps/src/ParameterService.cpp +++ b/pps_ws/src/d_fall_pps/src/ParameterService.cpp @@ -245,7 +245,7 @@ int main(int argc, char* argv[]) case TYPE_AGENT: { //m_ros_namespace = ros::this_node::getNamespace(); - m_ros_namespace = "/" + std::to_string(my_agentID) + '/' + "ParameterService"; + 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); break; } -- GitLab