From fe61c0fdc855f19effe8b1287b249631afda4168 Mon Sep 17 00:00:00 2001 From: beuchatp <beuchatp@control.ee.ethz.ch> Date: Wed, 19 Dec 2018 17:36:11 +0100 Subject: [PATCH] Now compiles, needs testing --- pps_ws/src/d_fall_pps/CMakeLists.txt | 1 + .../include/studentcontrollertab.h | 3 +- .../src/defaultcontrollertab.cpp | 2 +- .../src/studentcontrollertab.cpp | 49 ++++++++++--------- .../GUI_Qt/flyingAgentGUI/src/topbanner.cpp | 2 +- .../src/nodes/StudentControllerService.cpp | 9 ++-- 6 files changed, 35 insertions(+), 31 deletions(-) diff --git a/pps_ws/src/d_fall_pps/CMakeLists.txt b/pps_ws/src/d_fall_pps/CMakeLists.txt index b2f1ecd6..961c45c4 100755 --- a/pps_ws/src/d_fall_pps/CMakeLists.txt +++ b/pps_ws/src/d_fall_pps/CMakeLists.txt @@ -210,6 +210,7 @@ add_message_files( FloatWithHeader.msg StringWithHeader.msg SetpointWithHeader.msg + CustomButtonWithHeader.msg #------------------------ DebugMsg.msg CustomButton.msg diff --git a/pps_ws/src/d_fall_pps/GUI_Qt/flyingAgentGUI/include/studentcontrollertab.h b/pps_ws/src/d_fall_pps/GUI_Qt/flyingAgentGUI/include/studentcontrollertab.h index 7baf4930..4bcaa3af 100644 --- a/pps_ws/src/d_fall_pps/GUI_Qt/flyingAgentGUI/include/studentcontrollertab.h +++ b/pps_ws/src/d_fall_pps/GUI_Qt/flyingAgentGUI/include/studentcontrollertab.h @@ -4,6 +4,7 @@ #include <QWidget> #include <QMutex> #include <QVector> +#include <QLineEdit> #include <QTextStream> #ifdef CATKIN_MAKE @@ -19,7 +20,7 @@ // Include the DFALL message types //#include "d_fall_pps/IntWithHeader.h" #include "d_fall_pps/SetpointWithHeader.h" -#include "d_fall_pps/CustomButtonWithHeader" +#include "d_fall_pps/CustomButtonWithHeader.h" // Include the DFALL service types #include "d_fall_pps/GetSetpointService.h" diff --git a/pps_ws/src/d_fall_pps/GUI_Qt/flyingAgentGUI/src/defaultcontrollertab.cpp b/pps_ws/src/d_fall_pps/GUI_Qt/flyingAgentGUI/src/defaultcontrollertab.cpp index 7f503464..2f198ff9 100644 --- a/pps_ws/src/d_fall_pps/GUI_Qt/flyingAgentGUI/src/defaultcontrollertab.cpp +++ b/pps_ws/src/d_fall_pps/GUI_Qt/flyingAgentGUI/src/defaultcontrollertab.cpp @@ -556,7 +556,7 @@ void DefaultControllerTab::setAgentIDsToCoordinate(QVector<int> agentIDs , bool ros::NodeHandle agent_base_nodeHandle(agent_base_namespace.toStdString()); // // > Request the current setpoint - ros::ServiceClient getCurrentSetpointServiceClient = agent_base_nodeHandle.serviceClient<d_fall_pps::IntIntService>("DefaultControllerService/GetCurrentSetpoint", false); + ros::ServiceClient getCurrentSetpointServiceClient = agent_base_nodeHandle.serviceClient<d_fall_pps::GetSetpointService>("DefaultControllerService/GetCurrentSetpoint", false); d_fall_pps::GetSetpointService getSetpointCall; getSetpointCall.request.data = 0; getCurrentSetpointServiceClient.waitForExistence(ros::Duration(2.0)); diff --git a/pps_ws/src/d_fall_pps/GUI_Qt/flyingAgentGUI/src/studentcontrollertab.cpp b/pps_ws/src/d_fall_pps/GUI_Qt/flyingAgentGUI/src/studentcontrollertab.cpp index 77a93f53..993482f2 100644 --- a/pps_ws/src/d_fall_pps/GUI_Qt/flyingAgentGUI/src/studentcontrollertab.cpp +++ b/pps_ws/src/d_fall_pps/GUI_Qt/flyingAgentGUI/src/studentcontrollertab.cpp @@ -47,7 +47,7 @@ StudentControllerTab::StudentControllerTab(QWidget *parent) : } // CREATE THE CUSTOM BUTTON PRESSED PUBLISHED - customButtonPublisher = nodeHandle_for_this_gui.advertise<CustomButton>("StudentControllerService/CustomButtonPressed", 1); + customButtonPublisher = nodeHandle_for_this_gui.advertise<d_fall_pps::CustomButtonWithHeader>("StudentControllerService/CustomButtonPressed", 1); #endif @@ -87,10 +87,10 @@ void StudentControllerTab::publish_custom_button_command(int button_index , QLin // Fill in the button index msg.button_index = button_index; // Get the line edit data, as a float if possible - bool isFloat = false; - float lineEdit_as_float = (lineEdit_pointer->text()).toFloat(isFloat); + bool isValidFloat = false; + float lineEdit_as_float = (lineEdit_pointer->text()).toFloat(&isValidFloat); // Fill in the data - if (isFloat) + if (isValidFloat) msg.float_data = lineEdit_as_float; else msg.string_data = (lineEdit_pointer->text()).toStdString(); @@ -105,24 +105,25 @@ void StudentControllerTab::publish_custom_button_command(int button_index , QLin void StudentControllerTab::on_custom_button_1_clicked() { #ifdef CATKIN_MAKE - // Initialise the message as a local variable - d_fall_pps::CustomButtonWithHeader msg; - // Fill the header of the message - fillCustomButtonMessageHeader( msg ); - // Fill in the button index - msg.button_index = 1; - // Get the line edit data, as a float if possible - bool isFloat = false; - float lineEdit_as_float = (ui->lineEdit_custom_1->text()).toFloat(isFloat); - // Fill in the data - if (isFloat) - msg.float_data = lineEdit_as_float; - else - msg.string_data = (ui->lineEdit_custom_1->text()).toStdString(); - // Publish the setpoint - this->customButtonPublisher.publish(msg); - // Inform the user about the change - ROS_INFO("[STUDENT CONTROLLER TAB GUI] button 1 clicked."); + publish_custom_button_command(1,ui->lineEdit_custom_1); + // // Initialise the message as a local variable + // d_fall_pps::CustomButtonWithHeader msg; + // // Fill the header of the message + // fillCustomButtonMessageHeader( msg ); + // // Fill in the button index + // msg.button_index = 1; + // // Get the line edit data, as a float if possible + // bool isFloat = false; + // float lineEdit_as_float = (ui->lineEdit_custom_1->text()).toFloat(isFloat); + // // Fill in the data + // if (isFloat) + // msg.float_data = lineEdit_as_float; + // else + // msg.string_data = (ui->lineEdit_custom_1->text()).toStdString(); + // // Publish the setpoint + // this->customButtonPublisher.publish(msg); + // // Inform the user about the change + // ROS_INFO("[STUDENT CONTROLLER TAB GUI] button 1 clicked."); #endif } @@ -655,7 +656,7 @@ void StudentControllerTab::setAgentIDsToCoordinate(QVector<int> agentIDs , bool ros::NodeHandle agent_base_nodeHandle(agent_base_namespace.toStdString()); // // > Request the current setpoint - ros::ServiceClient getCurrentSetpointServiceClient = agent_base_nodeHandle.serviceClient<d_fall_pps::IntIntService>("StudentControllerService/GetCurrentSetpoint", false); + ros::ServiceClient getCurrentSetpointServiceClient = agent_base_nodeHandle.serviceClient<d_fall_pps::GetSetpointService>("StudentControllerService/GetCurrentSetpoint", false); d_fall_pps::GetSetpointService getSetpointCall; getSetpointCall.request.data = 0; getCurrentSetpointServiceClient.waitForExistence(ros::Duration(2.0)); @@ -747,7 +748,7 @@ void StudentControllerTab::fillSetpointMessageHeader( d_fall_pps::SetpointWithHe #ifdef CATKIN_MAKE // Fill the header for a message -void fillCustomButtonMessageHeader( d_fall_pps::CustomButtonWithHeader & msg ) +void StudentControllerTab::fillCustomButtonMessageHeader( d_fall_pps::CustomButtonWithHeader & msg ) { switch (m_type) { diff --git a/pps_ws/src/d_fall_pps/GUI_Qt/flyingAgentGUI/src/topbanner.cpp b/pps_ws/src/d_fall_pps/GUI_Qt/flyingAgentGUI/src/topbanner.cpp index 4f63bbd0..60be1432 100644 --- a/pps_ws/src/d_fall_pps/GUI_Qt/flyingAgentGUI/src/topbanner.cpp +++ b/pps_ws/src/d_fall_pps/GUI_Qt/flyingAgentGUI/src/topbanner.cpp @@ -249,7 +249,7 @@ void TopBanner::on_emergency_stop_button_clicked() { #ifdef CATKIN_MAKE d_fall_pps::IntWithHeader msg; - msg.shouldCheckIDs = false; + msg.shouldCheckForID = false; msg.data = CMD_CRAZYFLY_MOTORS_OFF; this->emergencyStopPublisher.publish(msg); ROS_INFO("[TOP BANNER GUI] EMERGENCY STOP button clicked"); diff --git a/pps_ws/src/d_fall_pps/src/nodes/StudentControllerService.cpp b/pps_ws/src/d_fall_pps/src/nodes/StudentControllerService.cpp index cd13c090..ddca6073 100644 --- a/pps_ws/src/d_fall_pps/src/nodes/StudentControllerService.cpp +++ b/pps_ws/src/d_fall_pps/src/nodes/StudentControllerService.cpp @@ -644,8 +644,9 @@ void customCommandReceivedCallback(const CustomButtonWithHeader& commandReceived if (isRevelant) { // Extract the data from the message - int custom_button_index = commandReceived.button_index; - float custom_command_code = commandReceived.command_code; + int custom_button_index = commandReceived.button_index; + float float_data = commandReceived.float_data; + //std::string string_data = commandReceived.string_data; // Switch between the button pressed switch(custom_button_index) @@ -675,7 +676,7 @@ void customCommandReceivedCallback(const CustomButtonWithHeader& commandReceived case 3: { // Let the user know that this part of the code was triggered - ROS_INFO_STREAM("[STUDENT CONTROLLER] Button 3 received in controller, with command code:" << custom_command_code ); + ROS_INFO_STREAM("[STUDENT CONTROLLER] Button 3 received in controller, with message.float_data = " << float_data ); // Code here to respond to custom button 3 break; @@ -684,7 +685,7 @@ void customCommandReceivedCallback(const CustomButtonWithHeader& commandReceived default: { // Let the user know that the command was not recognised - ROS_INFO_STREAM("[DEMO CONTROLLER] A button clicked command was received in the controller but not recognised, message.button_index = " << custom_button_index << ", and message.command_code = " << custom_command_code ); + ROS_INFO_STREAM("[DEMO CONTROLLER] A button clicked command was received in the controller but not recognised, message.button_index = " << custom_button_index << ", and message.float_data = " << float_data ); break; } } -- GitLab