Commit eac28fac authored by beuchatp's avatar beuchatp
Browse files

Finished integrating the Template Controller into Qt. Next Step is to add a ROS node for it

parent ae2cb346
......@@ -70,7 +70,7 @@
</spacer>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="pushButton_2">
<widget class="QPushButton" name="custom_button_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
......@@ -83,7 +83,7 @@
</widget>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="pushButton_3">
<widget class="QPushButton" name="custom_button_3">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
......@@ -96,7 +96,7 @@
</widget>
</item>
<item row="0" column="0">
<widget class="QPushButton" name="pushButton">
<widget class="QPushButton" name="custom_button_1">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
......@@ -117,7 +117,7 @@
<number>0</number>
</property>
<item>
<widget class="QLineEdit" name="lineEdit_9">
<widget class="QLineEdit" name="lineEdit_custom_3">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
......@@ -143,7 +143,7 @@
<number>0</number>
</property>
<item>
<widget class="QLineEdit" name="lineEdit_8">
<widget class="QLineEdit" name="lineEdit_custom_2">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
......@@ -169,7 +169,7 @@
<number>0</number>
</property>
<item>
<widget class="QLineEdit" name="lineEdit_7">
<widget class="QLineEdit" name="lineEdit_custom_1">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
......@@ -198,7 +198,7 @@
<item row="0" column="0">
<layout class="QGridLayout" name="gridLayout">
<item row="3" column="3">
<widget class="QLineEdit" name="lineEdit_15">
<widget class="QLineEdit" name="lineEdit_setpoint_new_y">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
......@@ -225,7 +225,7 @@
</widget>
</item>
<item row="1" column="3">
<widget class="QLabel" name="label_12">
<widget class="QLabel" name="label_new_title_line2">
<property name="text">
<string>Setpoint</string>
</property>
......@@ -235,7 +235,7 @@
</widget>
</item>
<item row="5" column="2">
<widget class="QLineEdit" name="lineEdit_13">
<widget class="QLineEdit" name="lineEdit_setpoint_current_yaw">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
......@@ -275,7 +275,7 @@
</widget>
</item>
<item row="0" column="3">
<widget class="QLabel" name="label_11">
<widget class="QLabel" name="label_new_title">
<property name="font">
<font>
<weight>75</weight>
......@@ -304,7 +304,7 @@
</spacer>
</item>
<item row="3" column="2">
<widget class="QLineEdit" name="lineEdit_11">
<widget class="QLineEdit" name="lineEdit_setpoint_current_y">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
......@@ -350,7 +350,7 @@
</widget>
</item>
<item row="4" column="3">
<widget class="QLineEdit" name="lineEdit_16">
<widget class="QLineEdit" name="lineEdit_setpoint_new_z">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
......@@ -377,7 +377,7 @@
</widget>
</item>
<item row="4" column="2">
<widget class="QLineEdit" name="lineEdit_12">
<widget class="QLineEdit" name="lineEdit_setpoint_current_z">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
......@@ -482,7 +482,7 @@
</widget>
</item>
<item row="2" column="2">
<widget class="QLineEdit" name="lineEdit_10">
<widget class="QLineEdit" name="lineEdit_setpoint_current_x">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
......@@ -512,7 +512,7 @@
</widget>
</item>
<item row="5" column="3">
<widget class="QLineEdit" name="lineEdit_17">
<widget class="QLineEdit" name="lineEdit_setpoint_new_yaw">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
......@@ -549,7 +549,7 @@
</widget>
</item>
<item row="6" column="3">
<widget class="QPushButton" name="pushButton_5">
<widget class="QPushButton" name="set_setpoint_button">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
......@@ -568,7 +568,7 @@
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="label_9">
<widget class="QLabel" name="label_current_title">
<property name="font">
<font>
<weight>75</weight>
......@@ -594,7 +594,7 @@
</widget>
</item>
<item row="2" column="3">
<widget class="QLineEdit" name="lineEdit_14">
<widget class="QLineEdit" name="lineEdit_setpoint_new_x">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
......@@ -621,7 +621,7 @@
</widget>
</item>
<item row="1" column="2">
<widget class="QLabel" name="label_10">
<widget class="QLabel" name="label_current_title_line2">
<property name="text">
<string>Setpoint</string>
</property>
......@@ -631,7 +631,7 @@
</widget>
</item>
<item row="6" column="2">
<widget class="QPushButton" name="pushButton_4">
<widget class="QPushButton" name="default_setpoint_button">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
......
......@@ -177,9 +177,9 @@ private:
bool getTypeAndIDParameters();
#endif
void publishSetpoint(float x, float y, float z, float yaw);
void publishSetpoint(float x, float y, float z, float yaw_degrees);
void increment_setpoint_by(float x_inc, float y_inc, float z_inc, float yaw_inc);
void increment_setpoint_by(float x_inc, float y_inc, float z_inc, float yaw_inc_degrees);
};
......
// Copyright (C) 2019, ETH Zurich, D-ITET, Paul Beuchat
//
// This file is part of D-FaLL-System.
//
// D-FaLL-System is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// D-FaLL-System is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with D-FaLL-System. If not, see <http://www.gnu.org/licenses/>.
//
//
// ----------------------------------------------------------------------------------
// DDDD FFFFF L L SSSS Y Y SSSS TTTTT EEEEE M M
// D D F aaa L L S Y Y S T E MM MM
// D D --- FFFF a a L L --- SSS Y SSS T EEE M M M
// D D F a aa L L S Y S T E M M
// DDDD F aa a LLLL LLLL SSSS Y SSSS T EEEEE M M
//
//
// DESCRIPTION:
// The GUI for a Template Controller for students build from
//
// ----------------------------------------------------------------------------------
#ifndef TEMPLATECONTROLLERTAB_H
#define TEMPLATECONTROLLERTAB_H
#include <QWidget>
#include <QMutex>
#include <QVector>
#include <QLineEdit>
#include <QTextStream>
#ifdef CATKIN_MAKE
#include <ros/ros.h>
#include <ros/network.h>
#include <ros/package.h>
// Include the standard message types
//#include "std_msgs/Int32.h"
//#include "std_msgs/Float32.h"
//#include <std_msgs/String.h>
// Include the DFALL message types
//#include "dfall_pkg/IntWithHeader.h"
#include "dfall_pkg/SetpointWithHeader.h"
#include "dfall_pkg/CustomButtonWithHeader.h"
// Include the DFALL service types
#include "dfall_pkg/GetSetpointService.h"
// Include the shared definitions
#include "nodes/Constants.h"
// SPECIFY THE PACKAGE NAMESPACE
//using namespace dfall_pkg;
#else
// Include the shared definitions
#include "include/Constants_for_Qt_compile.h"
#endif
namespace Ui {
class TemplateControllerTab;
......@@ -15,8 +88,89 @@ public:
explicit TemplateControllerTab(QWidget *parent = 0);
~TemplateControllerTab();
public slots:
void setAgentIDsToCoordinate(QVector<int> agentIDs , bool shouldCoordinateAll);
void setMeasuredPose(float x , float y , float z , float roll , float pitch , float yaw , bool occluded);
void poseDataUnavailableSlot();
private slots:
void on_lineEdit_setpoint_new_x_returnPressed();
void on_lineEdit_setpoint_new_y_returnPressed();
void on_lineEdit_setpoint_new_z_returnPressed();
void on_lineEdit_setpoint_new_yaw_returnPressed();
void on_set_setpoint_button_clicked();
void on_default_setpoint_button_clicked();
void on_custom_button_1_clicked();
void on_custom_button_2_clicked();
void on_custom_button_3_clicked();
private:
Ui::TemplateControllerTab *ui;
// --------------------------------------------------- //
// PRIVATE VARIABLES
// The type of this node, i.e., agent or a coordinator,
// specified as a parameter in the "*.launch" file
int m_type = 0;
// The ID of this node
int m_ID;
// For coordinating multiple agents
std::vector<int> m_vector_of_agentIDs_toCoordinate;
bool m_shouldCoordinateAll = true;
QMutex m_agentIDs_toCoordinate_mutex;
#ifdef CATKIN_MAKE
// PUBLISHER
// > For requesting the setpoint to be changed
ros::Publisher requestSetpointChangePublisher;
// SUBSCRIBER
// > For being notified when the setpoint is changed
ros::Subscriber setpointChangedSubscriber;
// PUBLISHER
// > For notifying that a custom button is pressed
ros::Publisher customButtonPublisher;
#endif
// --------------------------------------------------- //
// PRIVATE FUNCTIONS
#ifdef CATKIN_MAKE
// For receiving message that the setpoint was changed
void setpointChangedCallback(const dfall_pkg::SetpointWithHeader& newSetpoint);
// Publish a message when a custom button is pressed
void publish_custom_button_command(int button_index , QLineEdit * lineEdit_pointer);
// Fill the header for a message
void fillSetpointMessageHeader( dfall_pkg::SetpointWithHeader & msg );
void fillCustomButtonMessageHeader( dfall_pkg::CustomButtonWithHeader & msg );
// Get the paramters that specify the type and ID
bool getTypeAndIDParameters();
#endif
void publishSetpoint(float x, float y, float z, float yaw_degrees);
};
#endif // TEMPLATECONTROLLERTAB_H
......@@ -77,6 +77,11 @@ ControllerTabs::ControllerTabs(QWidget *parent) :
ui->tuning_controller_tab_widget , &TuningControllerTab::setMeasuredPose
);
QObject::connect(
this , &ControllerTabs::measuredPoseValueChanged ,
ui->template_controller_tab_widget , &TemplateControllerTab::setMeasuredPose
);
// CONNECT THE "MEASUREMENTS UNAVAILABLE" SIGNAL TO
......@@ -101,6 +106,11 @@ ControllerTabs::ControllerTabs(QWidget *parent) :
ui->tuning_controller_tab_widget , &TuningControllerTab::poseDataUnavailableSlot
);
QObject::connect(
this , &ControllerTabs::poseDataUnavailableSignal ,
ui->template_controller_tab_widget , &TemplateControllerTab::poseDataUnavailableSlot
);
// CONNECT TO THE COORDINATOR SIGNAL TO BE ALWAYS UPDATED
// WITH THE LIST OF AGENT IDs TO COORDINATE
......@@ -127,6 +137,11 @@ ControllerTabs::ControllerTabs(QWidget *parent) :
ui->tuning_controller_tab_widget , &TuningControllerTab::setAgentIDsToCoordinate
);
QObject::connect(
this , &ControllerTabs::agentIDsToCoordinateChanged ,
ui->template_controller_tab_widget , &TemplateControllerTab::setAgentIDsToCoordinate
);
......
......@@ -329,7 +329,7 @@ void StudentControllerTab::setpointChangedCallback(const dfall_pkg::SetpointWith
ui->lineEdit_setpoint_current_z->setText(qstr + QString::number( z, 'f', 3));
if (yaw < 0.0f) qstr = ""; else qstr = "+";
ui->lineEdit_setpoint_current_yaw->setText(qstr + QString::number( yaw * RAD2DEG, 'f', 3));
ui->lineEdit_setpoint_current_yaw->setText(qstr + QString::number( yaw * RAD2DEG, 'f', 1));
}
#endif
......@@ -357,7 +357,7 @@ void StudentControllerTab::setpointChangedCallback(const dfall_pkg::SetpointWith
// ----------------------------------------------------------------------------------
void StudentControllerTab::publishSetpoint(float x, float y, float z, float yaw)
void StudentControllerTab::publishSetpoint(float x, float y, float z, float yaw_degrees)
{
#ifdef CATKIN_MAKE
// Initialise the message as a local variable
......@@ -370,16 +370,16 @@ void StudentControllerTab::publishSetpoint(float x, float y, float z, float yaw)
msg.x = x;
msg.y = y;
msg.z = z;
msg.yaw = yaw * DEG2RAD;
msg.yaw = yaw_degrees * DEG2RAD;
// Publish the setpoint
this->requestSetpointChangePublisher.publish(msg);
// Inform the user about the change
ROS_INFO_STREAM("[STUDENT CONTROLLER GUI] Published request for setpoint change to: [" << x << ", "<< y << ", "<< z << ", "<< yaw << "]");
ROS_INFO_STREAM("[STUDENT CONTROLLER GUI] Published request for setpoint change to: [" << x << ", "<< y << ", "<< z << ", "<< yaw_degrees << "]");
#else
// TO ASSIST WITH DEBUGGING WHEN COMPILED AND RUN IN "QtCreator"
QTextStream(stdout) << "[STUDENT CONTROLLER GUI] would publish request for: [" << x << ", "<< y << ", "<< z << ", "<< yaw << "]";
QTextStream(stdout) << "[STUDENT CONTROLLER GUI] would publish request for: [" << x << ", "<< y << ", "<< z << ", "<< yaw_degrees << "]";
#endif
}
......@@ -388,12 +388,6 @@ void StudentControllerTab::publishSetpoint(float x, float y, float z, float yaw)
void StudentControllerTab::on_lineEdit_setpoint_new_x_returnPressed()
{
ui->set_setpoint_button->animateClick();
#ifdef CATKIN_MAKE
#else
// TO ASSIST WITH DEBUGGING WHEN COMPILED AND RUN IN "QtCreator"
QTextStream(stdout) << "[STUDENT CONTROLLER TAB] return pressed for x setpoint";
#endif
}
void StudentControllerTab::on_lineEdit_setpoint_new_y_returnPressed()
......@@ -423,29 +417,24 @@ void StudentControllerTab::on_set_setpoint_button_clicked()
x = (ui->lineEdit_setpoint_new_x->text()).toFloat();
else
x = (ui->lineEdit_setpoint_current_x->text()).toFloat();
// > For x
// > For y
if(!ui->lineEdit_setpoint_new_y->text().isEmpty())
y = (ui->lineEdit_setpoint_new_y->text()).toFloat();
else
y = (ui->lineEdit_setpoint_current_y->text()).toFloat();
// > For x
// > For z
if(!ui->lineEdit_setpoint_new_z->text().isEmpty())
z = (ui->lineEdit_setpoint_new_z->text()).toFloat();
else
z = (ui->lineEdit_setpoint_current_z->text()).toFloat();
// > For x
// > For yaws
if(!ui->lineEdit_setpoint_new_yaw->text().isEmpty())
yaw = (ui->lineEdit_setpoint_new_yaw->text()).toFloat();
else
yaw = (ui->lineEdit_setpoint_current_yaw->text()).toFloat();
#ifdef CATKIN_MAKE
// Call the function to publish the setpoint
publishSetpoint(x,y,z,yaw);
#else
// TO ASSIST WITH DEBUGGING WHEN COMPILED AND RUN IN "QtCreator"
QTextStream(stdout) << "[STUDENT CONTROLLER TAB] set setpoint button clicked";
#endif
}
void StudentControllerTab::on_default_setpoint_button_clicked()
......@@ -604,7 +593,7 @@ void StudentControllerTab::on_yaw_increment_minus_button_clicked()
}
void StudentControllerTab::increment_setpoint_by(float x_inc, float y_inc, float z_inc, float yaw_inc)
void StudentControllerTab::increment_setpoint_by(float x_inc, float y_inc, float z_inc, float yaw_inc_degrees)
{
if (m_type == TYPE_AGENT)
......@@ -616,7 +605,7 @@ void StudentControllerTab::increment_setpoint_by(float x_inc, float y_inc, float
(ui->lineEdit_setpoint_current_x->text() ).toFloat() + x_inc,
(ui->lineEdit_setpoint_current_y->text() ).toFloat() + y_inc,
(ui->lineEdit_setpoint_current_z->text() ).toFloat() + z_inc,
(ui->lineEdit_setpoint_current_yaw->text()).toFloat() + yaw_inc
(ui->lineEdit_setpoint_current_yaw->text()).toFloat() + yaw_inc_degrees
);
}
else if (m_type == TYPE_COORDINATOR)
......@@ -645,7 +634,7 @@ void StudentControllerTab::increment_setpoint_by(float x_inc, float y_inc, float
float x_new = x + x_inc;
float y_new = y + y_inc;
float z_new = z + z_inc;
float yaw_new = yaw + yaw_inc;
float yaw_new = yaw + yaw_inc_degrees;
// INITIALISE A STRING VARIABLE FOR ADDING THE "+"
QString qstr = "";
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment