From 3b2802d928b4b7d3a6559c9f8ce60b67ee1245a4 Mon Sep 17 00:00:00 2001
From: Paul Beuchat <beuchatp@control.ee.ethz.ch>
Date: Mon, 10 Sep 2018 16:39:05 +0200
Subject: [PATCH] Hacked together a change controller for all

---
 .../include/enablecontrollerloadyamlbar.h     | 38 +++++++++++++++++++
 .../src/enablecontrollerloadyamlbar.cpp       | 31 +++++++++++++--
 .../GUI_Qt/flyingAgentGUI/src/mainwindow.cpp  |  8 ++--
 3 files changed, 71 insertions(+), 6 deletions(-)

diff --git a/pps_ws/src/d_fall_pps/GUI_Qt/flyingAgentGUI/include/enablecontrollerloadyamlbar.h b/pps_ws/src/d_fall_pps/GUI_Qt/flyingAgentGUI/include/enablecontrollerloadyamlbar.h
index 9ef5f533..59a83270 100644
--- a/pps_ws/src/d_fall_pps/GUI_Qt/flyingAgentGUI/include/enablecontrollerloadyamlbar.h
+++ b/pps_ws/src/d_fall_pps/GUI_Qt/flyingAgentGUI/include/enablecontrollerloadyamlbar.h
@@ -3,6 +3,35 @@
 
 #include <QWidget>
 
+#ifdef CATKIN_MAKE
+#include <std_msgs/Int32.h>
+#include <std_msgs/Float32.h>
+
+#include <ros/ros.h>
+#include <ros/network.h>
+#include <ros/package.h>
+
+// #include "d_fall_pps/AreaBounds.h"
+// #include "d_fall_pps/CrazyflieContext.h"
+// #include "d_fall_pps/CMQuery.h"
+
+// using namespace d_fall_pps;
+#endif
+
+
+// COMMANDS FOR THE FLYING STATE/CONTROLLER USED
+// The constants that "command" changes in the
+// operation state of this agent. These "commands"
+// are sent from this GUI node to the "PPSClient"
+// node where the command is enacted
+#define CMD_USE_SAFE_CONTROLLER      1
+#define CMD_USE_DEMO_CONTROLLER      2
+#define CMD_USE_STUDENT_CONTROLLER   3
+#define CMD_USE_MPC_CONTROLLER       4
+#define CMD_USE_REMOTE_CONTROLLER    5
+#define CMD_USE_TUNING_CONTROLLER    6
+
+
 namespace Ui {
 class EnableControllerLoadYamlBar;
 }
@@ -31,6 +60,15 @@ private slots:
 
 private:
     Ui::EnableControllerLoadYamlBar *ui;
+
+#ifdef CATKIN_MAKE
+    // --------------------------------------------------- //
+    // PRIVATE VARIABLES FOR ROS
+
+    // PUBLISHERS AND SUBSRIBERS
+    // > For Crazyradio commands based on button clicks
+    ros::Publisher commandAllPublisher;
+#endif
 };
 
 #endif // ENABLECONTROLLERLOADYAMLBAR_H
diff --git a/pps_ws/src/d_fall_pps/GUI_Qt/flyingAgentGUI/src/enablecontrollerloadyamlbar.cpp b/pps_ws/src/d_fall_pps/GUI_Qt/flyingAgentGUI/src/enablecontrollerloadyamlbar.cpp
index 7e3dee64..8fd105fc 100644
--- a/pps_ws/src/d_fall_pps/GUI_Qt/flyingAgentGUI/src/enablecontrollerloadyamlbar.cpp
+++ b/pps_ws/src/d_fall_pps/GUI_Qt/flyingAgentGUI/src/enablecontrollerloadyamlbar.cpp
@@ -6,6 +6,16 @@ EnableControllerLoadYamlBar::EnableControllerLoadYamlBar(QWidget *parent) :
     ui(new Ui::EnableControllerLoadYamlBar)
 {
     ui->setupUi(this);
+
+
+#ifdef CATKIN_MAKE
+    //ros::init();
+    // CREATE A NODE HANDLE TO THE ROOT OF THE D-FaLL SYSTEM
+    ros::NodeHandle dfall_root_nodeHandle("/dfall");
+
+    commandAllPublisher = dfall_root_nodeHandle.advertise<std_msgs::Int32>("/my_GUI/commandAllAgents", 1);
+#endif
+
 }
 
 EnableControllerLoadYamlBar::~EnableControllerLoadYamlBar()
@@ -20,17 +30,32 @@ EnableControllerLoadYamlBar::~EnableControllerLoadYamlBar()
 
 void EnableControllerLoadYamlBar::on_enable_safe_button_clicked()
 {
-
+#ifdef CATKIN_MAKE
+    std_msgs::Int32 msg;
+    msg.data = CMD_USE_SAFE_CONTROLLER;
+    this->commandAllPublisher.publish(msg);
+    ROS_INFO("[FLYING AGENT GUI] Enable Safe Controller");
+#endif
 }
 
 void EnableControllerLoadYamlBar::on_enable_demo_button_clicked()
 {
-
+#ifdef CATKIN_MAKE
+    std_msgs::Int32 msg;
+    msg.data = CMD_USE_DEMO_CONTROLLER;
+    this->commandAllPublisher.publish(msg);
+    ROS_INFO("[FLYING AGENT GUI] Enable Demo Controller");
+#endif
 }
 
 void EnableControllerLoadYamlBar::on_enable_student_button_clicked()
 {
-
+#ifdef CATKIN_MAKE
+    std_msgs::Int32 msg;
+    msg.data = CMD_USE_STUDENT_CONTROLLER;
+    this->commandAllPublisher.publish(msg);
+    ROS_INFO("[FLYING AGENT GUI] Enable Student Controller");
+#endif
 }
 
 void EnableControllerLoadYamlBar::on_enable_mpc_button_clicked()
diff --git a/pps_ws/src/d_fall_pps/GUI_Qt/flyingAgentGUI/src/mainwindow.cpp b/pps_ws/src/d_fall_pps/GUI_Qt/flyingAgentGUI/src/mainwindow.cpp
index 7a2ae595..13382717 100644
--- a/pps_ws/src/d_fall_pps/GUI_Qt/flyingAgentGUI/src/mainwindow.cpp
+++ b/pps_ws/src/d_fall_pps/GUI_Qt/flyingAgentGUI/src/mainwindow.cpp
@@ -40,15 +40,17 @@ MainWindow::MainWindow(int argc, char **argv, QWidget *parent) :
     //ROS_INFO("[flyingAgentGUI] Debug Point 5");
     m_rosNodeThread = new rosNodeThread(argc, argv, "flyingAgentGUI");
 #endif
+
+#ifdef CATKIN_MAKE
+    m_rosNodeThread->init();
+#endif
     ui->setupUi(this);
 
     // ADD KEYBOARD SHORTCUTS
     // > For "kill GUI node", press "CTRL+C" while the GUI window is the focus
     m_close_GUI_shortcut = new QShortcut(QKeySequence(tr("CTRL+C")), this, SLOT(close()));
 
-#ifdef CATKIN_MAKE
-    m_rosNodeThread->init();
-#endif
+
 
 }
 
-- 
GitLab