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 78ad4d1fc258da0b006fe503eb3031043de68ddf..5a0b12c8c7dc446724b4723ad07760bcc7590032 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 e1d84a0fbae7443e3473d65c37fe49efbe4e106c..af825cf42bfe02ea89526e8e26b4fc3574c977b3 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 136f5c04958da05cd3d12b4755668f2b1f2236b5..e17c7e5ecc67eaddaf2eb17b3b5ac4050b272400 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 0000000000000000000000000000000000000000..76a2068cc303a6b195fc06755029a5ff38d640c5 --- /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 ef8a0e84bf79a691210e7852cb221242639e7f72..dd1403578736f1124bd71f6a18dbdb493fd5f63e 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 925b7489d7fcd583c5b7d09b594e2cc8a538ff4a..0000000000000000000000000000000000000000 --- 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 4c196ea51f2e5e5c981fafc64dba7c03ddb8c025..fe84d4f11a7f8b2d50a0e28d01188d7541278d34 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 95a3e186c6e7f7c19747b70ce471b6f17754b41d..b37c498c8de42bc64b43f26565446449f6cf2b08 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 0919d7657b8b4a9884069b6655c3ba472ea8c989..47d06a9e901db58aa644818c61b8e2394493357b 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; }