Commit ea3e1614 authored by Michael Carpenter's avatar Michael Carpenter

Fixes for Radio Calibration to work with proper min/max values

parent 9b62308e
......@@ -30,11 +30,13 @@ This file is part of the QGROUNDCONTROL project
*/
#include "RadioCalibrationConfig.h"
#include <QMessageBox>
RadioCalibrationConfig::RadioCalibrationConfig(QWidget *parent) : QWidget(parent)
{
ui.setupUi(this);
connect(ui.calibrateButton,SIGNAL(clicked()),this,SLOT(calibrateButtonClicked()));
m_uas = 0;
m_calibrationEnabled = false;
connect(UASManager::instance(), SIGNAL(activeUASSet(UASInterface*)), this, SLOT(setActiveUAS(UASInterface*)));
......@@ -47,6 +49,14 @@ RadioCalibrationConfig::RadioCalibrationConfig(QWidget *parent) : QWidget(parent
ui.throttleWidget->setMax(2200);
ui.yawWidget->setMin(800);
ui.yawWidget->setMax(2200);
ui.radio5Widget->setMin(800);
ui.radio5Widget->setMax(2200);
ui.radio6Widget->setMin(800);
ui.radio6Widget->setMax(2200);
ui.radio7Widget->setMin(800);
ui.radio7Widget->setMax(2200);
ui.radio8Widget->setMin(800);
ui.radio8Widget->setMax(2200);
ui.rollWidget->setOrientation(Qt::Horizontal);
ui.rollWidget->setName("Roll");
ui.yawWidget->setOrientation(Qt::Horizontal);
......@@ -72,12 +82,16 @@ RadioCalibrationConfig::~RadioCalibrationConfig()
void RadioCalibrationConfig::setActiveUAS(UASInterface *uas)
{
if (uas==NULL) return;
if (m_uas)
{
// Disconnect old system
disconnect(m_uas, SIGNAL(remoteControlChannelRawChanged(int,float)), this,SLOT(remoteControlChannelRawChanged(int,float)));
disconnect(m_uas, SIGNAL(parameterChanged(int,int,QString,QVariant)), this,SLOT(parameterChanged(int,int,QString,QVariant)));
}
m_uas = uas;
connect(m_uas,SIGNAL(remoteControlChannelRawChanged(int,float)),this,SLOT(remoteControlChannelRawChanged(int,float)));
connect(m_uas,SIGNAL(parameterChanged(int,int,QString,QVariant)),this,SLOT(parameterChanged(int,int,QString,QVariant)));
}
void RadioCalibrationConfig::remoteControlChannelRawChanged(int chan,float val)
......@@ -115,12 +129,113 @@ void RadioCalibrationConfig::guiUpdateTimerTick()
ui.radio6Widget->setValue(rcValue[5]);
ui.radio7Widget->setValue(rcValue[6]);
ui.radio8Widget->setValue(rcValue[7]);
if (m_calibrationEnabled)
{
ui.rollWidget->setMin(rcMin[0]);
ui.rollWidget->setMax(rcMax[0]);
ui.pitchWidget->setMin(rcMin[1]);
ui.pitchWidget->setMax(rcMax[1]);
ui.throttleWidget->setMin(rcMin[2]);
ui.throttleWidget->setMax(rcMax[2]);
ui.yawWidget->setMin(rcMin[3]);
ui.yawWidget->setMax(rcMax[3]);
ui.radio5Widget->setMin(rcMin[4]);
ui.radio5Widget->setMax(rcMax[4]);
ui.radio6Widget->setMin(rcMin[5]);
ui.radio6Widget->setMax(rcMax[5]);
ui.radio7Widget->setMin(rcMin[6]);
ui.radio7Widget->setMax(rcMax[6]);
ui.radio8Widget->setMin(rcMin[7]);
ui.radio8Widget->setMax(rcMax[7]);
}
}
void RadioCalibrationConfig::showEvent(QShowEvent *event)
{
guiUpdateTimer->stop();
guiUpdateTimer->start(100);
}
void RadioCalibrationConfig::hideEvent(QHideEvent *event)
{
guiUpdateTimer->start(100);
guiUpdateTimer->stop();
}
void RadioCalibrationConfig::calibrateButtonClicked()
{
if (!m_calibrationEnabled)
{
ui.calibrateButton->setText("End Calibration");
QMessageBox::information(0,"Warning!","You are about to start radio calibration.\nPlease ensure all motor power is disconnected AND all props are removed from the vehicle.\nAlso ensure transmitter and reciever are powered and connected\n\nClick OK to confirm");
m_calibrationEnabled = true;
for (int i=0;i<8;i++)
{
rcMin[i] = 1500;
rcMax[i] = 1500;
}
ui.rollWidget->showMinMax();
ui.pitchWidget->showMinMax();
ui.yawWidget->showMinMax();
ui.radio5Widget->showMinMax();
ui.radio6Widget->showMinMax();
ui.radio7Widget->showMinMax();
ui.radio8Widget->showMinMax();
QMessageBox::information(0,"Information","Click OK, then move all sticks to their extreme positions, watching the min/max values to ensure you get the most range from your controller. This includes all switches");
}
else
{
ui.calibrateButton->setText("Calibrate");
QMessageBox::information(0,"Trims","Ensure all sticks are centered and throttle is in the downmost position, click OK to continue");
///TODO: Set trims!
m_calibrationEnabled = false;
ui.rollWidget->hideMinMax();
ui.pitchWidget->hideMinMax();
ui.yawWidget->hideMinMax();
ui.radio5Widget->hideMinMax();
ui.radio6Widget->hideMinMax();
ui.radio7Widget->hideMinMax();
ui.radio8Widget->hideMinMax();
QString statusstr;
statusstr = "Below you will find the detected radio calibration information that will be sent to the autopilot\n";
statusstr += "Normal values are around 1100 to 1900, with disconnected channels reading very close to 1500\n\n";
statusstr += "Channel\tMin\tCenter\tMax\n";
statusstr += "--------------------\n";
for (int i=0;i<8;i++)
{
statusstr += QString::number(i) + "\t" + QString::number(rcMin[i]) + "\t" + QString::number(rcValue[i]) + "\t" + QString::number(rcMax[i]) + "\n";
}
QMessageBox::information(0,"Status",statusstr);
//Send calibrations.
QString minTpl("RC%1_MIN");
QString maxTpl("RC%1_MAX");
//QString trimTpl("RC%1_TRIM");
// Do not write the RC type, as these values depend on this
// active onboard parameter
for (unsigned int i = 0; i < 8; ++i)
{
qDebug() << "SENDING MIN" << minTpl.arg(i+1) << rcMin[i];
qDebug() << "SENDING MAX" << maxTpl.arg(i+1) << rcMax[i];
m_uas->setParameter(0, minTpl.arg(i+1), (float)rcMin[i]);
QGC::SLEEP::usleep(50000);
//m_uas->setParameter(0, trimTpl.arg(i+1), rcTrim[i]);
//QGC::SLEEP::usleep(50000);
m_uas->setParameter(0, maxTpl.arg(i+1), (float)rcMax[i]);
QGC::SLEEP::usleep(50000);
}
ui.rollWidget->setMin(800);
ui.rollWidget->setMax(2200);
ui.pitchWidget->setMin(800);
ui.pitchWidget->setMax(2200);
ui.throttleWidget->setMin(800);
ui.throttleWidget->setMax(2200);
ui.yawWidget->setMin(800);
ui.yawWidget->setMax(2200);
ui.radio5Widget->setMin(800);
ui.radio5Widget->setMax(2200);
ui.radio6Widget->setMin(800);
ui.radio6Widget->setMax(2200);
ui.radio7Widget->setMin(800);
ui.radio7Widget->setMax(2200);
ui.radio8Widget->setMin(800);
ui.radio8Widget->setMax(2200);
}
}
......@@ -54,9 +54,11 @@ private slots:
void remoteControlChannelRawChanged(int chan,float val);
void parameterChanged(int uas, int component, QString parameterName, QVariant value);
void guiUpdateTimerTick();
void calibrateButtonClicked();
private:
double rcMin[8];
double rcMax[8];
double rcTrim[8];
double rcValue[8];
QTimer *guiUpdateTimer;
bool m_calibrationEnabled;
......
......@@ -258,7 +258,7 @@
<rect>
<x>20</x>
<y>360</y>
<width>75</width>
<width>91</width>
<height>23</height>
</rect>
</property>
......
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