From f487ed385293720e89b3128a1e5d382c5a499ef5 Mon Sep 17 00:00:00 2001 From: Fredrik Larson Date: Sun, 28 Sep 2014 15:05:17 +1000 Subject: [PATCH] Start on ESC Calib page --- .../setupwizard/pages/esccalibrationpage.cpp | 131 ++++++++++++++++++ .../setupwizard/pages/esccalibrationpage.h | 63 +++++++++ .../setupwizard/pages/esccalibrationpage.ui | 73 ++++++++++ 3 files changed, 267 insertions(+) create mode 100644 ground/openpilotgcs/src/plugins/setupwizard/pages/esccalibrationpage.cpp create mode 100644 ground/openpilotgcs/src/plugins/setupwizard/pages/esccalibrationpage.h create mode 100644 ground/openpilotgcs/src/plugins/setupwizard/pages/esccalibrationpage.ui diff --git a/ground/openpilotgcs/src/plugins/setupwizard/pages/esccalibrationpage.cpp b/ground/openpilotgcs/src/plugins/setupwizard/pages/esccalibrationpage.cpp new file mode 100644 index 000000000..766d1aa75 --- /dev/null +++ b/ground/openpilotgcs/src/plugins/setupwizard/pages/esccalibrationpage.cpp @@ -0,0 +1,131 @@ +/** + ****************************************************************************** + * + * @file EscCalibrationPage.cpp + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2014. + * @addtogroup + * @{ + * @addtogroup EscCalibrationPage + * @{ + * @brief + *****************************************************************************/ +/* + * This program 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. + * + * This program 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 this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include +#include "esccalibrationpage.h" +#include "ui_esccalibrationpage.h" +#include "setupwizard.h" + +EscCalibrationPage::EscCalibrationPage(SetupWizard *wizard, QWidget *parent) : + AbstractWizardPage(wizard, parent), + ui(new Ui::EscCalibrationPage), m_calibrationUtil(0) +{ + ui->setupUi(this); + connect(ui->levelButton, SIGNAL(clicked()), this, SLOT(performCalibration())); +} + +EscCalibrationPage::~EscCalibrationPage() +{ + delete ui; +} + +bool EscCalibrationPage::validatePage() +{ + return true; +} + +bool EscCalibrationPage::isComplete() const +{ + return ui->levelButton->isEnabled(); +} + +void EscCalibrationPage::enableButtons(bool enable) +{ + ui->levelButton->setEnabled(enable); + getWizard()->button(QWizard::NextButton)->setEnabled(enable); + getWizard()->button(QWizard::CancelButton)->setEnabled(enable); + getWizard()->button(QWizard::BackButton)->setEnabled(enable); + getWizard()->button(QWizard::CustomButton1)->setEnabled(enable); + QApplication::processEvents(); +} + +void EscCalibrationPage::performCalibration() +{ + if (!getWizard()->getConnectionManager()->isConnected()) { + QMessageBox msgBox; + msgBox.setText(tr("An OpenPilot controller must be connected to your computer to perform bias " + "calculations.\nPlease connect your OpenPilot controller to your computer and try again.")); + msgBox.setStandardButtons(QMessageBox::Ok); + msgBox.setDefaultButton(QMessageBox::Ok); + msgBox.exec(); + return; + } + + enableButtons(false); + ui->progressLabel->setText(QString(tr("Retrieving data..."))); + + + if (!m_calibrationUtil) { + m_calibrationUtil = new BiasCalibrationUtil(BIAS_CYCLES, BIAS_RATE); + } + + connect(m_calibrationUtil, SIGNAL(progress(long, long)), this, SLOT(calibrationProgress(long, long))); + connect(m_calibrationUtil, SIGNAL(done(accelGyroBias)), this, SLOT(calibrationDone(accelGyroBias))); + connect(m_calibrationUtil, SIGNAL(timeout(QString)), this, SLOT(calibrationTimeout(QString))); + + m_calibrationUtil->start(); +} + +void EscCalibrationPage::calibrationProgress(long current, long total) +{ + if (ui->levellinProgressBar->maximum() != (int)total) { + ui->levellinProgressBar->setMaximum((int)total); + } + if (ui->levellinProgressBar->value() != (int)current) { + ui->levellinProgressBar->setValue((int)current); + } +} + +void EscCalibrationPage::calibrationDone(accelGyroBias bias) +{ + stopCalibration(); + getWizard()->setLevellingBias(bias); + emit completeChanged(); +} + +void EscCalibrationPage::calibrationTimeout(QString message) +{ + stopCalibration(); + + QMessageBox msgBox; + msgBox.setText(message); + msgBox.setStandardButtons(QMessageBox::Ok); + msgBox.setDefaultButton(QMessageBox::Ok); + msgBox.exec(); +} + +void EscCalibrationPage::stopCalibration() +{ + if (m_calibrationUtil) { + disconnect(m_calibrationUtil, SIGNAL(progress(long, long)), this, SLOT(calibrationProgress(long, long))); + disconnect(m_calibrationUtil, SIGNAL(done(accelGyroBias)), this, SLOT(calibrationDone(accelGyroBias))); + disconnect(m_calibrationUtil, SIGNAL(timeout(QString)), this, SLOT(calibrationTimeout(QString))); + ui->progressLabel->setText(QString(tr("Done!"))); + enableButtons(true); + } +} diff --git a/ground/openpilotgcs/src/plugins/setupwizard/pages/esccalibrationpage.h b/ground/openpilotgcs/src/plugins/setupwizard/pages/esccalibrationpage.h new file mode 100644 index 000000000..5c1a55f11 --- /dev/null +++ b/ground/openpilotgcs/src/plugins/setupwizard/pages/esccalibrationpage.h @@ -0,0 +1,63 @@ +/** + ****************************************************************************** + * + * @file biascalibrationpage.h + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. + * @addtogroup + * @{ + * @addtogroup BiasCalibrationPage + * @{ + * @brief + *****************************************************************************/ +/* + * This program 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. + * + * This program 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 this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef ESCCALIBRATIONPAGE_H +#define ESCCALIBRATIONPAGE_H + +#include "abstractwizardpage.h" + +namespace Ui { +class EscCalibrationPage; +} + +class EscCalibrationPage : public AbstractWizardPage { + Q_OBJECT + +public: + explicit EscCalibrationPage(SetupWizard *wizard, QWidget *parent = 0); + ~EscCalibrationPage(); + bool validatePage(); + bool isComplete() const; + +private slots: + void performCalibration(); + void calibrationProgress(long current, long total); + void calibrationDone(accelGyroBias bias); + void calibrationTimeout(QString message); + +private: + static const int BIAS_CYCLES = 200; + static const int BIAS_RATE = 50; + + Ui::EscCalibrationPage *ui; + BiasCalibrationUtil *m_calibrationUtil; + + void stopCalibration(); + void enableButtons(bool enable); +}; + +#endif // ESCCALIBRATIONPAGE_H diff --git a/ground/openpilotgcs/src/plugins/setupwizard/pages/esccalibrationpage.ui b/ground/openpilotgcs/src/plugins/setupwizard/pages/esccalibrationpage.ui new file mode 100644 index 000000000..e00a9fe94 --- /dev/null +++ b/ground/openpilotgcs/src/plugins/setupwizard/pages/esccalibrationpage.ui @@ -0,0 +1,73 @@ + + + BiasCalibrationPage + + + + 0 + 0 + 600 + 400 + + + + WizardPage + + + + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8pt; font-weight:400; font-style:normal;"> +<p align="center" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:12pt; font-weight:600;">OpenPilot ESC Calibration Procedure</span></p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:12pt; font-weight:600;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:10pt;">As you have selected to use a MultiRotor and Fast / Flashed ESCs, we need to calibrate the endpoints of these ESCs so they can see the full throttle range from the flight controller. </span></p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:10pt;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:10pt;">This part of the wizard will tell you to connect the battery to your aircraft, before doing so you </span><span style=" font-family:'MS Shell Dlg 2,sans-serif'; font-size:10pt;">absolutely must </span><span style=" font-family:'MS Shell Dlg 2,sans-serif'; font-size:10pt; font-weight:600; color:#ff0000;">remove the props from all motors</span><span style=" font-family:'MS Shell Dlg 2,sans-serif'; font-size:10pt;">.</span> </p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:10pt;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:10pt;">The steps to perform this calibration are as follows:</span></p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:10pt;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:10pt;">1. Press the start button on this page </span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:10pt;">2. Connect the battery to your airframe</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:10pt;">3. Wait for 2 seconds after the ESC beeps stop </span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:10pt;">4. Press the stop button on this page</span></p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:10pt;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:10pt;">When ready push the start button below.</span></p></body></html> + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + true + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + + + + + +