dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
biascalibrationpage.cpp
Go to the documentation of this file.
1 
14 /*
15  * This program is free software; you can redistribute it and/or modify
16  * it under the terms of the GNU General Public License as published by
17  * the Free Software Foundation; either version 3 of the License, or
18  * (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful, but
21  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
22  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23  * for more details.
24  *
25  * You should have received a copy of the GNU General Public License along
26  * with this program; if not, see <http://www.gnu.org/licenses/>
27  */
28 
29 #include <QMessageBox>
30 #include <QDebug>
31 #include "biascalibrationpage.h"
32 #include "ui_biascalibrationpage.h"
33 #include "setupwizard.h"
34 
36  : AbstractWizardPage(wizard, parent)
37  , ui(new Ui::BiasCalibrationPage)
38  , m_calibrationUtil(nullptr)
39 {
40  ui->setupUi(this);
41  connect(ui->levelButton, &QAbstractButton::clicked, this,
42  &BiasCalibrationPage::performCalibration);
43 }
44 
46 {
47  delete ui;
48 }
49 
51 {
52  return true;
53 }
54 
56 {
57  return ui->levelButton->isEnabled();
58 }
59 
60 void BiasCalibrationPage::enableButtons(bool enable)
61 {
62  ui->levelButton->setEnabled(enable);
63  getWizard()->button(QWizard::NextButton)->setEnabled(enable);
64  getWizard()->button(QWizard::CancelButton)->setEnabled(enable);
65  getWizard()->button(QWizard::BackButton)->setEnabled(enable);
66  getWizard()->button(QWizard::CustomButton1)->setEnabled(enable);
67  QApplication::processEvents();
68 }
69 
70 void BiasCalibrationPage::performCalibration()
71 {
72  if (!getWizard()->getConnectionManager()->isConnected()) {
73  QMessageBox msgBox(this);
74  msgBox.setText(tr("A flight controller must be connected to your computer to perform bias "
75  "calculations.\nPlease connect your flight controller to your computer "
76  "and try again."));
77  msgBox.setStandardButtons(QMessageBox::Ok);
78  msgBox.setDefaultButton(QMessageBox::Ok);
79  msgBox.exec();
80  return;
81  }
82 
83  // Get the calibration helper object
84  if (!m_calibrationUtil) {
85  ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
86  m_calibrationUtil = pm->getObject<Calibration>();
87  Q_ASSERT(m_calibrationUtil);
88  if (!m_calibrationUtil)
89  return;
90  }
91 
92  enableButtons(false);
93  ui->progressLabel->setText(QString(tr("Retrieving data...")));
94 
95  QTimer *timer = new QTimer(this);
96  timer->setSingleShot(true);
97  timer->setInterval(30000);
98 
99  connect(m_calibrationUtil, &Calibration::levelingProgressChanged, this,
100  &BiasCalibrationPage::calibrationProgress);
101  connect(m_calibrationUtil, &Calibration::calibrationCompleted, this,
102  &BiasCalibrationPage::calibrationDone);
103  connect(m_calibrationUtil, &Calibration::calibrationCompleted, timer, &QTimer::stop);
104  connect(timer, &QTimer::timeout, this, &BiasCalibrationPage::calibrationTimeout);
105  timer->start();
106  m_calibrationUtil->doStartBiasAndLeveling();
107 }
108 
109 void BiasCalibrationPage::calibrationProgress(int current)
110 {
111  const int total = 100;
112  if (ui->levellinProgressBar->maximum() != (int)total) {
113  ui->levellinProgressBar->setMaximum((int)total);
114  }
115  if (ui->levellinProgressBar->value() != (int)current) {
116  ui->levellinProgressBar->setValue((int)current);
117  }
118 }
119 
120 void BiasCalibrationPage::calibrationDone()
121 {
122  disconnect(this, SLOT(calibrationTimeout()));
123  stopCalibration();
124  emit completeChanged();
125 }
126 
127 void BiasCalibrationPage::calibrationTimeout()
128 {
129  stopCalibration();
130 
131  QMessageBox msgBox(this);
132  msgBox.setText(tr("Calibration timed out"));
133  msgBox.setStandardButtons(QMessageBox::Ok);
134  msgBox.setDefaultButton(QMessageBox::Ok);
135  msgBox.exec();
136 }
137 
138 void BiasCalibrationPage::stopCalibration()
139 {
140  if (m_calibrationUtil) {
141  disconnect(m_calibrationUtil, &Calibration::levelingProgressChanged, this,
142  &BiasCalibrationPage::calibrationProgress);
143  disconnect(m_calibrationUtil, &Calibration::calibrationCompleted, this,
144  &BiasCalibrationPage::calibrationDone);
145  ui->progressLabel->setText(QString(tr("<font color='green'>Done!</font>")));
146  enableButtons(true);
147  }
148 }
The SetupWizard class is the main interface to the setup wizard. It provides selects the sequence of ...
Definition: setupwizard.h:47
void calibrationCompleted()
Indicate that a calibration process has successfully completed and the results saved to UAVO...
The Calibration class is a UI free algorithm that can be connected to any interfaces. As such it only communicates with the UI via signals and slots, but has no direct handles to any particular controls or widgets.
Definition: calibration.h:46
SetupWizard * getWizard() const
Core plugin system that manages the plugins, their life cycle and their registered objects...
Definition: pluginmanager.h:53
BiasCalibrationPage(SetupWizard *wizard, QWidget *parent=nullptr)
void levelingProgressChanged(int)
Indicate what the progress is for leveling.
void doStartBiasAndLeveling()
Start collecting data while vehicle is level.