From 8f43018f549e755abcebf7bb0164a2d8e1c7313f Mon Sep 17 00:00:00 2001 From: Paul Beuchat <beuchatp@control.ee.ethz.ch> Date: Mon, 9 Apr 2018 11:15:39 +0200 Subject: [PATCH] added custom buttons for student --- pps_ws/src/d_fall_pps/CMakeLists.txt | 1 + .../GUI_Qt/studentGUI/include/MainWindow.h | 3 + .../GUI_Qt/studentGUI/src/MainWindow.cpp | 43 ++- .../GUI_Qt/studentGUI/src/MainWindow.ui | 304 ++++++++++-------- pps_ws/src/d_fall_pps/msg/CustomButton.msg | 2 + 5 files changed, 207 insertions(+), 146 deletions(-) create mode 100644 pps_ws/src/d_fall_pps/msg/CustomButton.msg diff --git a/pps_ws/src/d_fall_pps/CMakeLists.txt b/pps_ws/src/d_fall_pps/CMakeLists.txt index 67d4fe74..3e92c2eb 100755 --- a/pps_ws/src/d_fall_pps/CMakeLists.txt +++ b/pps_ws/src/d_fall_pps/CMakeLists.txt @@ -135,6 +135,7 @@ add_message_files( #---------------------------------------------------------------------- DebugMsg.msg CustomControllerYAML.msg + CustomButton.msg ) ## Generate services in the 'srv' folder diff --git a/pps_ws/src/d_fall_pps/GUI_Qt/studentGUI/include/MainWindow.h b/pps_ws/src/d_fall_pps/GUI_Qt/studentGUI/include/MainWindow.h index 8aacf439..21e8a101 100644 --- a/pps_ws/src/d_fall_pps/GUI_Qt/studentGUI/include/MainWindow.h +++ b/pps_ws/src/d_fall_pps/GUI_Qt/studentGUI/include/MainWindow.h @@ -124,6 +124,9 @@ private slots: void on_en_safe_controller_clicked(); + void on_customButton_1_clicked(); + void on_customButton_2_clicked(); + void on_customButton_3_clicked(); private: Ui::MainWindow *ui; 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 15f1497c..817af1e6 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 @@ -42,6 +42,8 @@ #include "d_fall_pps/ViconData.h" +#include "d_fall_pps/CustomButton.h" + MainWindow::MainWindow(int argc, char **argv, QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), @@ -84,8 +86,6 @@ MainWindow::MainWindow(int argc, char **argv, QWidget *parent) : ros::NodeHandle my_nodeHandle("~"); controllerSetpointPublisher = my_nodeHandle.advertise<Setpoint>("ControllerSetpoint", 1); - - // communication with PPS Client, just to make it possible to communicate through terminal also we use PPSClient's name //ros::NodeHandle nh_PPSClient(m_ros_namespace + "/PPSClient"); @@ -93,19 +93,19 @@ MainWindow::MainWindow(int argc, char **argv, QWidget *parent) : crazyRadioCommandPublisher = nh_PPSClient.advertise<std_msgs::Int32>("crazyRadioCommand", 1); PPSClientCommandPublisher = nh_PPSClient.advertise<std_msgs::Int32>("Command", 1); + PPSClientStudentCustomButtonPublisher = nh_PPSClient.advertise<CustomButton>("StudentCustomButton", 1); + - // > For publishing a message that requests the + // > For publishing a message that requests the // YAML parameters to be re-loaded from file // > The message contents specify which controller // the parameters should be re-loaded for requestLoadControllerYamlPublisher = nh_PPSClient.advertise<std_msgs::Int32>("requestLoadControllerYaml", 1); - // Subscriber for locking the load the controller YAML // parameters when the Coordintor GUI requests a load 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)) @@ -482,6 +482,8 @@ void MainWindow::on_set_setpoint_button_clicked() msg_setpoint.yaw = (ui->new_setpoint_yaw->text()).toFloat() * DEG2RAD; this->controllerSetpointPublisher.publish(msg_setpoint); + + ROS_INFO_STREAM("Setpoint change clicked with:" << msg_setpoint.x << ", "<< msg_setpoint.y << ", "<< msg_setpoint.z << ", "<< msg_setpoint.yaw); } void MainWindow::initialize_custom_setpoint() @@ -514,6 +516,8 @@ void MainWindow::on_set_setpoint_button_2_clicked() msg_setpoint.yaw = (ui->new_setpoint_yaw_2->text()).toFloat() * DEG2RAD; this->customSetpointPublisher.publish(msg_setpoint); + + ROS_INFO_STREAM("Setpoint change clicked with:" << msg_setpoint.x << ", "<< msg_setpoint.y << ", "<< msg_setpoint.z << ", "<< msg_setpoint.yaw); } void MainWindow::on_RF_disconnect_button_clicked() @@ -591,7 +595,6 @@ void MainWindow::customYamlFileTimerCallback(const ros::TimerEvent&) - void MainWindow::requestLoadControllerYaml_from_my_GUI_Callback(const std_msgs::Int32& msg) { // Extract from the "msg" for which controller the YAML @@ -657,3 +660,31 @@ void MainWindow::on_en_safe_controller_clicked() msg.data = CMD_USE_SAFE_CONTROLLER; this->PPSClientCommandPublisher.publish(msg); } + +void MainWindow::on_customButton_1_clicked() +{ + CustomButton msg_custom_button; + msg_custom_button.button_index = 1; + msg_custom_button.command_code = 0; + this->PPSClientStudentCustomButtonPublisher.publish(msg_custom_button); + + ROS_INFO("Custom button 1 pressed"); +} + +void MainWindow::on_customButton_2_clicked() +{ + CustomButton msg_custom_button; + msg_custom_button.button_index = 2; + msg_custom_button.command_code = 0; + this->PPSClientStudentCustomButtonPublisher.publish(msg_custom_button); + ROS_INFO("Custom button 2 pressed"); +} + +void MainWindow::on_customButton_3_clicked() +{ + CustomButton msg_custom_button; + msg_custom_button.button_index = 3; + msg_custom_button.command_code = (ui->custom_command_3->text()).toFloat(); + this->PPSClientStudentCustomButtonPublisher.publish(msg_custom_button); + ROS_INFO("Custom button 3 pressed"); +} diff --git a/pps_ws/src/d_fall_pps/GUI_Qt/studentGUI/src/MainWindow.ui b/pps_ws/src/d_fall_pps/GUI_Qt/studentGUI/src/MainWindow.ui index 3dd33614..4eb82b0e 100644 --- a/pps_ws/src/d_fall_pps/GUI_Qt/studentGUI/src/MainWindow.ui +++ b/pps_ws/src/d_fall_pps/GUI_Qt/studentGUI/src/MainWindow.ui @@ -6,8 +6,8 @@ <rect> <x>0</x> <y>0</y> - <width>1027</width> - <height>619</height> + <width>1042</width> + <height>701</height> </rect> </property> <property name="sizePolicy"> @@ -33,6 +33,141 @@ <string/> </property> <layout class="QGridLayout" name="gridLayout_10"> + <item row="3" column="1"> + <widget class="QGroupBox" name="groupBox_4"> + <property name="title"> + <string/> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <widget class="QPushButton" name="motors_OFF_button"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Minimum" vsizetype="Expanding"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Motors OFF</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="take_off_button"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Minimum" vsizetype="Expanding"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Take Off</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="land_button"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Minimum" vsizetype="Expanding"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Land</string> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="label_battery"> + <property name="font"> + <font> + <pointsize>9</pointsize> + <italic>true</italic> + </font> + </property> + <property name="text"> + <string/> + </property> + </widget> + </item> + </layout> + </widget> + </item> + <item row="1" column="0"> + <widget class="QGroupBox" name="groupBox"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Maximum" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="font"> + <font> + <pointsize>18</pointsize> + </font> + </property> + <property name="title"> + <string>StudentID # connected to CF #</string> + </property> + <layout class="QGridLayout" name="gridLayout_2"> + <item row="1" column="0"> + <widget class="QLabel" name="raw_voltage_label"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="font"> + <font> + <pointsize>18</pointsize> + <italic>false</italic> + </font> + </property> + <property name="text"> + <string>Raw voltage: </string> + </property> + </widget> + </item> + <item row="1" column="1"> + <widget class="QLineEdit" name="voltage_field"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Maximum" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="maximumSize"> + <size> + <width>80</width> + <height>16777215</height> + </size> + </property> + <property name="readOnly"> + <bool>true</bool> + </property> + </widget> + </item> + </layout> + </widget> + </item> + <item row="1" column="1"> + <widget class="QLabel" name="flying_state_label"> + <property name="sizePolicy"> + <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>FlyingState</string> + </property> + <property name="alignment"> + <set>Qt::AlignCenter</set> + </property> + </widget> + </item> <item row="3" column="0"> <widget class="QTabWidget" name="tabWidget"> <property name="currentIndex"> @@ -563,6 +698,27 @@ <string>Custom Controller</string> </attribute> <layout class="QGridLayout" name="gridLayout_9"> + <item row="2" column="1"> + <widget class="QPushButton" name="customButton_2"> + <property name="text"> + <string>Custom Command 2</string> + </property> + </widget> + </item> + <item row="3" column="1"> + <widget class="QPushButton" name="customButton_3"> + <property name="text"> + <string>Custom Command 3</string> + </property> + </widget> + </item> + <item row="1" column="1"> + <widget class="QPushButton" name="customButton_1"> + <property name="text"> + <string>Custom Command 1</string> + </property> + </widget> + </item> <item row="0" column="0"> <widget class="QGroupBox" name="groupBox_5"> <property name="title"> @@ -1032,7 +1188,7 @@ </layout> </widget> </item> - <item row="1" column="1"> + <item row="4" column="1"> <widget class="QPushButton" name="en_custom_controller"> <property name="sizePolicy"> <sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding"> @@ -1051,7 +1207,7 @@ </property> </widget> </item> - <item row="1" column="0"> + <item row="4" column="0"> <widget class="QPushButton" name="load_custom_yaml_button"> <property name="sizePolicy"> <sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding"> @@ -1070,145 +1226,13 @@ </property> </widget> </item> + <item row="3" column="2"> + <widget class="QLineEdit" name="custom_command_3"/> + </item> </layout> </widget> </widget> </item> - <item row="3" column="1"> - <widget class="QGroupBox" name="groupBox_4"> - <property name="title"> - <string/> - </property> - <layout class="QVBoxLayout" name="verticalLayout"> - <item> - <widget class="QPushButton" name="motors_OFF_button"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Minimum" vsizetype="Expanding"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="text"> - <string>Motors OFF</string> - </property> - </widget> - </item> - <item> - <widget class="QPushButton" name="take_off_button"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Minimum" vsizetype="Expanding"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="text"> - <string>Take Off</string> - </property> - </widget> - </item> - <item> - <widget class="QPushButton" name="land_button"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Minimum" vsizetype="Expanding"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="text"> - <string>Land</string> - </property> - </widget> - </item> - <item> - <widget class="QLabel" name="label_battery"> - <property name="font"> - <font> - <pointsize>9</pointsize> - <italic>true</italic> - </font> - </property> - <property name="text"> - <string/> - </property> - </widget> - </item> - </layout> - </widget> - </item> - <item row="1" column="0"> - <widget class="QGroupBox" name="groupBox"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Maximum" vsizetype="Preferred"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="font"> - <font> - <pointsize>18</pointsize> - </font> - </property> - <property name="title"> - <string>StudentID # connected to CF #</string> - </property> - <layout class="QGridLayout" name="gridLayout_2"> - <item row="1" column="0"> - <widget class="QLabel" name="raw_voltage_label"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Fixed" vsizetype="Preferred"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="font"> - <font> - <pointsize>18</pointsize> - <italic>false</italic> - </font> - </property> - <property name="text"> - <string>Raw voltage: </string> - </property> - </widget> - </item> - <item row="1" column="1"> - <widget class="QLineEdit" name="voltage_field"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Maximum" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="maximumSize"> - <size> - <width>80</width> - <height>16777215</height> - </size> - </property> - <property name="readOnly"> - <bool>true</bool> - </property> - </widget> - </item> - </layout> - </widget> - </item> - <item row="1" column="1"> - <widget class="QLabel" name="flying_state_label"> - <property name="sizePolicy"> - <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="text"> - <string>FlyingState</string> - </property> - <property name="alignment"> - <set>Qt::AlignCenter</set> - </property> - </widget> - </item> </layout> </widget> </item> @@ -1270,7 +1294,7 @@ <rect> <x>0</x> <y>0</y> - <width>1027</width> + <width>1042</width> <height>25</height> </rect> </property> diff --git a/pps_ws/src/d_fall_pps/msg/CustomButton.msg b/pps_ws/src/d_fall_pps/msg/CustomButton.msg new file mode 100644 index 00000000..7ba9d563 --- /dev/null +++ b/pps_ws/src/d_fall_pps/msg/CustomButton.msg @@ -0,0 +1,2 @@ +uint32 button_index +float64 command_code \ No newline at end of file -- GitLab