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 3b3619a2 authored by beuchatp's avatar beuchatp
Browse files

Battery label display icons, to be tested

parent 76b0b359
......@@ -210,7 +210,15 @@ 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.40 // in Volts
const float battery_voltage_full_while_motors_off = 4.20 // in Volts
ros::Publisher crazyRadioCommandPublisher;
ros::Subscriber crazyRadioStatusSubscriber;
......@@ -326,7 +334,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
......@@ -340,6 +340,10 @@ void MainWindow::mpcSetpointCallback(const Setpoint& newSetpoint)
void MainWindow::flyingStateChangedCallback(const std_msgs::Int32& msg)
{
// 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)
{
......@@ -374,6 +378,13 @@ void MainWindow::batteryStateChangedCallback(const std_msgs::Int32& msg)
// ui->groupBox_4->setEnabled(false);
ui->label_battery->setText(qstr);
// SET THE IMAGE FOR THE BATTERY STATUS LABEL
QPixmap battery_empty_pixmap(":/images/battery_empty.png");
ui->label_battery->setPixmap(battery_empty_pixmap);
ui->label_battery->setScaledContents(true);
// SET THE CLASS VARIABLE FOR TRACKING THE BATTERY STATE
m_battery_state = BATTERY_STATE_LOW;
break;
case BATTERY_STATE_NORMAL:
......@@ -382,6 +393,8 @@ void MainWindow::batteryStateChangedCallback(const std_msgs::Int32& msg)
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:
......@@ -418,21 +431,43 @@ void MainWindow::setCrazyRadioStatus(int radio_status)
float MainWindow::fromVoltageToPercent(float voltage)
{
int num_cutoffs = m_cutoff_voltages.size();
float hysteresis = 0.05;
// int num_cutoffs = m_cutoff_voltages.size();
// float hysteresis = 0.05;
// while(m_battery_level < num_cutoffs && voltage >= m_cutoff_voltages[m_battery_level])
// {
// ++m_battery_level;
// }
// while(m_battery_level > 0 && voltage < m_cutoff_voltages[m_battery_level - 1] - hysteresis)
// {
// --m_battery_level;
// }
// float percentage = 100.0 * m_battery_level/num_cutoffs;
// 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;
}
while(m_battery_level < num_cutoffs && voltage >= m_cutoff_voltages[m_battery_level])
{
++m_battery_level;
}
while(m_battery_level > 0 && voltage < m_cutoff_voltages[m_battery_level - 1] - hysteresis)
{
--m_battery_level;
}
// COMPUTE THE PERCENTAGE
float percentage = 100 * (voltage-voltage_when_empty)/(voltage_when_full-voltage_when_empty)
float percentage = 100.0 * m_battery_level/num_cutoffs;
// should not hapen, but just in case...
// CLIP THE PERCENTAGE TO BE BETWEEN [0,100]
// > This should not happen to often
if(percentage > 100)
percentage = 100;
if(percentage < 0)
......@@ -443,14 +478,81 @@ float MainWindow::fromVoltageToPercent(float voltage)
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
int battery_voltage_percentage = (int) fromVoltageToPercent(m_battery_voltage);
// 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
QPixmap battery_empty_pixmap(":/images/battery_empty.png");
ui->label_battery->setPixmap(battery_empty_pixmap);
ui->label_battery->setScaledContents(true);
break;
// WHEN THE BATTERY IS IN A NORMAL STATE
case BATTERY_STATE_NORMAL:
if (battery_voltage_percentage <= 0)
{
// SET THE IMAGE FOR THE BATTERY STATUS LABEL
QPixmap battery_empty_pixmap(":/images/battery_empty.png");
ui->label_battery->setPixmap(battery_empty_pixmap);
ui->label_battery->setScaledContents(true);
}
else if (battery_voltage_percentage <= 20)
{
// SET THE IMAGE FOR THE BATTERY STATUS LABEL
QPixmap battery_20_pixmap(":/images/battery_20.png");
ui->label_battery->setPixmap(battery_20_pixmap);
ui->label_battery->setScaledContents(true);
}
else if (battery_voltage_percentage <= 40)
{
// SET THE IMAGE FOR THE BATTERY STATUS LABEL
QPixmap battery_40_pixmap(":/images/battery_40.png");
ui->label_battery->setPixmap(battery_40_pixmap);
ui->label_battery->setScaledContents(true);
}
else if (battery_voltage_percentage <= 60)
{
// SET THE IMAGE FOR THE BATTERY STATUS LABEL
QPixmap battery_60_pixmap(":/images/battery_60.png");
ui->label_battery->setPixmap(battery_60_pixmap);
ui->label_battery->setScaledContents(true);
}
else if (battery_voltage_percentage <= 80)
{
// SET THE IMAGE FOR THE BATTERY STATUS LABEL
QPixmap battery_80_pixmap(":/images/battery_80.png");
ui->label_battery->setPixmap(battery_80_pixmap);
ui->label_battery->setScaledContents(true);
}
else
{
// SET THE IMAGE FOR THE BATTERY STATUS LABEL
QPixmap battery_full_pixmap(":/images/battery_full.png");
ui->label_battery->setPixmap(battery_full_pixmap);
ui->label_battery->setScaledContents(true);
}
break;
default:
break;
}
}
void MainWindow::CFBatteryCallback(const std_msgs::Float32& msg)
......
......@@ -169,10 +169,16 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>180</width>
<height>80</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>750</width>
<height>100</height>
<height>80</height>
</size>
</property>
<property name="font">
......@@ -185,6 +191,31 @@
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="rf_status_label">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>90</width>
<height>80</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>90</width>
<height>80</height>
</size>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="RF_Connect_button">
<property name="sizePolicy">
......@@ -193,10 +224,16 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>180</width>
<height>80</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>750</width>
<height>100</height>
<height>80</height>
</size>
</property>
<property name="font">
......@@ -210,57 +247,65 @@
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_8">
<item>
<widget class="QLineEdit" name="voltage_field">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>50</height>
</size>
</property>
<property name="font">
<font>
<pointsize>16</pointsize>
</font>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_battery">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>50</height>
</size>
</property>
<property name="font">
<font>
<pointsize>16</pointsize>
<italic>true</italic>
</font>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
<widget class="QLineEdit" name="voltage_field">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>180</width>
<height>80</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>400</width>
<height>80</height>
</size>
</property>
<property name="font">
<font>
<pointsize>16</pointsize>
</font>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_battery">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>90</width>
<height>80</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>90</width>
<height>80</height>
</size>
</property>
<property name="font">
<font>
<pointsize>16</pointsize>
<italic>true</italic>
</font>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="take_off_button">
......@@ -270,10 +315,16 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>180</width>
<height>80</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>100</height>
<width>750</width>
<height>80</height>
</size>
</property>
<property name="font">
......@@ -294,10 +345,16 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>180</width>
<height>80</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>100</height>
<width>750</width>
<height>80</height>
</size>
</property>
<property name="font">
......@@ -318,10 +375,16 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>180</width>
<height>80</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>100</height>
<width>750</width>
<height>80</height>
</size>
</property>
<property name="font">
......
<RCC>
<qresource prefix="/">
<file>images/battery_20.png</file>
<file>images/battery_40.png</file>
<file>images/battery_60.png</file>
<file>images/battery_80.png</file>
<file>images/battery_empty.png</file>
<file>images/battery_full.png</file>
<file>images/rf_connected.png</file>
<file>images/rf_connecting.png</file>
<file>images/rf_disconnected.png</file>
</qresource>
</RCC>
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