29 #include "physical_constants.h"
34 #include <QStringList>
37 #include <QVBoxLayout>
38 #include <QPushButton>
39 #include <QMessageBox>
41 #include <QErrorMessage>
43 #include <QDesktopServices>
46 #include <attitudesettings.h>
47 #include <sensorsettings.h>
48 #include <inssettings.h>
49 #include <homelocation.h>
52 #include <magnetometer.h>
53 #include <baroaltitude.h>
58 #define sign(x) ((x < 0) ? -1 : 1)
61 #define SIX_POINT_CAL_ACCEL
63 const double ConfigAttitudeWidget::maxVarValue = 0.1;
70 static void usleep(
unsigned long usecs) { QThread::usleep(usecs); }
77 , m_ui(new Ui_AttitudeWidget())
82 m_ui->sixPointHelp->setScene(
new QGraphicsScene(
this));
84 paperplane =
new QGraphicsSvgItem();
85 paperplane->setSharedRenderer(
new QSvgRenderer());
86 paperplane->renderer()->load(QString(
":/configgadget/images/paper-plane.svg"));
87 paperplane->setElementId(
"plane-horizontal");
88 m_ui->sixPointHelp->scene()->addItem(paperplane);
89 m_ui->sixPointHelp->setSceneRect(paperplane->boundingRect());
93 this, &ConfigAttitudeWidget::updateCalibrationEnabled);
96 if (Q_LIKELY(uavoMan)) {
97 auto mag = uavoMan->
getObject(QStringLiteral(
"Magnetometer"));
100 this, &ConfigAttitudeWidget::updateCalibrationEnabled);
104 updateCalibrationEnabled();
118 updateCalibrationEnabled();
124 connect(m_ui->yawOrientationStart, &QAbstractButton::clicked, &
calibration,
126 connect(m_ui->levelingStart, &QAbstractButton::clicked, &
calibration,
128 connect(m_ui->levelingAndBiasStart, &QAbstractButton::clicked, &
calibration,
130 connect(m_ui->sixPointStart, &QAbstractButton::clicked, &
calibration,
132 connect(m_ui->sixPointSave, &QAbstractButton::clicked, &
calibration,
134 connect(m_ui->sixPointCancel, &QAbstractButton::clicked, &
calibration,
136 connect(m_ui->cbCalibrateAccels, &QAbstractButton::clicked,
this,
137 &ConfigAttitudeWidget::configureSixPoint);
138 connect(m_ui->cbCalibrateMags, &QAbstractButton::clicked,
this,
139 &ConfigAttitudeWidget::configureSixPoint);
140 connect(m_ui->startTempCal, &QAbstractButton::clicked, &
calibration,
142 connect(m_ui->acceptTempCal, &QAbstractButton::clicked, &
calibration,
144 connect(m_ui->cancelTempCal, &QAbstractButton::clicked, &
calibration,
146 connect(m_ui->tempCalRange, QOverload<int>::of(&QSpinBox::valueChanged), &
calibration,
149 m_ui->acceptTempCal->setEnabled(
false);
151 if (!m_ui->acceptTempCal)
154 m_ui->acceptTempCal->setEnabled(
true);
155 else if (m_ui->acceptTempCal->isEnabled())
156 m_ui->acceptTempCal->setEnabled(
false);
162 &QProgressBar::setValue);
164 &QProgressBar::setValue);
166 &QProgressBar::setValue);
169 &QProgressBar::setValue);
171 &QTextEdit::setText);
176 &QWidget::setEnabled);
179 &QWidget::setDisabled);
181 &QWidget::setEnabled);
184 &QWidget::setEnabled);
191 &ConfigAttitudeWidget::do_SetDirty);
195 &ConfigAttitudeWidget::onCalibrationBusy);
197 m_ui->sixPointStart->setEnabled(
true);
198 m_ui->yawOrientationStart->setEnabled(
true);
199 m_ui->levelingStart->setEnabled(
true);
200 m_ui->levelingAndBiasStart->setEnabled(
true);
202 refreshWidgetsValues();
213 m_ui->sixPointHelp->fitInView(paperplane, Qt::KeepAspectRatio);
219 m_ui->sixPointHelp->fitInView(paperplane, Qt::KeepAspectRatio);
225 void ConfigAttitudeWidget::displayPlane(
int position)
227 QString displayElement;
230 displayElement =
"plane-horizontal";
233 displayElement =
"plane-left";
236 displayElement =
"plane-flip";
239 displayElement =
"plane-right";
242 displayElement =
"plane-up";
245 displayElement =
"plane-down";
251 paperplane->setElementId(displayElement);
252 m_ui->sixPointHelp->setSceneRect(paperplane->boundingRect());
253 m_ui->sixPointHelp->fitInView(paperplane, Qt::KeepAspectRatio);
262 void ConfigAttitudeWidget::refreshWidgetsValues(
UAVObject *)
270 void ConfigAttitudeWidget::do_SetDirty()
275 void ConfigAttitudeWidget::configureSixPoint()
277 if (!m_ui->cbCalibrateAccels->isChecked() && !m_ui->cbCalibrateMags->isChecked()) {
278 QMessageBox::information(
this,
"No sensors chosen",
"At least one of the sensors must be "
279 "chosen. \n\nResetting six-point "
280 "sensor calibration selection.");
282 updateCalibrationEnabled();
285 m_ui->cbCalibrateMags->isChecked());
289 void ConfigAttitudeWidget::onCalibrationBusy(
bool busy)
293 QApplication::setOverrideCursor(Qt::WaitCursor);
295 QApplication::restoreOverrideCursor();
298 void ConfigAttitudeWidget::updateCalibrationEnabled()
300 bool have_mag =
false, have_accel =
false;
311 if (Q_LIKELY(uavoMan)) {
313 uavoMan->getObject(QStringLiteral(
"Magnetometer")));
314 if (mag && mag->getIsPresentOnHardware()) {
317 for (
const auto f : fields) {
318 if (f->getValue() != f->getDefaultValue())
325 m_ui->cbCalibrateAccels->setEnabled(have_accel);
326 m_ui->cbCalibrateMags->setEnabled(have_mag);
328 m_ui->cbCalibrateAccels->setChecked(
false);
330 m_ui->cbCalibrateMags->setChecked(
false);
331 if (!m_ui->cbCalibrateAccels->isChecked() && !m_ui->cbCalibrateMags->isChecked()) {
332 m_ui->cbCalibrateAccels->setChecked(have_accel);
333 m_ui->cbCalibrateMags->setChecked(have_mag);
336 if (have_accel || have_mag) {
void updatePlane(int position)
Change the UAV visualization.
void showEvent(QShowEvent *event)
void doSaveSixPointPosition()
Indicates UAV is in a position to collect data during 6pt calibration.
void calibrationCompleted()
Indicate that a calibration process has successfully completed and the results saved to UAVO...
void doStartSixPoint()
Start the six point calibration routine.
void setTempCalRange(int r)
Set temperature calibration range.
ConfigAttitudeWidget(QWidget *parent=nullptr)
void objectUnpacked(UAVObject *obj)
objectUnpacked: triggered whenever an object is unpacked (i.e. arrives from the telemetry link) ...
void resizeEvent(QResizeEvent *event)
void tempCalProgressChanged(int)
Indicate what the progress is for temperature calibration.
void levelingProgressChanged(int)
Indicate what the progress is for leveling.
void initialize(bool calibrateAccels, bool calibrateMags)
Calibration::initialize Configure whether to calibrate the magnetometer and/or accelerometer during 6...
void doStartOrientation()
Start collecting data while vehicle is in pure pitch.
virtual bool queryCapabilities(BoardCapabilities capability)=0
Query capabilities of the board.
void doStartNoBiasLeveling()
Start collecting data while vehicle is level.
void showTempCalMessage(QString message)
Show an instruction or message from temperature calibration.
UAVObjectManager * getObjectManager()
void sixPointProgressChanged(int)
Indicate what the progress is for six point collection.
void doCancelSixPoint()
Cancels the six point calibration routine.
void showSixPointMessage(QString message)
Show an instruction to the user for six point calibration.
void doCancelTempCalPoint()
Cancels the temperature calibration routine.
QList< UAVObjectField * > getFields()
void yawOrientationProgressChanged(int)
Indicate what the progress is for yaw orientation.
static void usleep(unsigned long usecs)
Gui-less support class for calibration.
void doStartBiasAndLeveling()
Start collecting data while vehicle is level.
void toggleSavePosition(bool enable)
Indicate whether to enable or disable controls.
void calibrationBusy(bool busy)
Indicate whether the calibration is busy.
void doAcceptTempCal()
Accept gyro temp calibration data.
void toggleControls(bool enable)
Indicate whether to enable or disable controls.
UAVObject * getObject(const QString &name, quint32 instId=0)
Core::IBoardType * getBoardType()
Get the IBoardType corresponding to the connected board.
void configureTempCurves(TempCompCurve *x, TempCompCurve *y, TempCompCurve *z)
Set up the curves.
void doStartTempCal()
Start collecting gyro temp calibration data.