To receive notifications about scheduled maintenance, please subscribe to the mailing-list gitlab-operations@sympa.ethz.ch. You can subscribe to the mailing-list at https://sympa.ethz.ch

Commit f4d6c742 authored by beuchatp's avatar beuchatp
Browse files

Merge branch 'studentGUI_withIcons' into 'master'

Student gui with icons

See merge request D-FaLL/PandS-System/D-FaLL-System!8
parents 9e8af6d1 53ffc6a3
......@@ -59,12 +59,18 @@ find_package(Qt5Svg REQUIRED)
set(MY_GUI_LIB_PATH_SRC ${PROJECT_SOURCE_DIR}/GUI_Qt/CrazyFlyGUI/src)
set(MY_GUI_LIB_PATH_INC ${PROJECT_SOURCE_DIR}/GUI_Qt/CrazyFlyGUI/include)
# GUI -- Resource file
set(MY_RESOURCE_FILE_QRC ${PROJECT_SOURCE_DIR}/GUI_Qt/CrazyFlyGUI/CrazyFlyGUI.qrc)
# StudentGUI -- Add src and includes
set(STUDENT_GUI_LIB_PATH_SRC ${PROJECT_SOURCE_DIR}/GUI_Qt/studentGUI/src)
set(STUDENT_GUI_LIB_PATH_INC ${PROJECT_SOURCE_DIR}/GUI_Qt/studentGUI/include)
# GUI -- Resource file
set(MY_RESOURCE_FILE_QRC ${PROJECT_SOURCE_DIR}/GUI_Qt/CrazyFlyGUI/CrazyFlyGUI.qrc)
# StudentGUI -- Resource file
set(STUDENT_RESOURCE_FILE_QRC ${PROJECT_SOURCE_DIR}/GUI_Qt/studentGUI/studentgui.qrc)
# #set the default path for built executables to the "bin" directory
# set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
......@@ -105,6 +111,9 @@ set(SRC_HDRS_QOBJECT_STUDENT_GUI
qt5_wrap_ui(UIS_HDRS_STUDENT_GUI ${STUDENT_GUI_LIB_PATH_SRC}/MainWindow.ui)
qt5_wrap_cpp(SRC_MOC_HDRS_STUDENT_GUI ${SRC_HDRS_QOBJECT_STUDENT_GUI})
# GUI -- wrap resource file qrc->rcc
qt5_add_resources(STUDENT_RESOURCE_FILE_RCC ${STUDENT_RESOURCE_FILE_QRC})
## Uncomment this if the package has a setup.py. This macro ensures
......@@ -309,7 +318,7 @@ add_executable(my_GUI ${MY_CPP_SOURCES_GUI} ${UIS_HDRS_GUI} ${SRC_MOC_HDRS_GUI}
qt5_use_modules(my_GUI Widgets)
# StudentGUI -- Add executables here
add_executable(student_GUI ${MY_CPP_SOURCES_STUDENT_GUI} ${UIS_HDRS_STUDENT_GUI} ${SRC_MOC_HDRS_STUDENT_GUI})
add_executable(student_GUI ${MY_CPP_SOURCES_STUDENT_GUI} ${UIS_HDRS_STUDENT_GUI} ${SRC_MOC_HDRS_STUDENT_GUI} ${STUDENT_RESOURCE_FILE_RCC})
qt5_use_modules(student_GUI Widgets)
......
......@@ -89,6 +89,15 @@
#define BATTERY_STATE_NORMAL 0
#define BATTERY_STATE_LOW 1
// Battery label image index
#define BATTERY_LABEL_IMAGE_INDEX_EMPTY 0
#define BATTERY_LABEL_IMAGE_INDEX_20 1
#define BATTERY_LABEL_IMAGE_INDEX_40 2
#define BATTERY_LABEL_IMAGE_INDEX_60 3
#define BATTERY_LABEL_IMAGE_INDEX_80 4
#define BATTERY_LABEL_IMAGE_INDEX_FULL 5
#define BATTERY_LABEL_IMAGE_INDEX_UNKNOWN 6
// For which controller parameters to load
#define LOAD_YAML_SAFE_CONTROLLER_AGENT 1
#define LOAD_YAML_DEMO_CONTROLLER_AGENT 2
......@@ -210,7 +219,17 @@ private:
Setpoint m_student_setpoint;
Setpoint m_mpc_setpoint;
int m_flying_state;
int m_battery_state;
// BATTERY EMPTY VOLTAGES (THESE SHOULD BE READ IN AS PARAMTERS)
//const std::vector<float> m_cutoff_voltages {3.1966, 3.2711, 3.3061, 3.3229, 3.3423, 3.3592, 3.3694, 3.385, 3.4006, 3.4044, 3.4228, 3.4228, 3.4301, 3.4445, 3.4531, 3.4677, 3.4705, 3.4712, 3.4756, 3.483, 3.4944, 3.5008, 3.5008, 3.5084, 3.511, 3.5122, 3.5243, 3.5329, 3.5412, 3.5529, 3.5609, 3.5625, 3.5638, 3.5848, 3.6016, 3.6089, 3.6223, 3.628, 3.6299, 3.6436, 3.6649, 3.6878, 3.6983, 3.7171, 3.7231, 3.7464, 3.7664, 3.7938, 3.8008, 3.816, 3.8313, 3.8482, 3.866, 3.8857, 3.8984, 3.9159, 3.9302, 3.9691, 3.997, 4.14 };
const float battery_voltage_empty_while_flying = 2.80; // in Volts
const float battery_voltage_empty_while_motors_off = 3.30; // in Volts
// BATTERY FULL VOLTAGES
const float battery_voltage_full_while_flying = 3.70; // in Volts
const float battery_voltage_full_while_motors_off = 4.20; // in Volts
int m_battery_label_image_current_index;
ros::Publisher crazyRadioCommandPublisher;
ros::Subscriber crazyRadioStatusSubscriber;
......@@ -326,7 +345,6 @@ private:
bool setpointInsideBox(Setpoint setpoint, CrazyflieContext context);
Setpoint correctSetpointBox(Setpoint setpoint, CrazyflieContext context);
const std::vector<float> m_cutoff_voltages {3.1966, 3.2711, 3.3061, 3.3229, 3.3423, 3.3592, 3.3694, 3.385, 3.4006, 3.4044, 3.4228, 3.4228, 3.4301, 3.4445, 3.4531, 3.4677, 3.4705, 3.4712, 3.4756, 3.483, 3.4944, 3.5008, 3.5008, 3.5084, 3.511, 3.5122, 3.5243, 3.5329, 3.5412, 3.5529, 3.5609, 3.5625, 3.5638, 3.5848, 3.6016, 3.6089, 3.6223, 3.628, 3.6299, 3.6436, 3.6649, 3.6878, 3.6983, 3.7171, 3.7231, 3.7464, 3.7664, 3.7938, 3.8008, 3.816, 3.8313, 3.8482, 3.866, 3.8857, 3.8984, 3.9159, 3.9302, 3.9691, 3.997, 4.14 };
};
#endif // MAINWINDOW_H
......@@ -169,9 +169,36 @@ MainWindow::MainWindow(int argc, char **argv, QWidget *parent) :
disableGUI();
highlightSafeControllerTab();
ui->label_battery->setStyleSheet("QLabel { color : red; }");
// INITIALISE THE BATTERY STATE AS NORMAL
m_battery_state = BATTERY_STATE_NORMAL;
// SET THE BATTERY VOLTAGE FIELD TO BE BLANK
QString qstr = "-.-- V";
ui->voltage_field->setText(qstr);
// SET THE IMAGE FOR THE BATTERY STATUS LABEL
QPixmap battery_unknown_pixmap(":/images/battery_unknown.png");
ui->battery_status_label->setPixmap(battery_unknown_pixmap);
ui->battery_status_label->setScaledContents(true);
m_battery_label_image_current_index = BATTERY_LABEL_IMAGE_INDEX_UNKNOWN;
// SET THE IMAGE FOR THE CRAZY RADIO STATUS LABEL
QPixmap rf_disconnected_pixmap(":/images/rf_disconnected.png");
ui->rf_status_label->setPixmap(rf_disconnected_pixmap);
ui->rf_status_label->setScaledContents(true);
// SET THE IMAGE FOR THE FLYING STATE LABEL
QPixmap flying_state_off_pixmap(":/images/flying_state_off.png");
ui->flying_state_label->setPixmap(flying_state_off_pixmap);
ui->flying_state_label->setScaledContents(true);
//QPixmap battery_80_pixmap(":/images/battery_80.png");
//m_battery_80_pixmap = battery_80_pixmap.scaled(50,70,Qt::IgnoreAspectRatio);
// The syntax for "scaled" is (int width, int height, ...)
ui->error_label->setStyleSheet("QLabel { color : red; }");
ui->error_label->clear();
......@@ -340,25 +367,68 @@ void MainWindow::mpcSetpointCallback(const Setpoint& newSetpoint)
void MainWindow::flyingStateChangedCallback(const std_msgs::Int32& msg)
{
QString qstr = "Flying State: ";
// PUT THE CURRENT STATE INTO THE CLASS VARIABLE
m_flying_state = msg.data;
// UPDATE THE LABEL TO DISPLAY THE FLYING STATE
//QString qstr = "Flying State: ";
switch(msg.data)
{
case STATE_MOTORS_OFF:
qstr.append("Motors OFF");
{
//qstr.append("Motors OFF");
// SET THE APPROPRIATE IMAGE FOR THE FLYING STATE LABEL
QPixmap flying_state_off_pixmap(":/images/flying_state_off.png");
ui->flying_state_label->setPixmap(flying_state_off_pixmap);
ui->flying_state_label->setScaledContents(true);
ui->flying_state_label->update();
break;
}
case STATE_TAKE_OFF:
qstr.append("Take OFF");
{
//qstr.append("Take OFF");
// SET THE APPROPRIATE IMAGE FOR THE FLYING STATE LABEL
QPixmap flying_state_enabling_pixmap(":/images/flying_state_enabling.png");
ui->flying_state_label->setPixmap(flying_state_enabling_pixmap);
ui->flying_state_label->setScaledContents(true);
ui->flying_state_label->update();
break;
}
case STATE_FLYING:
qstr.append("Flying");
{
//qstr.append("Flying");
// SET THE APPROPRIATE IMAGE FOR THE FLYING STATE LABEL
QPixmap flying_state_flying_pixmap(":/images/flying_state_flying.png");
ui->flying_state_label->setPixmap(flying_state_flying_pixmap);
ui->flying_state_label->setScaledContents(true);
ui->flying_state_label->update();
break;
}
case STATE_LAND:
qstr.append("Land");
{
//qstr.append("Land");
// SET THE APPROPRIATE IMAGE FOR THE FLYING STATE LABEL
QPixmap flying_state_disabling_pixmap(":/images/flying_state_disabling.png");
ui->flying_state_label->setPixmap(flying_state_disabling_pixmap);
ui->flying_state_label->setScaledContents(true);
ui->flying_state_label->update();
break;
}
default:
{
// SET THE APPROPRIATE IMAGE FOR THE FLYING STATE LABEL
QPixmap flying_state_unknown_pixmap(":/images/flying_state_unknown.png");
ui->flying_state_label->setPixmap(flying_state_unknown_pixmap);
ui->flying_state_label->setScaledContents(true);
ui->flying_state_label->update();
break;
}
}
ui->flying_state_label->setText(qstr);
//ui->flying_state_label->setText(qstr);
}
void MainWindow::batteryStateChangedCallback(const std_msgs::Int32& msg)
......@@ -368,22 +438,28 @@ void MainWindow::batteryStateChangedCallback(const std_msgs::Int32& msg)
switch(msg.data)
{
case BATTERY_STATE_LOW:
qstr.append("Low Battery!");
{
// DISABLE THE TAKE OFF AND LAND BUTTONS
ui->take_off_button->setEnabled(false);
ui->land_button->setEnabled(false);
// ui->groupBox_4->setEnabled(false);
ui->label_battery->setText(qstr);
// SET THE CLASS VARIABLE FOR TRACKING THE BATTERY STATE
m_battery_state = BATTERY_STATE_LOW;
break;
}
case BATTERY_STATE_NORMAL:
{
// ui->groupBox_4->setEnabled(true);
ui->take_off_button->setEnabled(true);
ui->land_button->setEnabled(true);
ui->label_battery->clear();
// SET THE CLASS VARIABLE FOR TRACKING THE BATTERY STATE
m_battery_state = BATTERY_STATE_NORMAL;
break;
}
default:
break;
}
......@@ -396,61 +472,253 @@ void MainWindow::setCrazyRadioStatus(int radio_status)
switch(radio_status)
{
case CONNECTED:
// change icon, the rest of the GUI is available now
ui->connected_disconnected_label->setText("Crazyradio status: Connected!");
{
// SET THE APPROPRIATE IMAGE FOR THE RADIOSTATUS LABEL
QPixmap rf_connected_pixmap(":/images/rf_connected.png");
ui->rf_status_label->setPixmap(rf_connected_pixmap);
ui->rf_status_label->setScaledContents(true);
ui->rf_status_label->update();
// ENABLE THE REMAINDER OF THE GUI
enableGUI();
break;
}
case CONNECTING:
// change icon
ui->connected_disconnected_label->setText("Crazyradio status: Connecting...");
{
// SET THE APPROPRIATE IMAGE FOR THE RADIO STATUS LABEL
QPixmap rf_connecting_pixmap(":/images/rf_connecting.png");
ui->rf_status_label->setPixmap(rf_connecting_pixmap);
ui->rf_status_label->setScaledContents(true);
ui->rf_status_label->update();
// SET THE BATTERY VOLTAGE FIELD TO BE BLANK
// QString qstr = "-.-- V";
// ui->voltage_field->setText(qstr);
break;
}
case DISCONNECTED:
// change icon, the rest of the GUI is disabled
ui->connected_disconnected_label->setText("Crazyradio status: Disconnected");
{
// SET THE APPROPRIATE IMAGE FOR THE RADIO STATUS LABEL
QPixmap rf_disconnected_pixmap(":/images/rf_disconnected.png");
ui->rf_status_label->setPixmap(rf_disconnected_pixmap);
ui->rf_status_label->setScaledContents(true);
ui->rf_status_label->update();
// SET THE BATTERY VOLTAGE FIELD TO BE BLANK
QString qstr = "-.-- V";
ui->voltage_field->setText(qstr);
// SET THE APPROPRIATE IMAGE FOR THE BATTERY STATUS LABEL
if (m_battery_label_image_current_index != BATTERY_LABEL_IMAGE_INDEX_UNKNOWN)
{
QPixmap battery_unknown_pixmap(":/images/battery_unknown.png");
ui->battery_status_label->setPixmap(battery_unknown_pixmap);
ui->battery_status_label->setScaledContents(true);
m_battery_label_image_current_index = BATTERY_LABEL_IMAGE_INDEX_UNKNOWN;
ui->battery_status_label->update();
}
// DISABLE THE REMAINDER OF THE GUI
disableGUI();
break;
}
default:
{
ROS_ERROR_STREAM("unexpected radio status: " << m_radio_status);
break;
}
}
this->m_radio_status = radio_status;
}
float MainWindow::fromVoltageToPercent(float voltage)
{
int num_cutoffs = m_cutoff_voltages.size();
float hysteresis = 0.05;
// INITIALISE THE LOCAL VARIABLE FOR THE VOLTAGE WHEN FULL/EMPTY
float voltage_when_full;
float voltage_when_empty;
// COMPUTE THE PERCENTAGE DIFFERENTLY DEPENDING ON
// THE CURRENT FLYING STATE
if (m_flying_state == STATE_MOTORS_OFF)
{
voltage_when_empty = battery_voltage_empty_while_motors_off;
voltage_when_full = battery_voltage_full_while_motors_off;
}
else
{
voltage_when_empty = battery_voltage_empty_while_flying;
voltage_when_full = battery_voltage_full_while_flying;
}
//voltage_when_empty = battery_voltage_empty_while_motors_off;
//voltage_when_full = battery_voltage_full_while_motors_off;
// COMPUTE THE PERCENTAGE
float percentage = 100.0f * (voltage-voltage_when_empty)/(voltage_when_full-voltage_when_empty);
while(m_battery_level < num_cutoffs && voltage >= m_cutoff_voltages[m_battery_level])
// CLIP THE PERCENTAGE TO BE BETWEEN [0,100]
// > This should not happen to often
if(percentage > 100.0f)
{
++m_battery_level;
percentage = 100.0f;
}
while(m_battery_level > 0 && voltage < m_cutoff_voltages[m_battery_level - 1] - hysteresis)
if(percentage < 0.0f)
{
--m_battery_level;
percentage = 0.0f;
}
float percentage = 100.0 * m_battery_level/num_cutoffs;
// should not hapen, but just in case...
if(percentage > 100)
percentage = 100;
if(percentage < 0)
percentage = 0;
return percentage;
}
void MainWindow::updateBatteryVoltage(float battery_voltage)
{
// PUT THE VOLTAGE INTO THE CLASS VARIABLES
m_battery_voltage = battery_voltage;
// Need to take voltage, display it and transform it to percentage
// int percentage = (int) fromVoltageToPercent(m_battery_voltage);
// UPDATE THE BATTERY VOLTAGE FIELD
QString qstr = "";
qstr.append(QString::number(battery_voltage, 'f', 2));
qstr.append(" V");
ui->voltage_field->setText(qstr);
// COMPUTE THE BATTERY VOLTAGE AS A PERCENTAGE
float battery_voltage_percentage = fromVoltageToPercent(battery_voltage);
//ROS_INFO_STREAM("Battery percentage = " << battery_voltage_percentage );
// UPDATE THE IMAGE DISPLAYED IN THE BATTERY VOLTAGE LABEL IMAGE
switch(m_battery_state)
{
// WHEN THE BATTERY IS IN A LOW STATE
case BATTERY_STATE_LOW:
{
// SET THE IMAGE FOR THE BATTERY STATUS LABEL
if (m_battery_label_image_current_index != BATTERY_LABEL_IMAGE_INDEX_EMPTY)
{
QPixmap battery_empty_pixmap(":/images/battery_empty.png");
ui->battery_status_label->setPixmap(battery_empty_pixmap);
ui->battery_status_label->setScaledContents(true);
m_battery_label_image_current_index = BATTERY_LABEL_IMAGE_INDEX_EMPTY;
ui->battery_status_label->update();
}
break;
}
// WHEN THE BATTERY IS IN A NORMAL STATE
case BATTERY_STATE_NORMAL:
{
if (
((m_battery_label_image_current_index != BATTERY_LABEL_IMAGE_INDEX_EMPTY) && (battery_voltage_percentage <= 0.0f))
||
((m_battery_label_image_current_index == BATTERY_LABEL_IMAGE_INDEX_EMPTY) && (battery_voltage_percentage <= 2.0f))
)
{
if (m_battery_label_image_current_index != BATTERY_LABEL_IMAGE_INDEX_EMPTY)
{
// SET THE IMAGE FOR THE BATTERY STATUS LABEL
QPixmap battery_empty_pixmap(":/images/battery_empty.png");
ui->battery_status_label->setPixmap(battery_empty_pixmap);
ui->battery_status_label->setScaledContents(true);
m_battery_label_image_current_index = BATTERY_LABEL_IMAGE_INDEX_EMPTY;
ui->battery_status_label->update();
}
}
else if (
((m_battery_label_image_current_index != BATTERY_LABEL_IMAGE_INDEX_20) && (battery_voltage_percentage <= 20.0f))
||
((m_battery_label_image_current_index == BATTERY_LABEL_IMAGE_INDEX_20) && (battery_voltage_percentage <= 22.0f))
)
{
if (m_battery_label_image_current_index != BATTERY_LABEL_IMAGE_INDEX_20)
{
// SET THE IMAGE FOR THE BATTERY STATUS LABEL
QPixmap battery_20_pixmap(":/images/battery_20.png");
ui->battery_status_label->setPixmap(battery_20_pixmap);
ui->battery_status_label->setScaledContents(true);
m_battery_label_image_current_index = BATTERY_LABEL_IMAGE_INDEX_20;
ui->battery_status_label->update();
}
}
else if (
((m_battery_label_image_current_index != BATTERY_LABEL_IMAGE_INDEX_40) && (battery_voltage_percentage <= 40.0f))
||
((m_battery_label_image_current_index == BATTERY_LABEL_IMAGE_INDEX_40) && (battery_voltage_percentage <= 42.0f))
)
{
if (m_battery_label_image_current_index != BATTERY_LABEL_IMAGE_INDEX_40)
{
// SET THE IMAGE FOR THE BATTERY STATUS LABEL
QPixmap battery_40_pixmap(":/images/battery_40.png");
ui->battery_status_label->setPixmap(battery_40_pixmap);
ui->battery_status_label->setScaledContents(true);
m_battery_label_image_current_index = BATTERY_LABEL_IMAGE_INDEX_40;
ui->battery_status_label->update();
}
}
else if (
((m_battery_label_image_current_index != BATTERY_LABEL_IMAGE_INDEX_60) && (battery_voltage_percentage <= 60.0f))
||
((m_battery_label_image_current_index == BATTERY_LABEL_IMAGE_INDEX_60) && (battery_voltage_percentage <= 62.0f))
)
{
if (m_battery_label_image_current_index != BATTERY_LABEL_IMAGE_INDEX_60)
{
// SET THE IMAGE FOR THE BATTERY STATUS LABEL
QPixmap battery_60_pixmap(":/images/battery_60.png");
ui->battery_status_label->setPixmap(battery_60_pixmap);
ui->battery_status_label->setScaledContents(true);
m_battery_label_image_current_index = BATTERY_LABEL_IMAGE_INDEX_60;
ui->battery_status_label->update();
}
}
else if (
((m_battery_label_image_current_index != BATTERY_LABEL_IMAGE_INDEX_80) && (battery_voltage_percentage <= 80.0f))
||
((m_battery_label_image_current_index == BATTERY_LABEL_IMAGE_INDEX_80) && (battery_voltage_percentage <= 82.0f))
)
{
if (m_battery_label_image_current_index != BATTERY_LABEL_IMAGE_INDEX_80)
{
// SET THE IMAGE FOR THE BATTERY STATUS LABEL
QPixmap battery_80_pixmap(":/images/battery_80.png");
ui->battery_status_label->setPixmap(battery_80_pixmap);
ui->battery_status_label->setScaledContents(true);
m_battery_label_image_current_index = BATTERY_LABEL_IMAGE_INDEX_80;
ui->battery_status_label->update();
}
}
else
{
if (m_battery_label_image_current_index != BATTERY_LABEL_IMAGE_INDEX_FULL)
{
// SET THE IMAGE FOR THE BATTERY STATUS LABEL
QPixmap battery_full_pixmap(":/images/battery_full.png");
ui->battery_status_label->setPixmap(battery_full_pixmap);
ui->battery_status_label->setScaledContents(true);
m_battery_label_image_current_index = BATTERY_LABEL_IMAGE_INDEX_FULL;
ui->battery_status_label->update();
}
}
break;
}
default:
{
if (m_battery_label_image_current_index != BATTERY_LABEL_IMAGE_INDEX_UNKNOWN)
{
// SET THE IMAGE FOR THE BATTERY STATUS LABEL
QPixmap battery_unknown_pixmap(":/images/battery_unknown.png");
ui->battery_status_label->setPixmap(battery_unknown_pixmap);
ui->battery_status_label->setScaledContents(true);
m_battery_label_image_current_index = BATTERY_LABEL_IMAGE_INDEX_UNKNOWN;
ui->battery_status_label->update();
}
break;
}
}
//ui->battery_status_label->update();
}
void MainWindow::CFBatteryCallback(const std_msgs::Float32& msg)
......@@ -460,7 +728,7 @@ void MainWindow::CFBatteryCallback(const std_msgs::Float32& msg)
void MainWindow::crazyRadioStatusCallback(const std_msgs::Int32& msg)
{
ROS_INFO("Callback CrazyRadioStatus called");
ROS_INFO("[Student GUI] Callback CrazyRadioStatus called");
this->setCrazyRadioStatus(msg.data);
}
......
Markdown is supported
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