Commit 0b4fb183 authored by Michael Carpenter's avatar Michael Carpenter

Implementation of Battery Monitor configuration, and addition of...

Implementation of Battery Monitor configuration, and addition of AP2ConfigWidget, which automatically handles UAS connections to allow for simpler configuration window code.
parent a6f871ba
......@@ -424,7 +424,8 @@ HEADERS += src/MG.h \
src/ui/configuration/OpticalFlowConfig.h \
src/ui/configuration/OsdConfig.h \
src/ui/configuration/AntennaTrackerConfig.h \
src/ui/configuration/CameraGimbalConfig.h
src/ui/configuration/CameraGimbalConfig.h \
src/ui/configuration/AP2ConfigWidget.h
# Google Earth is only supported on Mac OS and Windows with Visual Studio Compiler
macx|macx-g++|macx-g++42|win32-msvc2008|win32-msvc2010|win32-msvc2012::HEADERS += src/ui/map3D/QGCGoogleEarthView.h
......@@ -616,7 +617,8 @@ SOURCES += src/main.cc \
src/ui/configuration/OpticalFlowConfig.cc \
src/ui/configuration/OsdConfig.cc \
src/ui/configuration/AntennaTrackerConfig.cc \
src/ui/configuration/CameraGimbalConfig.cc
src/ui/configuration/CameraGimbalConfig.cc \
src/ui/configuration/AP2ConfigWidget.cc
# Enable Google Earth only on Mac OS and Windows with Visual Studio compiler
macx|macx-g++|macx-g++42|win32-msvc2008|win32-msvc2010|win32-msvc2012::SOURCES += src/ui/map3D/QGCGoogleEarthView.cc
......
......@@ -110,6 +110,7 @@
<file>files/images/mavs/frames_x.png</file>
<file>files/images/mavs/frames-05.png</file>
<file>files/images/devices/BR-HMC5883-01-2.jpg</file>
<file>files/images/devices/BR-APMPWRDEAN-2.jpg</file>
</qresource>
<qresource prefix="/general">
<file alias="vera.ttf">files/styles/Vera.ttf</file>
......
#include "AP2ConfigWidget.h"
AP2ConfigWidget::AP2ConfigWidget(QWidget *parent) : QWidget(parent)
{
m_uas = 0;
connect(UASManager::instance(),SIGNAL(activeUASSet(UASInterface*)),this,SLOT(activeUASSet(UASInterface*)));
activeUASSet(UASManager::instance()->getActiveUAS());
}
void AP2ConfigWidget::activeUASSet(UASInterface *uas)
{
if (!uas) return;
if (m_uas)
{
disconnect(m_uas,SIGNAL(parameterChanged(int,int,QString,QVariant)),this,SLOT(parameterChanged(int,int,QString,QVariant)));
}
m_uas = uas;
connect(m_uas,SIGNAL(parameterChanged(int,int,QString,QVariant)),this,SLOT(parameterChanged(int,int,QString,QVariant)));
}
void AP2ConfigWidget::parameterChanged(int uas, int component, QString parameterName, QVariant value)
{
}
#ifndef AP2CONFIGWIDGET_H
#define AP2CONFIGWIDGET_H
#include <QWidget>
#include "UASManager.h"
#include "UASInterface.h"
class AP2ConfigWidget : public QWidget
{
Q_OBJECT
public:
explicit AP2ConfigWidget(QWidget *parent = 0);
protected:
UASInterface *m_uas;
signals:
public slots:
virtual void activeUASSet(UASInterface *uas);
virtual void parameterChanged(int uas, int component, QString parameterName, QVariant value);
};
#endif // AP2CONFIGWIDGET_H
#include "BatteryMonitorConfig.h"
#include <QMessageBox>
BatteryMonitorConfig::BatteryMonitorConfig(QWidget *parent) : QWidget(parent)
BatteryMonitorConfig::BatteryMonitorConfig(QWidget *parent) : AP2ConfigWidget(parent)
{
ui.setupUi(this);
ui.monitorComboBox->addItem("0: Disabled");
ui.monitorComboBox->addItem("3: Battery Volts");
ui.monitorComboBox->addItem("4: Voltage and Current");
ui.sensorComboBox->addItem("0: Other");
ui.sensorComboBox->addItem("1: AttoPilot 45A");
ui.sensorComboBox->addItem("2: AttoPilot 90A");
ui.sensorComboBox->addItem("3: AttoPilot 180A");
ui.sensorComboBox->addItem("4: 3DR Power Module");
ui.apmVerComboBox->addItem("0: APM1");
ui.apmVerComboBox->addItem("1: APM2 - 2.5 non 3DR");
ui.apmVerComboBox->addItem("2: APM2.5 - 3DR Power Module");
ui.apmVerComboBox->addItem("3: PX4");
connect(ui.monitorComboBox,SIGNAL(currentIndexChanged(int)),this,SLOT(monitorCurrentIndexChanged(int)));
connect(ui.sensorComboBox,SIGNAL(currentIndexChanged(int)),this,SLOT(sensorCurrentIndexChanged(int)));
connect(ui.apmVerComboBox,SIGNAL(currentIndexChanged(int)),this,SLOT(apmVerCurrentIndexChanged(int)));
connect(ui.calcDividerLineEdit,SIGNAL(editingFinished()),this,SLOT(calcDividerSet()));
connect(ui.ampsPerVoltsLineEdit,SIGNAL(editingFinished()),this,SLOT(ampsPerVoltSet()));
connect(ui.battCapacityLineEdit,SIGNAL(editingFinished()),this,SLOT(batteryCapacitySet()));
ui.alertOnLowCheckBox->setVisible(false);
}
void BatteryMonitorConfig::calcDividerSet()
{
bool ok = false;
float newval = ui.calcDividerLineEdit->text().toFloat(&ok);
if (!ok)
{
//Error parsing;
QMessageBox::information(0,"Error","Invalid number entered for voltage divider. Please try again");
return;
}
m_uas->setParameter(0,"VOLT_DIVIDER",newval);
}
void BatteryMonitorConfig::ampsPerVoltSet()
{
bool ok = false;
float newval = ui.ampsPerVoltsLineEdit->text().toFloat(&ok);
if (!ok)
{
//Error parsing;
QMessageBox::information(0,"Error","Invalid number entered for amps per volts. Please try again");
return;
}
m_uas->setParameter(0,"AMPS_PER_VOLT",newval);
}
void BatteryMonitorConfig::batteryCapacitySet()
{
bool ok = false;
float newval = ui.battCapacityLineEdit->text().toFloat(&ok);
if (!ok)
{
//Error parsing;
QMessageBox::information(0,"Error","Invalid number entered for amps per volts. Please try again");
return;
}
m_uas->setParameter(0,"BATT_CAPACITY",newval);
}
void BatteryMonitorConfig::monitorCurrentIndexChanged(int index)
{
if (!m_uas)
{
QMessageBox::information(0,tr("Error"),tr("Please connect to a MAV before attempting to set configuration"));
return;
}
if (index == 0)
{
m_uas->setParameter(0,"BATT_VOLT_PIN",-1);
m_uas->setParameter(0,"BATT_CURR_PIN",-1);
m_uas->setParameter(0,"BATT_MONITOR",0);
ui.sensorComboBox->setEnabled(false);
ui.apmVerComboBox->setEnabled(false);
ui.measuredVoltsLineEdit->setEnabled(false);
ui.measuredVoltsLineEdit->setEnabled(false);
ui.calcDividerLineEdit->setEnabled(false);
ui.calcVoltsLineEdit->setEnabled(false);
ui.ampsPerVoltsLineEdit->setEnabled(false);
}
else if (index == 1)
{
m_uas->setParameter(0,"BATT_MONITOR",3);
ui.sensorComboBox->setEnabled(false);
ui.apmVerComboBox->setEnabled(true);
ui.measuredVoltsLineEdit->setEnabled(true);
ui.calcDividerLineEdit->setEnabled(true);
ui.calcVoltsLineEdit->setEnabled(false);
ui.ampsPerVoltsLineEdit->setEnabled(false);
}
else if (index == 2)
{
m_uas->setParameter(0,"BATT_MONITOR",4);
ui.sensorComboBox->setEnabled(true);
ui.apmVerComboBox->setEnabled(true);
ui.measuredVoltsLineEdit->setEnabled(true);
ui.calcDividerLineEdit->setEnabled(true);
ui.calcVoltsLineEdit->setEnabled(false);
ui.ampsPerVoltsLineEdit->setEnabled(true);
}
}
void BatteryMonitorConfig::sensorCurrentIndexChanged(int index)
{
float maxvolt = 0;
float maxamps = 0;
float mvpervolt = 0;
float mvperamp = 0;
float topvolt = 0;
float topamps = 0;
if (index == 1)
{
//atto 45
maxvolt = 13.6;
maxamps = 44.7;
mvpervolt = 242.3;
mvperamp = 73.20;
}
else if (index == 2)
{
//atto 90
maxvolt = 50;
maxamps = 89.4;
mvpervolt = 63.69;
mvperamp = 36.60;
}
else if (index == 3)
{
//atto 180
maxvolt = 50;
maxamps = 178.8;
mvpervolt = 63.69;
mvperamp = 18.30;
}
else if (index == 4)
{
//3dr
maxvolt = 50;
maxamps = 90;
mvpervolt = 100;
mvperamp = 55.55;
}
if (index == 0)
{
//Other
ui.ampsPerVoltsLineEdit->setEnabled(true);
ui.calcDividerLineEdit->setEnabled(true);
ui.measuredVoltsLineEdit->setEnabled(true);
}
else
{
topvolt = (maxvolt * mvpervolt) / 1000.0;
topamps = (maxamps * mvperamp) / 1000.0;
ui.calcDividerLineEdit->setText(QString::number(maxvolt/topvolt));
ui.ampsPerVoltsLineEdit->setText(QString::number(maxamps / topamps));
ui.ampsPerVoltsLineEdit->setEnabled(false);
ui.calcDividerLineEdit->setEnabled(false);
ui.measuredVoltsLineEdit->setEnabled(false);
}
}
void BatteryMonitorConfig::apmVerCurrentIndexChanged(int index)
{
}
BatteryMonitorConfig::~BatteryMonitorConfig()
{
}
void BatteryMonitorConfig::parameterChanged(int uas, int component, QString parameterName, QVariant value)
{
if (parameterName == "VOLT_DIVIDER")
{
ui.calcDividerLineEdit->setText(QString::number(value.toFloat(),'f',4));
}
else if (parameterName == "AMP_PER_VOLT")
{
ui.ampsPerVoltsLineEdit->setText(QString::number(value.toFloat(),'g',2));
}
else if (parameterName == "BATT_MONITOR")
{
if (value.toInt() == 0) //0: Disable
{
ui.monitorComboBox->setCurrentIndex(0);
}
else if (value.toInt() == 3) //3: Battery volts
{
ui.monitorComboBox->setCurrentIndex(1);
}
else if (value.toInt() == 4) //4: Voltage and Current
{
ui.monitorComboBox->setCurrentIndex(2);
}
}
else if (parameterName == "BATT_CAPACITY")
{
ui.battCapacityLineEdit->setText(QString::number(value.toFloat()));
}
else if (parameterName == "BATT_VOLT_PIN")
{
int ivalue = value.toInt();
if (ivalue == 0) //APM1
{
ui.apmVerComboBox->setCurrentIndex(0);
}
else if (ivalue == 1) //APM2
{
ui.apmVerComboBox->setCurrentIndex(1);
}
else if (ivalue == 13) //APM2.5
{
ui.apmVerComboBox->setCurrentIndex(2);
}
else if (ivalue == 100) //PX4
{
ui.apmVerComboBox->setCurrentIndex(3);
}
}
else if (parameterName == "BATT_CURR_PIN")
{
//Unused at the moment, everything is off BATT_VOLT_PIN
}
}
......@@ -2,16 +2,24 @@
#define BATTERYMONITORCONFIG_H
#include <QWidget>
#include "AP2ConfigWidget.h"
#include "ui_BatteryMonitorConfig.h"
class BatteryMonitorConfig : public QWidget
class BatteryMonitorConfig : public AP2ConfigWidget
{
Q_OBJECT
public:
explicit BatteryMonitorConfig(QWidget *parent = 0);
~BatteryMonitorConfig();
private slots:
void parameterChanged(int uas, int component, QString parameterName, QVariant value);
void monitorCurrentIndexChanged(int index);
void sensorCurrentIndexChanged(int index);
void apmVerCurrentIndexChanged(int index);
void calcDividerSet();
void ampsPerVoltSet();
void batteryCapacitySet();
private:
Ui::BatteryMonitorConfig ui;
};
......
......@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
<width>745</width>
<height>494</height>
</rect>
</property>
<property name="windowTitle">
......@@ -29,7 +29,203 @@
<bool>false</bool>
</property>
</widget>
<widget class="QLabel" name="label_2">
<property name="geometry">
<rect>
<x>10</x>
<y>70</y>
<width>141</width>
<height>51</height>
</rect>
</property>
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="../../../qgroundcontrol.qrc">:/files/images/devices/BR-APMPWRDEAN-2.jpg</pixmap>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
</widget>
<widget class="QCheckBox" name="alertOnLowCheckBox">
<property name="geometry">
<rect>
<x>480</x>
<y>120</y>
<width>70</width>
<height>17</height>
</rect>
</property>
<property name="text">
<string>CheckBox</string>
</property>
</widget>
<widget class="QGroupBox" name="groupBox">
<property name="geometry">
<rect>
<x>160</x>
<y>170</y>
<width>241</width>
<height>141</height>
</rect>
</property>
<property name="title">
<string>Calibration</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QLabel" name="label_9">
<property name="text">
<string>1. Measured battery voltage:</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_8">
<property name="text">
<string>2. Battery voltage (Calc'ed):</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_10">
<property name="text">
<string>3. Voltage divider (Calc'ed):</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_11">
<property name="text">
<string>4. Amperes per volt:</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLineEdit" name="measuredVoltsLineEdit">
<property name="readOnly">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="calcVoltsLineEdit">
<property name="readOnly">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="calcDividerLineEdit">
<property name="readOnly">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="ampsPerVoltsLineEdit">
<property name="readOnly">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QWidget" name="horizontalLayoutWidget_2">
<property name="geometry">
<rect>
<x>160</x>
<y>70</y>
<width>281</width>
<height>80</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_3" stretch="0,1">
<item>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Monitor</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_4">
<property name="text">
<string>Sensor</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string>APM Version</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QComboBox" name="monitorComboBox"/>
</item>
<item>
<widget class="QComboBox" name="sensorComboBox"/>
</item>
<item>
<widget class="QComboBox" name="apmVerComboBox"/>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QWidget" name="horizontalLayoutWidget_3">
<property name="geometry">
<rect>
<x>470</x>
<y>70</y>
<width>195</width>
<height>41</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="label_13">
<property name="text">
<string>Battery Capacity:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="battCapacityLineEdit"/>
</item>
<item>
<widget class="QLabel" name="label_12">
<property name="text">
<string>mAh</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
<resources/>
<resources>
<include location="../../../qgroundcontrol.qrc"/>
</resources>
<connections/>
</ui>
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