From ff83767f1141c594117d6c9197acb8ca94625fc0 Mon Sep 17 00:00:00 2001
From: beuchatp <beuchatp@control.ee.ethz.ch>
Date: Wed, 22 May 2019 00:06:26 +0200
Subject: [PATCH] Copied across main variables and functions from previous
 implementation of the remote GUI

---
 .../include/remotecontrollertab.h             |  32 +++-
 .../src/remotecontrollertab.cpp               | 147 ++++++++++++++++--
 2 files changed, 163 insertions(+), 16 deletions(-)

diff --git a/dfall_ws/src/dfall_pkg/GUI_Qt/flyingAgentGUI/include/remotecontrollertab.h b/dfall_ws/src/dfall_pkg/GUI_Qt/flyingAgentGUI/include/remotecontrollertab.h
index 3a681003..831aef9a 100644
--- a/dfall_ws/src/dfall_pkg/GUI_Qt/flyingAgentGUI/include/remotecontrollertab.h
+++ b/dfall_ws/src/dfall_pkg/GUI_Qt/flyingAgentGUI/include/remotecontrollertab.h
@@ -48,7 +48,7 @@
 #include <ros/package.h>
 
 // Include the standard message types
-//#include "std_msgs/Int32.h"
+#include "std_msgs/Int32.h"
 //#include "std_msgs/Float32.h"
 //#include <std_msgs/String.h>
 
@@ -56,6 +56,8 @@
 //#include "dfall_pkg/IntWithHeader.h"
 #include "dfall_pkg/SetpointWithHeader.h"
 #include "dfall_pkg/CustomButtonWithHeader.h"
+#include "dfall_pkg/CrazyflieData.h"
+#include "dfall_pkg/ViconSubscribeObjectName.h"
 
 // Include the DFALL service types
 #include "dfall_pkg/GetSetpointService.h"
@@ -112,6 +114,14 @@ private slots:
     void on_custom_button_3_clicked();
 
 
+    // COPIED FROM PREVIOUS REMOTE CONTROLLER GUI
+//    void on_subscribe_button_clicked();
+//    void on_unsubscribe_button_clicked();
+//    void on_activate_button_clicked();
+//    void on_deactivate_button_clicked();
+
+
+
 
 
 
@@ -147,6 +157,19 @@ private:
     // PUBLISHER
     // > For notifying that a custom button is pressed
     ros::Publisher customButtonPublisher;
+
+    // PUBLISHER
+    // > For the Remote Controller subscribe action
+    ros::Publisher remoteSubscribePublisher;
+    // > For the Remote Controller activate action
+    ros::Publisher remoteActivatePublisher;
+
+    // SUBSCRIBER
+    // > For the Remote Controller data
+    ros::Subscriber remoteDataSubscriber;
+    // > For the Remote Control setpoint
+    ros::Subscriber remoteControlSetpointSubscriber;
+
 #endif
 
 
@@ -155,6 +178,13 @@ private:
     // PRIVATE FUNCTIONS
 
 #ifdef CATKIN_MAKE
+
+    // COPIED FROM PREVIOUS REMOTE CONTROLLER GUI
+    // For receiving message with the data of the remote
+    void remoteDataCallback(const dfall_pkg::CrazyflieData& objectData);
+    void remoteControlSetpointCallback(const dfall_pkg::CrazyflieData& setpointData);
+
+
     // For receiving message that the setpoint was changed
     void setpointChangedCallback(const dfall_pkg::SetpointWithHeader& newSetpoint);
 
diff --git a/dfall_ws/src/dfall_pkg/GUI_Qt/flyingAgentGUI/src/remotecontrollertab.cpp b/dfall_ws/src/dfall_pkg/GUI_Qt/flyingAgentGUI/src/remotecontrollertab.cpp
index a1b26665..d0e0060a 100644
--- a/dfall_ws/src/dfall_pkg/GUI_Qt/flyingAgentGUI/src/remotecontrollertab.cpp
+++ b/dfall_ws/src/dfall_pkg/GUI_Qt/flyingAgentGUI/src/remotecontrollertab.cpp
@@ -84,26 +84,43 @@ RemoteControllerTab::RemoteControllerTab(QWidget *parent) :
     // CREATE THE CUSTOM BUTTON PRESSED PUBLISHER
     customButtonPublisher = nodeHandle_for_this_gui.advertise<dfall_pkg::CustomButtonWithHeader>("RemoteControllerService/CustomButtonPressed", 1);
 
-    // GET THE CURRENT SETPOINT
+//    // GET THE CURRENT SETPOINT
+//    // Only if this is an agent GUI
+//    if (m_type == TYPE_AGENT)
+//    {
+//        // > Request the current setpoint
+//        ros::ServiceClient getCurrentSetpointServiceClient = nodeHandle_for_this_gui.serviceClient<dfall_pkg::GetSetpointService>("RemoteControllerService/GetCurrentSetpoint", false);
+//        dfall_pkg::GetSetpointService getSetpointCall;
+//        getSetpointCall.request.data = 0;
+//        getCurrentSetpointServiceClient.waitForExistence(ros::Duration(2.0));
+//        if(getCurrentSetpointServiceClient.call(getSetpointCall))
+//        {
+//            setpointChangedCallback(getSetpointCall.response.setpointWithHeader);
+//        }
+//        else
+//        {
+//            // Inform the user
+//            ROS_INFO("[REMOTE CONTROLLER GUI] Failed to get setpoint from controller using the \"GetCurrentSetpoint\" service");
+//        }
+//    }
+
+    // REMOTE CONTROLLER PUBLISHERS AND SUBSCRIBERS
     // Only if this is an agent GUI
     if (m_type == TYPE_AGENT)
     {
-        // > Request the current setpoint
-        ros::ServiceClient getCurrentSetpointServiceClient = nodeHandle_for_this_gui.serviceClient<dfall_pkg::GetSetpointService>("RemoteControllerService/GetCurrentSetpoint", false);
-        dfall_pkg::GetSetpointService getSetpointCall;
-        getSetpointCall.request.data = 0;
-        getCurrentSetpointServiceClient.waitForExistence(ros::Duration(2.0));
-        if(getCurrentSetpointServiceClient.call(getSetpointCall))
-        {
-            setpointChangedCallback(getSetpointCall.response.setpointWithHeader);
-        }
-        else
-        {
-            // Inform the user
-            ROS_INFO("[REMOTE CONTROLLER GUI] Failed to get setpoint from controller using the \"GetCurrentSetpoint\" service");
-        }
+        // > For the Remote Controller subscribe action
+        remoteSubscribePublisher = nodeHandle_for_this_gui.advertise<dfall_pkg::ViconSubscribeObjectName>("RemoteControllerService/ViconSubscribeObjectName", 1);
+        // > For the Remote Controller activate action
+        remoteActivatePublisher = nodeHandle_for_this_gui.advertise<std_msgs::Int32>("RemoteControllerService/Activate", 1);
+        // > For the Remote Controller data
+        remoteDataSubscriber = nodeHandle_for_this_gui.subscribe("RemoteControllerService/RemoteData", 1, &RemoteControllerTab::remoteDataCallback, this);;
+        // > For the Remote Controller data
+        remoteControlSetpointSubscriber = nodeHandle_for_this_gui.subscribe("RemoteControllerService/RemoteControlSetpoint", 1, &RemoteControllerTab::remoteControlSetpointCallback, this);
     }
 
+
+
+
 #endif
 
 }
@@ -132,6 +149,106 @@ RemoteControllerTab::~RemoteControllerTab()
 //    ----------------------------------------------------------------------------------
 
 
+// COPIED FROM PREVIOUS REMOTE CONTROLLER GUI
+// # Custom buttons for the REMOTE controller service
+//void RemoteControllerTab::on_remote_subscribe_button_clicked()
+//{
+//    // Initialise the message
+//    ViconSubscribeObjectName msg;
+//    // Set the subscribe flag
+//    msg.shouldSubscribe = true;
+//    // Set the object name
+//    msg.objectName = (ui->remote_object_name->text()).toUtf8().constData();
+//    // Publish the message
+//    this->remoteSubscribePublisher.publish(msg);
+//}
+
+//void RemoteControllerTab::on_remote_unsubscribe_button_clicked()
+//{
+//    // Initialise the message
+//    ViconSubscribeObjectName msg;
+//    // Set the subscribe flag
+//    msg.shouldSubscribe = false;
+//    // Set the object name
+//    msg.objectName = (ui->remote_object_name->text()).toUtf8().constData();
+//    // Publish the message
+//    this->remoteSubscribePublisher.publish(msg);
+//}
+
+//void RemoteControllerTab::on_remote_activate_button_clicked()
+//{
+//    // Initialise the message
+//    std_msgs::Int32 msg;
+//    // Set the msg data
+//    msg.data = 1;
+//    // Publish the message
+//    this->remoteActivatePublisher.publish(msg);
+//}
+
+//void RemoteControllerTab::on_remote_deactivate_button_clicked()
+//{
+//    // Initialise the message
+//    std_msgs::Int32 msg;
+//    // Set the msg data
+//    msg.data = 0;
+//    // Publish the message
+//    this->remoteActivatePublisher.publish(msg);
+//}
+
+
+#ifdef CATKIN_MAKE
+void RemoteControllerTab::remoteDataCallback(const dfall_pkg::CrazyflieData& objectData)
+{
+//    // Check if the object is occluded
+//    if (objectData.occluded)
+//    {
+//        // Set the column heading label to have a red background
+//        // > IMPORTANT: Set the background auto fill property to true
+//        ui->remote_data_label->setAutoFillBackground(true);
+//        // > Get the pallette currently set for the label
+//        QPalette pal = ui->remote_roll_label->palette();
+//        // > Set the palette property that will change the background
+//        pal.setColor(QPalette::Window, QColor(Qt::red));
+//        // > Update the palette for the label
+//        ui->remote_data_label->setPalette(pal);
+//    }
+//    else
+//    {
+//        // Put the roll, pitch, yaw, and z data into the appropriate fields
+//        ui->remote_data_roll ->setText(QString::number( objectData.roll  * RAD2DEG, 'f', 1));
+//        ui->remote_data_pitch->setText(QString::number( objectData.pitch * RAD2DEG, 'f', 1));
+//        ui->remote_data_yaw  ->setText(QString::number( objectData.yaw   * RAD2DEG, 'f', 1));
+//        ui->remote_data_z    ->setText(QString::number( objectData.z,               'f', 2));
+
+//        // Set the column heading label to have a "normal" background
+//        // > IMPORTANT: Set the background auto fill property to true
+//        ui->remote_data_label->setAutoFillBackground(false);
+//        // > Get the pallette currently set for the roll label
+//        QPalette pal = ui->remote_roll_label->palette();
+//        // > Update the palette for the column heading label
+//        ui->remote_data_label->setPalette(pal);
+//    }
+}
+#endif
+
+
+#ifdef CATKIN_MAKE
+void RemoteControllerTab::remoteControlSetpointCallback(const dfall_pkg::CrazyflieData& setpointData)
+{
+//    ui->remote_setpoint_roll ->setText(QString::number( setpointData.roll  * RAD2DEG, 'f', 1));
+//    ui->remote_setpoint_pitch->setText(QString::number( setpointData.pitch * RAD2DEG, 'f', 1));
+//    ui->remote_setpoint_yaw  ->setText(QString::number( setpointData.yaw   * RAD2DEG, 'f', 1));
+//    ui->remote_setpoint_z    ->setText(QString::number( setpointData.z,               'f', 2));
+}
+#endif
+
+
+
+
+
+
+
+
 #ifdef CATKIN_MAKE
 void RemoteControllerTab::publish_custom_button_command(int button_index , QLineEdit * lineEdit_pointer)
 {
-- 
GitLab