34 #include "manualcontrolsettings.h"
35 #include "systemident.h"
41 #include <QStringList>
44 #include <QVBoxLayout>
45 #include <QPushButton>
46 #include <QDesktopServices>
52 , manualControlSettings(nullptr)
54 m_stabilization =
new Ui_StabilizationWidget();
55 m_stabilization->setupUi(
this);
57 m_stabilization->tabWidget->setCurrentIndex(0);
59 updateInProgress =
false;
62 connect(m_stabilization->sbHangtimeDuration,
63 QOverload<double>::of(&QDoubleSpinBox::valueChanged),
this,
64 &ConfigStabilizationWidget::hangtimeDurationChanged);
66 if (manualControlSettings)
68 &ConfigStabilizationWidget::hangtimeDurationChanged);
69 connect(m_stabilization->gbHangtime, &QGroupBox::toggled,
this,
70 &ConfigStabilizationWidget::hangtimeToggle);
74 connect(m_stabilization->checkBox_7, &QCheckBox::stateChanged,
this,
75 &ConfigStabilizationWidget::linkCheckBoxes);
76 connect(m_stabilization->checkBox_2, &QCheckBox::stateChanged,
this,
77 &ConfigStabilizationWidget::linkCheckBoxes);
78 connect(m_stabilization->checkBox_8, &QCheckBox::stateChanged,
this,
79 &ConfigStabilizationWidget::linkCheckBoxes);
80 connect(m_stabilization->checkBox_3, &QCheckBox::stateChanged,
this,
81 &ConfigStabilizationWidget::linkCheckBoxes);
83 connect(m_stabilization->cbLinkRateRollYaw, &QCheckBox::stateChanged,
this,
84 &ConfigStabilizationWidget::ratesLink);
85 connect(m_stabilization->cbLinkRateRollPitch, &QCheckBox::stateChanged,
this,
86 &ConfigStabilizationWidget::ratesLink);
88 connect(m_stabilization->sliderLTRoll, &QAbstractSlider::valueChanged,
89 m_stabilization->rateRollLT, &QSpinBox::setValue);
90 connect(m_stabilization->rateRollLT, QOverload<int>::of(&QSpinBox::valueChanged),
91 m_stabilization->sliderLTRoll, &QSlider::setValue);
92 connect(m_stabilization->sliderLTPitch, &QAbstractSlider::valueChanged,
93 m_stabilization->ratePitchLT, &QSpinBox::setValue);
94 connect(m_stabilization->ratePitchLT, QOverload<int>::of(&QSpinBox::valueChanged),
95 m_stabilization->sliderLTPitch, &QSlider::setValue);
96 connect(m_stabilization->sliderLTYaw, &QAbstractSlider::valueChanged,
97 m_stabilization->rateYawLT, &QSpinBox::setValue);
98 connect(m_stabilization->rateYawLT, QOverload<int>::of(&QSpinBox::valueChanged),
99 m_stabilization->sliderLTYaw, &QSlider::setValue);
101 connect(m_stabilization->fullStickRateRoll,
102 QOverload<double>::of(&QDoubleSpinBox::valueChanged),
this,
103 &ConfigStabilizationWidget::setMaximums);
104 connect(m_stabilization->fullStickRatePitch,
105 QOverload<double>::of(&QDoubleSpinBox::valueChanged),
this,
106 &ConfigStabilizationWidget::setMaximums);
107 connect(m_stabilization->fullStickRateYaw, QOverload<double>::of(&QDoubleSpinBox::valueChanged),
108 this, &ConfigStabilizationWidget::setMaximums);
109 connect(m_stabilization->centerStickRateRoll, QOverload<int>::of(&QSpinBox::valueChanged),
this,
110 &ConfigStabilizationWidget::derivedValuesChanged);
111 connect(m_stabilization->centerStickRatePitch, QOverload<int>::of(&QSpinBox::valueChanged),
112 this, &ConfigStabilizationWidget::derivedValuesChanged);
113 connect(m_stabilization->centerStickRateYaw, QOverload<int>::of(&QSpinBox::valueChanged),
this,
114 &ConfigStabilizationWidget::derivedValuesChanged);
115 connect(m_stabilization->rateRollLT, QOverload<int>::of(&QSpinBox::valueChanged),
this,
116 &ConfigStabilizationWidget::derivedValuesChanged);
117 connect(m_stabilization->ratePitchLT, QOverload<int>::of(&QSpinBox::valueChanged),
this,
118 &ConfigStabilizationWidget::derivedValuesChanged);
119 connect(m_stabilization->rateYawLT, QOverload<int>::of(&QSpinBox::valueChanged),
this,
120 &ConfigStabilizationWidget::derivedValuesChanged);
122 connect(m_stabilization->sliderCRateRoll, &QAbstractSlider::valueChanged,
123 m_stabilization->centerStickRateRoll, &QSpinBox::setValue);
124 connect(m_stabilization->centerStickRateRoll, QOverload<int>::of(&QSpinBox::valueChanged),
125 m_stabilization->sliderCRateRoll, &QSlider::setValue);
126 connect(m_stabilization->sliderCRatePitch, &QAbstractSlider::valueChanged,
127 m_stabilization->centerStickRatePitch, &QSpinBox::setValue);
128 connect(m_stabilization->centerStickRatePitch, QOverload<int>::of(&QSpinBox::valueChanged),
129 m_stabilization->sliderCRatePitch, &QSlider::setValue);
130 connect(m_stabilization->sliderCRateYaw, &QAbstractSlider::valueChanged,
131 m_stabilization->centerStickRateYaw, &QSpinBox::setValue);
132 connect(m_stabilization->centerStickRateYaw, QOverload<int>::of(&QSpinBox::valueChanged),
133 m_stabilization->sliderCRateYaw, &QSlider::setValue);
135 connect(m_stabilization->rateRollExpo, QOverload<double>::of(&QDoubleSpinBox::valueChanged),
136 this, &ConfigStabilizationWidget::sourceValuesChanged);
137 connect(m_stabilization->ratePitchExpo, QOverload<double>::of(&QDoubleSpinBox::valueChanged),
138 this, &ConfigStabilizationWidget::sourceValuesChanged);
139 connect(m_stabilization->rateYawExpo, QOverload<double>::of(&QDoubleSpinBox::valueChanged),
140 this, &ConfigStabilizationWidget::sourceValuesChanged);
142 connect(m_stabilization->rateRollExponent, QOverload<double>::of(&QDoubleSpinBox::valueChanged),
143 this, &ConfigStabilizationWidget::sourceValuesChanged);
144 connect(m_stabilization->ratePitchExponent,
145 QOverload<double>::of(&QDoubleSpinBox::valueChanged),
this,
146 &ConfigStabilizationWidget::sourceValuesChanged);
147 connect(m_stabilization->rateYawExponent, QOverload<double>::of(&QDoubleSpinBox::valueChanged),
148 this, &ConfigStabilizationWidget::sourceValuesChanged);
151 &ConfigStabilizationWidget::processLinkedWidgets);
156 &ConfigStabilizationWidget::applyRateLimits);
159 &ConfigStabilizationWidget::enableDerivedControls);
161 &ConfigStabilizationWidget::disableDerivedControls);
163 disableDerivedControls();
166 void ConfigStabilizationWidget::setDerivedControlsEnabled(
bool enable)
168 m_stabilization->sliderLTRoll->setEnabled(enable);
169 m_stabilization->rateRollLT->setEnabled(enable);
170 m_stabilization->sliderLTPitch->setEnabled(enable);
171 m_stabilization->ratePitchLT->setEnabled(enable);
172 m_stabilization->sliderLTYaw->setEnabled(enable);
173 m_stabilization->rateYawLT->setEnabled(enable);
174 m_stabilization->sliderCRateRoll->setEnabled(enable);
175 m_stabilization->centerStickRateRoll->setEnabled(enable);
176 m_stabilization->sliderCRatePitch->setEnabled(enable);
177 m_stabilization->centerStickRatePitch->setEnabled(enable);
178 m_stabilization->sliderCRateYaw->setEnabled(enable);
179 m_stabilization->centerStickRateYaw->setEnabled(enable);
182 void ConfigStabilizationWidget::enableDerivedControls()
184 setDerivedControlsEnabled(
true);
187 void ConfigStabilizationWidget::disableDerivedControls()
189 setDerivedControlsEnabled(
false);
197 void ConfigStabilizationWidget::ratesLink(
int value)
201 bool hideYaw = m_stabilization->cbLinkRateRollYaw->isChecked();
202 bool hidePitch = m_stabilization->cbLinkRateRollPitch->isChecked();
204 m_stabilization->lblYawRate->setHidden(hideYaw);
205 m_stabilization->sliderFullStickRateYaw->setHidden(hideYaw);
206 m_stabilization->sliderLTYaw->setHidden(hideYaw);
207 m_stabilization->sliderCRateYaw->setHidden(hideYaw);
208 m_stabilization->fullStickRateYaw->setHidden(hideYaw);
209 m_stabilization->rateYawLT->setHidden(hideYaw);
210 m_stabilization->centerStickRateYaw->setHidden(hideYaw);
211 m_stabilization->sliderRateYawExpo->setHidden(hideYaw);
212 m_stabilization->rateYawExpo->setHidden(hideYaw);
213 m_stabilization->sliderExponentYaw->setHidden(hideYaw);
214 m_stabilization->rateYawExponent->setHidden(hideYaw);
216 m_stabilization->lblPitchRate->setHidden(hidePitch);
217 m_stabilization->sliderFullStickRatePitch->setHidden(hidePitch);
218 m_stabilization->sliderLTPitch->setHidden(hidePitch);
219 m_stabilization->sliderCRatePitch->setHidden(hidePitch);
220 m_stabilization->fullStickRatePitch->setHidden(hidePitch);
221 m_stabilization->ratePitchLT->setHidden(hidePitch);
222 m_stabilization->centerStickRatePitch->setHidden(hidePitch);
223 m_stabilization->sliderRatePitchExpo->setHidden(hidePitch);
224 m_stabilization->ratePitchExpo->setHidden(hidePitch);
225 m_stabilization->sliderExponentPitch->setHidden(hidePitch);
226 m_stabilization->ratePitchExponent->setHidden(hidePitch);
228 QString rollLbl = QString(tr(
"Roll"));
231 rollLbl += tr(
" & Pitch");
235 rollLbl += tr(
" & Yaw");
238 m_stabilization->lblRollRate->setText(rollLbl);
240 sourceValuesChanged();
243 void ConfigStabilizationWidget::linkCheckBoxes(
int value)
245 if (sender() == m_stabilization->checkBox_7)
246 m_stabilization->checkBox_3->setCheckState((Qt::CheckState)value);
247 else if (sender() == m_stabilization->checkBox_3)
248 m_stabilization->checkBox_7->setCheckState((Qt::CheckState)value);
249 else if (sender() == m_stabilization->checkBox_8)
250 m_stabilization->checkBox_2->setCheckState((Qt::CheckState)value);
251 else if (sender() == m_stabilization->checkBox_2)
252 m_stabilization->checkBox_8->setCheckState((Qt::CheckState)value);
255 void ConfigStabilizationWidget::setMaximums()
257 m_stabilization->centerStickRateRoll->setMaximum(m_stabilization->fullStickRateRoll->value());
258 m_stabilization->centerStickRatePitch->setMaximum(m_stabilization->fullStickRatePitch->value());
259 m_stabilization->centerStickRateYaw->setMaximum(m_stabilization->fullStickRateYaw->value());
261 m_stabilization->sliderCRateRoll->setMaximum(m_stabilization->fullStickRateRoll->value());
262 m_stabilization->sliderCRatePitch->setMaximum(m_stabilization->fullStickRatePitch->value());
263 m_stabilization->sliderCRateYaw->setMaximum(m_stabilization->fullStickRateYaw->value());
265 derivedValuesChanged();
269 void ConfigStabilizationWidget::sourceValuesChanged()
271 if (updateInProgress) {
275 updateInProgress =
true;
277 bool hideYaw = m_stabilization->cbLinkRateRollYaw->isChecked();
278 bool hidePitch = m_stabilization->cbLinkRateRollPitch->isChecked();
281 m_stabilization->fullStickRateYaw->setValue(m_stabilization->fullStickRateRoll->value());
282 m_stabilization->rateYawExpo->setValue(m_stabilization->rateRollExpo->value());
283 m_stabilization->rateYawExponent->setValue(m_stabilization->rateRollExponent->value());
287 m_stabilization->fullStickRatePitch->setValue(m_stabilization->fullStickRateRoll->value());
288 m_stabilization->ratePitchExpo->setValue(m_stabilization->rateRollExpo->value());
289 m_stabilization->ratePitchExponent->setValue(m_stabilization->rateRollExponent->value());
293 m_stabilization->centerStickRateRoll->setValue(m_stabilization->fullStickRateRoll->value()
294 * (100 - m_stabilization->rateRollExpo->value())
296 m_stabilization->centerStickRatePitch->setValue(
297 m_stabilization->fullStickRatePitch->value()
298 * (100 - m_stabilization->ratePitchExpo->value()) / 100);
299 m_stabilization->centerStickRateYaw->setValue(m_stabilization->fullStickRateYaw->value()
300 * (100 - m_stabilization->rateYawExpo->value())
303 m_stabilization->rateRollLT->setValue(
304 100 * exp(log(0.01) / m_stabilization->rateRollExponent->value()));
305 m_stabilization->ratePitchLT->setValue(
306 100 * exp(log(0.01) / m_stabilization->ratePitchExponent->value()));
307 m_stabilization->rateYawLT->setValue(
308 100 * exp(log(0.01) / m_stabilization->rateYawExponent->value()));
310 updateInProgress =
false;
315 void ConfigStabilizationWidget::derivedValuesChanged()
317 if (updateInProgress) {
321 updateInProgress =
true;
323 bool hideYaw = m_stabilization->cbLinkRateRollYaw->isChecked();
324 bool hidePitch = m_stabilization->cbLinkRateRollPitch->isChecked();
327 m_stabilization->fullStickRateYaw->setValue(m_stabilization->fullStickRateRoll->value());
328 m_stabilization->centerStickRateYaw->setValue(
329 m_stabilization->centerStickRateRoll->value());
330 m_stabilization->rateYawLT->setValue(m_stabilization->rateRollLT->value());
334 m_stabilization->fullStickRatePitch->setValue(m_stabilization->fullStickRateRoll->value());
335 m_stabilization->centerStickRatePitch->setValue(
336 m_stabilization->centerStickRateRoll->value());
337 m_stabilization->ratePitchLT->setValue(m_stabilization->rateRollLT->value());
340 m_stabilization->rateRollExpo->setValue(100
341 - m_stabilization->centerStickRateRoll->value() * 100
342 / m_stabilization->fullStickRateRoll->value());
343 m_stabilization->ratePitchExpo->setValue(100
344 - m_stabilization->centerStickRatePitch->value() * 100
345 / m_stabilization->fullStickRatePitch->value());
346 m_stabilization->rateYawExpo->setValue(100
347 - m_stabilization->centerStickRateYaw->value() * 100
348 / m_stabilization->fullStickRateYaw->value());
350 m_stabilization->rateRollExponent->setValue(
351 log(0.01) / log((m_stabilization->rateRollLT->value() / 100.0f)));
352 m_stabilization->ratePitchExponent->setValue(
353 log(0.01) / log((m_stabilization->ratePitchLT->value() / 100.0f)));
354 m_stabilization->rateYawExponent->setValue(
355 log(0.01) / log((m_stabilization->rateYawLT->value() / 100.0f)));
357 updateInProgress =
false;
362 void ConfigStabilizationWidget::updateGraphs()
364 m_stabilization->expoPlot->plotDataRoll(m_stabilization->rateRollExpo->value(),
365 m_stabilization->fullStickRateRoll->value(),
366 m_stabilization->rateRollExponent->value() * 10.0);
367 m_stabilization->expoPlot->plotDataPitch(m_stabilization->ratePitchExpo->value(),
368 m_stabilization->fullStickRatePitch->value(),
369 m_stabilization->ratePitchExponent->value() * 10.0);
370 m_stabilization->expoPlot->plotDataYaw(m_stabilization->rateYawExpo->value(),
371 m_stabilization->fullStickRateYaw->value(),
372 m_stabilization->rateYawExponent->value() * 10.0);
375 void ConfigStabilizationWidget::processLinkedWidgets(QWidget *widget)
377 if (m_stabilization->checkBox_7->checkState() == Qt::Checked) {
378 if (widget == m_stabilization->RateRollKp) {
379 m_stabilization->RatePitchKp->setValue(m_stabilization->RateRollKp->value());
380 }
else if (widget == m_stabilization->RateRollKi) {
381 m_stabilization->RatePitchKi->setValue(m_stabilization->RateRollKi->value());
382 }
else if (widget == m_stabilization->RateRollILimit) {
383 m_stabilization->RatePitchILimit->setValue(m_stabilization->RateRollILimit->value());
384 }
else if (widget == m_stabilization->RatePitchKp) {
385 m_stabilization->RateRollKp->setValue(m_stabilization->RatePitchKp->value());
386 }
else if (widget == m_stabilization->RatePitchKi) {
387 m_stabilization->RateRollKi->setValue(m_stabilization->RatePitchKi->value());
388 }
else if (widget == m_stabilization->RatePitchILimit) {
389 m_stabilization->RateRollILimit->setValue(m_stabilization->RatePitchILimit->value());
390 }
else if (widget == m_stabilization->RollRateKd) {
391 m_stabilization->PitchRateKd->setValue(m_stabilization->RollRateKd->value());
392 }
else if (widget == m_stabilization->PitchRateKd) {
393 m_stabilization->RollRateKd->setValue(m_stabilization->PitchRateKd->value());
396 if (m_stabilization->checkBox_8->checkState() == Qt::Checked) {
397 if (widget == m_stabilization->AttitudeRollKp) {
398 m_stabilization->AttitudePitchKp->setValue(m_stabilization->AttitudeRollKp->value());
399 }
else if (widget == m_stabilization->AttitudeRollKi) {
400 m_stabilization->AttitudePitchKi->setValue(m_stabilization->AttitudeRollKi->value());
401 }
else if (widget == m_stabilization->AttitudeRollILimit) {
402 m_stabilization->AttitudePitchILimit->setValue(
403 m_stabilization->AttitudeRollILimit->value());
404 }
else if (widget == m_stabilization->AttitudePitchKp) {
405 m_stabilization->AttitudeRollKp->setValue(m_stabilization->AttitudePitchKp->value());
406 }
else if (widget == m_stabilization->AttitudePitchKi) {
407 m_stabilization->AttitudeRollKi->setValue(m_stabilization->AttitudePitchKi->value());
408 }
else if (widget == m_stabilization->AttitudePitchILimit) {
409 m_stabilization->AttitudeRollILimit->setValue(
410 m_stabilization->AttitudePitchILimit->value());
415 void ConfigStabilizationWidget::applyRateLimits()
419 double maxRate = 500;
423 m_stabilization->fullStickRateRoll->setMaximum(maxRate);
424 m_stabilization->fullStickRatePitch->setMaximum(maxRate);
425 m_stabilization->fullStickRateYaw->setMaximum(maxRate);
428 void ConfigStabilizationWidget::hangtimeDurationChanged()
430 bool warn = m_stabilization->sbHangtimeDuration->value() > 0.0;
432 if (warn && !m_stabilization->gbHangtime->isChecked())
433 m_stabilization->gbHangtime->setChecked(
true);
434 else if (!warn && m_stabilization->gbHangtime->isChecked())
435 m_stabilization->gbHangtime->setChecked(
false);
437 if (manualControlSettings) {
440 const QString option = field->
getValue().toString();
441 warn &= !option.startsWith(
"Switch") && option !=
"Always Disarmed";
444 m_stabilization->lblSwitchArmingWarning->setVisible(warn);
447 void ConfigStabilizationWidget::hangtimeToggle(
bool enabled)
450 m_stabilization->sbHangtimeDuration->setValue(0.0);
451 }
else if (m_stabilization->sbHangtimeDuration->value() == 0.0) {
452 m_stabilization->sbHangtimeDuration->setValue(2.5);
461 float hoverThrottle = field->
getValue().toFloat();
462 if (hoverThrottle > 0.01) {
463 float powerAdd = hoverThrottle * 85;
469 m_stabilization->sbHangtimePower->setValue(powerAdd);
QVariant getValue(int index=0) const
void objectUpdated(UAVObject *obj)
Signal sent whenever any field of the object is updated.
virtual int queryMaxGyroRate()
Query the board for the currently set max rate of the gyro.
UAVObjectField * getField(const QString &name)
ConfigStabilizationWidget(QWidget *parent=nullptr)
UAVObject * getObject(const QString &name, quint32 instId=0)
Core::IBoardType * getBoardType()
Get the IBoardType corresponding to the connected board.
~ConfigStabilizationWidget()