QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
APMSensorsComponentController.cc
Go to the documentation of this file.
4#include "MAVLinkLib.h"
5#include "MAVLinkProtocol.h"
6#include "ParameterManager.h"
7#include "AppMessages.h"
9#include "Vehicle.h"
10#include "VehicleLinkManager.h"
11
12#include <QtCore/QVariant>
13
14QGC_LOGGING_CATEGORY(APMSensorsComponentControllerLog, "AutoPilotPlugins.APMSensorsComponentController")
15QGC_LOGGING_CATEGORY(APMSensorsComponentControllerVerboseLog, "AutoPilotPlugins.APMSensorsComponentController:verbose")
16
18 : FactPanelController(parent)
19{
20 APMAutoPilotPlugin *const apmPlugin = qobject_cast<APMAutoPilotPlugin*>(_vehicle->autopilotPlugin());
21
22 // Find the sensors component
23 for (const QVariant &varVehicleComponent : apmPlugin->vehicleComponents()) {
24 _sensorsComponent = qobject_cast<APMSensorsComponent*>(varVehicleComponent.value<VehicleComponent*>());
25 if (_sensorsComponent) {
26 break;
27 }
28 }
29
30 if (_sensorsComponent) {
32 } else {
33 qCWarning(APMSensorsComponentControllerLog) << "Sensors component is missing";
34 }
35
36}
37
39{
40 _restorePreviousCompassCalFitness();
41}
42
43void APMSensorsComponentController::_appendStatusLog(const QString &text)
44{
45 Q_ASSERT(_statusLog);
46
47 const QString varText = text;
48 (void) QMetaObject::invokeMethod(_statusLog, "append", varText);
49}
50
51void APMSensorsComponentController::_startLogCalibration()
52{
53 _hideAllCalAreas();
54
55 (void) connect(_vehicle, &Vehicle::textMessageReceived, this, &APMSensorsComponentController::_handleTextMessage);
56
57 emit setAllCalButtonsEnabled(false);
58 if ((_calTypeInProgress == QGCMAVLink::CalibrationAccel) || (_calTypeInProgress == QGCMAVLink::CalibrationAPMCompassMot)) {
59 _nextButton->setEnabled(true);
60 }
61 _cancelButton->setEnabled(_calTypeInProgress == QGCMAVLink::CalibrationMag);
62
63 (void) connect(MAVLinkProtocol::instance(), &MAVLinkProtocol::messageReceived, this, &APMSensorsComponentController::_mavlinkMessageReceived);
65}
66
67void APMSensorsComponentController::_startVisualCalibration()
68{
69 emit setAllCalButtonsEnabled(false);
70 _cancelButton->setEnabled(true);
71 _nextButton->setEnabled(false);
72
73 _resetInternalState();
74
75 (void) _progressBar->setProperty("value", 0);
76
77 (void) connect(MAVLinkProtocol::instance(), &MAVLinkProtocol::messageReceived, this, &APMSensorsComponentController::_mavlinkMessageReceived);
79}
80
81void APMSensorsComponentController::_resetInternalState()
82{
83 _orientationCalDownSideDone = true;
84 _orientationCalUpsideDownSideDone = true;
85 _orientationCalLeftSideDone = true;
86 _orientationCalRightSideDone = true;
87 _orientationCalTailDownSideDone = true;
88 _orientationCalNoseDownSideDone = true;
89 _orientationCalDownSideInProgress = false;
90 _orientationCalUpsideDownSideInProgress = false;
91 _orientationCalLeftSideInProgress = false;
92 _orientationCalRightSideInProgress = false;
93 _orientationCalNoseDownSideInProgress = false;
94 _orientationCalTailDownSideInProgress = false;
95 _orientationCalDownSideRotate = false;
96 _orientationCalUpsideDownSideRotate = false;
97 _orientationCalLeftSideRotate = false;
98 _orientationCalRightSideRotate = false;
99 _orientationCalNoseDownSideRotate = false;
100 _orientationCalTailDownSideRotate = false;
101
105}
106
107void APMSensorsComponentController::_stopCalibration(APMSensorsComponentController::StopCalibrationCode code)
108{
109 // Clear mag cal sequencing state first so a reentrant CANCEL ack can't trigger a new START
110 _magCalStartAccepted = false;
111 _magCalCancelBeforeStartPending = false;
112
113 (void) disconnect(MAVLinkProtocol::instance(), &MAVLinkProtocol::messageReceived, this, &APMSensorsComponentController::_mavlinkMessageReceived);
115
116 (void) disconnect(_vehicle, &Vehicle::textMessageReceived, this, &APMSensorsComponentController::_handleTextMessage);
117
118 emit setAllCalButtonsEnabled(true);
119 _nextButton->setEnabled(false);
120 _cancelButton->setEnabled(false);
121
122 if (_calTypeInProgress == QGCMAVLink::CalibrationMag) {
123 _restorePreviousCompassCalFitness();
124 if (code == StopCalibrationFailed) {
125 // ArduPilot keeps streaming the failed MAG_CAL_REPORT until cancelled
126 _vehicle->sendMavCommand(_vehicle->defaultComponentId(), MAV_CMD_DO_CANCEL_MAG_CAL, false /* showError */);
127 }
128 }
129
130 if (code == StopCalibrationSuccess) {
131 _resetInternalState();
132 (void) _progressBar->setProperty("value", 1);
133 if (parameterExists(ParameterManager::defaultComponentId, QStringLiteral("COMPASS_LEARN"))) {
134 getParameterFact(ParameterManager::defaultComponentId, QStringLiteral("COMPASS_LEARN"))->setRawValue(0);
135 }
136 } else {
137 (void) _progressBar->setProperty("value", 0);
138 }
139
140 _waitingForCancel = false;
142
143 _refreshParams();
144
145 switch (code) {
146 case StopCalibrationSuccess:
147 (void) _orientationCalAreaHelpText->setProperty("text", tr("Calibration complete"));
148 emit resetStatusTextArea();
149 emit calibrationComplete(_calTypeInProgress);
150 break;
151 case StopCalibrationSuccessShowLog:
152 emit calibrationComplete(_calTypeInProgress);
153 break;
154 case StopCalibrationCancelled:
155 emit resetStatusTextArea();
156 _hideAllCalAreas();
157 break;
158 default:
159 // Assume failed
160 _hideAllCalAreas();
161 QGC::showAppMessage(tr("Calibration failed. Calibration log will be displayed."));
162 break;
163 }
164
165 (void) disconnect(_vehicle, &Vehicle::mavCommandResult, this, &APMSensorsComponentController::_mavCommandResult);
166 _calTypeInProgress = QGCMAVLink::CalibrationNone;
168}
169
170void APMSensorsComponentController::_mavCommandResult(int vehicleId, int component, int command, int result, int failureCode)
171{
172 Q_UNUSED(component); Q_UNUSED(failureCode);
173
174 if (_vehicle->id() != vehicleId) {
175 return;
176 }
177
178 switch (command) {
179 case MAV_CMD_DO_CANCEL_MAG_CAL:
180 if (_magCalCancelBeforeStartPending) {
181 // Pre-start flush of stale cal state is complete (result doesn't matter - older
182 // firmwares reject CANCEL when no cal is running). Safe to start the new cal now.
183 _magCalCancelBeforeStartPending = false;
184 _sendStartMagCal();
185 }
186 break;
187 case MAV_CMD_DO_START_MAG_CAL:
188 if (result == MAV_RESULT_ACCEPTED) {
189 _magCalStartAccepted = true;
190 } else {
191 _appendStatusLog(tr("Failed to start compass calibration"));
192 _stopCalibration(StopCalibrationFailed);
193 }
194 break;
195 case MAV_CMD_FIXED_MAG_CAL_YAW:
196 if (result == MAV_RESULT_ACCEPTED) {
197 _appendStatusLog(tr("Successfully completed"));
198 _stopCalibration(StopCalibrationSuccessShowLog);
199 } else {
200 _appendStatusLog(tr("Failed"));
201 _stopCalibration(StopCalibrationFailed);
202 }
203 break;
204 default:
205 break;
206 }
207}
208
210{
211 _calTypeInProgress = QGCMAVLink::CalibrationMag;
212 _magCalStartAccepted = false;
213 _rgCompassCalProgress[0] = 0;
214 _rgCompassCalProgress[1] = 0;
215 _rgCompassCalProgress[2] = 0;
216 _rgCompassCalComplete[0] = false;
217 _rgCompassCalComplete[1] = false;
218 _rgCompassCalComplete[2] = false;
219
220 _startLogCalibration();
221 uint8_t compassBits = 0;
222 if ((getParameterFact(ParameterManager::defaultComponentId, QStringLiteral("COMPASS_DEV_ID"))->rawValue().toInt() > 0) &&
223 getParameterFact(ParameterManager::defaultComponentId, QStringLiteral("COMPASS_USE"))->rawValue().toBool()) {
224 compassBits |= 1 << 0;
225 qCDebug(APMSensorsComponentControllerLog) << "Performing onboard compass cal for compass 1";
226 } else {
227 _rgCompassCalComplete[0] = true;
228 _rgCompassCalSucceeded[0] = true;
229 _rgCompassCalFitness[0] = 0;
230 }
231 if ((getParameterFact(ParameterManager::defaultComponentId, QStringLiteral("COMPASS_DEV_ID2"))->rawValue().toInt() > 0) &&
232 getParameterFact(ParameterManager::defaultComponentId, QStringLiteral("COMPASS_USE2"))->rawValue().toBool()) {
233 compassBits |= 1 << 1;
234 qCDebug(APMSensorsComponentControllerLog) << "Performing onboard compass cal for compass 2";
235 } else {
236 _rgCompassCalComplete[1] = true;
237 _rgCompassCalSucceeded[1] = true;
238 _rgCompassCalFitness[1] = 0;
239 }
240 if ((getParameterFact(ParameterManager::defaultComponentId, QStringLiteral("COMPASS_DEV_ID3"))->rawValue().toInt() > 0) &&
241 getParameterFact(ParameterManager::defaultComponentId, QStringLiteral("COMPASS_USE3"))->rawValue().toBool()) {
242 compassBits |= 1 << 2;
243 qCDebug(APMSensorsComponentControllerLog) << "Performing onboard compass cal for compass 3";
244 } else {
245 _rgCompassCalComplete[2] = true;
246 _rgCompassCalSucceeded[2] = true;
247 _rgCompassCalFitness[2] = 0;
248 }
249
250 // We bump up the fitness value so calibration will always succeed
251 const Fact *const compassCalFitness = getParameterFact(ParameterManager::defaultComponentId, _compassCalFitnessParam);
252 _restoreCompassCalFitness = true;
253 _previousCompassCalFitness = compassCalFitness->rawValue().toFloat();
254 getParameterFact(ParameterManager::defaultComponentId, _compassCalFitnessParam)->setRawValue(100.0);
255
256 _appendStatusLog(tr("Rotate the vehicle randomly around all axes until the progress bar fills all the way to the right."));
257 (void) connect(_vehicle, &Vehicle::mavCommandResult, this, &APMSensorsComponentController::_mavCommandResult, Qt::UniqueConnection);
258
259 // A previously failed cal keeps streaming MAG_CAL_REPORT until cancelled. Flush that stale
260 // state before starting so it can't instantly complete the new calibration. START is sent
261 // from the CANCEL ack handler (_mavCommandResult) so the two commands can't race.
262 _magCalCompassBits = compassBits;
263 _magCalCancelBeforeStartPending = true;
264 _vehicle->sendMavCommand(_vehicle->defaultComponentId(), MAV_CMD_DO_CANCEL_MAG_CAL, false /* showError */);
265}
266
267void APMSensorsComponentController::_sendStartMagCal()
268{
271 MAV_CMD_DO_START_MAG_CAL,
272 true, // showError
273 _magCalCompassBits, // which compass(es) to calibrate
274 0, // no retry on failure
275 1, // save values after complete
276 0, // no delayed start
277 0 // no auto-reboot
278 );
279}
280
282{
283 _calTypeInProgress = QGCMAVLink::CalibrationMag;
284 _startLogCalibration();
285 (void) connect(_vehicle, &Vehicle::mavCommandResult, this, &APMSensorsComponentController::_mavCommandResult, Qt::UniqueConnection);
286 _vehicle->sendMavCommand(_vehicle->defaultComponentId(), MAV_CMD_FIXED_MAG_CAL_YAW, true /* showError */, 0 /* north*/, mask, lat, lon);
287}
288
290{
291 _calTypeInProgress = QGCMAVLink::CalibrationAccel;
292 if (doSimpleAccelCal) {
293 _startLogCalibration();
294 _calTypeInProgress = QGCMAVLink::CalibrationAPMAccelSimple;
295 _vehicle->startCalibration(_calTypeInProgress);
296 return;
297 }
299 _startVisualCalibration();
300 _cancelButton->setEnabled(false);
301 (void) _orientationCalAreaHelpText->setProperty("text", tr("Hold still in the current orientation and press Next when ready"));
302
303 // Reset all progress indication
304 _orientationCalDownSideDone = false;
305 _orientationCalUpsideDownSideDone = false;
306 _orientationCalLeftSideDone = false;
307 _orientationCalRightSideDone = false;
308 _orientationCalTailDownSideDone = false;
309 _orientationCalNoseDownSideDone = false;
310 _orientationCalDownSideInProgress = false;
311 _orientationCalUpsideDownSideInProgress = false;
312 _orientationCalLeftSideInProgress = false;
313 _orientationCalRightSideInProgress = false;
314 _orientationCalNoseDownSideInProgress = false;
315 _orientationCalTailDownSideInProgress = false;
316
317 // Reset all visibility
318 _orientationCalDownSideVisible = false;
319 _orientationCalUpsideDownSideVisible = false;
320 _orientationCalLeftSideVisible = false;
321 _orientationCalRightSideVisible = false;
322 _orientationCalTailDownSideVisible = false;
323 _orientationCalNoseDownSideVisible = false;
324
325 _calTypeInProgress = QGCMAVLink::CalibrationAccel;
326 _orientationCalDownSideVisible = true;
327 _orientationCalUpsideDownSideVisible = true;
328 _orientationCalLeftSideVisible = true;
329 _orientationCalRightSideVisible = true;
330 _orientationCalTailDownSideVisible = true;
331 _orientationCalNoseDownSideVisible = true;
332
336 _updateAndEmitShowOrientationCalArea(true);
337
338 _vehicle->startCalibration(_calTypeInProgress);
339}
340
342{
343 _calTypeInProgress = QGCMAVLink::CalibrationAPMCompassMot;
345 _startLogCalibration();
346 _appendStatusLog(tr("Raise the throttle slowly to between 50% ~ 75% (the props will spin!) for 5 ~ 10 seconds."));
347 _appendStatusLog(tr("Quickly bring the throttle back down to zero"));
348 _appendStatusLog(tr("Press the Next button to complete the calibration"));
349 _vehicle->startCalibration(_calTypeInProgress);
350}
351
353{
354 _calTypeInProgress = QGCMAVLink::CalibrationLevel;
356 _startLogCalibration();
357 _appendStatusLog(tr("Hold the vehicle in its level flight position."));
358 _vehicle->startCalibration(_calTypeInProgress);
359}
360
362{
365 _startLogCalibration();
366 _appendStatusLog(tr("Requesting pressure calibration..."));
367 _vehicle->startCalibration(_calTypeInProgress);
368}
369
371{
372 _calTypeInProgress = QGCMAVLink::CalibrationGyro;
374 _startLogCalibration();
375 _appendStatusLog(tr("Requesting gyro calibration..."));
376 _vehicle->startCalibration(_calTypeInProgress);
377}
378
379void APMSensorsComponentController::_handleTextMessage(int sysid, int componentid, int severity, const QString &text, const QString &description)
380{
381 Q_UNUSED(componentid); Q_UNUSED(severity); Q_UNUSED(description);
382
383 if (sysid != _vehicle->id()) {
384 return;
385 }
386
387 const QString originalMessageText = text;
388 const QString messageText = text.toLower();
389
390 const QStringList hidePrefixList = { QStringLiteral("prearm:"), QStringLiteral("ekf"), QStringLiteral("arm"), QStringLiteral("initialising") };
391 for (const QString &hidePrefix : hidePrefixList) {
392 if (messageText.startsWith(hidePrefix)) {
393 return;
394 }
395 }
396
397 _appendStatusLog(originalMessageText);
398 qCDebug(APMSensorsComponentControllerLog) << originalMessageText << severity;
399}
400
401void APMSensorsComponentController::_refreshParams()
402{
404 QStringLiteral("COMPASS_OFS_X"), QStringLiteral("COMPASS_OFS_Y"), QStringLiteral("COMPASS_OFS_Z"),
405 QStringLiteral("INS_ACCOFFS_X"), QStringLiteral("INS_ACCOFFS_Y"), QStringLiteral("INS_ACCOFFS_Z"),
406 QStringLiteral("COMPASS_*"),
407 QStringLiteral("INS_*"),
408 }, false /* notifyFailure */);
409}
410
411void APMSensorsComponentController::_updateAndEmitShowOrientationCalArea(bool show)
412{
413 _showOrientationCalArea = show;
415}
416
417void APMSensorsComponentController::_hideAllCalAreas()
418{
419 _updateAndEmitShowOrientationCalArea(false);
420}
421
423{
424 _cancelButton->setEnabled(false);
425
426 if (_calTypeInProgress == QGCMAVLink::CalibrationMag) {
427 // Clear pending start first so a reentrant CANCEL ack can't trigger a new START
428 _magCalCancelBeforeStartPending = false;
429 _vehicle->sendMavCommand(_vehicle->defaultComponentId(), MAV_CMD_DO_CANCEL_MAG_CAL, true /* showError */);
430 _stopCalibration(StopCalibrationCancelled);
431 } else {
432 _waitingForCancel = true;
434 // The firmware doesn't always allow us to cancel calibration. The best we can do is wait
435 // for it to timeout.
436 _vehicle->stopCalibration(true /* showError */);
437 }
438}
439
441{
443 if (sharedLink) {
444 mavlink_message_t msg{};
445
446 (void) mavlink_msg_command_ack_pack_chan(
449 sharedLink->mavlinkChannel(),
450 &msg,
451 0, // command
452 1, // result
453 0, // progress
454 0, // result_param2
455 0, // target_system
456 0 // target_component
457 );
458
459 (void) _vehicle->sendMessageOnLinkThreadSafe(sharedLink.get(), msg);
460
461 if (_calTypeInProgress == QGCMAVLink::CalibrationAPMCompassMot) {
462 _stopCalibration(StopCalibrationSuccess);
463 }
464 }
465}
466
468{
469 return _sensorsComponent->compassSetupNeeded();
470}
471
473{
474 return _sensorsComponent->accelSetupNeeded();
475}
476
478{
479 const SharedLinkInterfacePtr sharedLink = _vehicle->vehicleLinkManager()->primaryLink().lock();
480 if (!sharedLink) {
481 return false;
482 }
483
484 return (sharedLink->linkConfiguration()->type() == LinkConfiguration::TypeUdp);
485}
486
487void APMSensorsComponentController::_handleCommandAck(const mavlink_message_t &message)
488{
489 if ((_calTypeInProgress == QGCMAVLink::CalibrationLevel) || (_calTypeInProgress == QGCMAVLink::CalibrationGyro) || (_calTypeInProgress == QGCMAVLink::CalibrationAPMPressureAirspeed) || (_calTypeInProgress == QGCMAVLink::CalibrationAPMAccelSimple)) {
490 mavlink_command_ack_t commandAck{};
491 mavlink_msg_command_ack_decode(&message, &commandAck);
492
493 if (commandAck.command == MAV_CMD_PREFLIGHT_CALIBRATION) {
494 switch (commandAck.result) {
495 case MAV_RESULT_IN_PROGRESS:
496 _appendStatusLog(tr("In progress"));
497 break;
498 case MAV_RESULT_ACCEPTED:
499 _appendStatusLog(tr("Successfully completed"));
500 _stopCalibration(StopCalibrationSuccessShowLog);
501 break;
502 default:
503 _appendStatusLog(tr("Failed"));
504 _stopCalibration(StopCalibrationFailed);
505 break;
506 }
507 }
508 }
509}
510
511void APMSensorsComponentController::_handleMagCalProgress(const mavlink_message_t &message)
512{
513 if ((_calTypeInProgress != QGCMAVLink::CalibrationMag) || !_magCalStartAccepted) {
514 return;
515 }
516
517 mavlink_mag_cal_progress_t magCalProgress{};
518 mavlink_msg_mag_cal_progress_decode(&message, &magCalProgress);
519
520 qCDebug(APMSensorsComponentControllerVerboseLog) << "id:mask:pct"
521 << magCalProgress.compass_id
522 << magCalProgress.cal_mask
523 << magCalProgress.completion_pct;
524
525 // How many compasses are we calibrating?
526 int compassCalCount = 0;
527 for (int i = 0; i < 3; i++) {
528 if (magCalProgress.cal_mask & (1 << i)) {
529 compassCalCount++;
530 }
531 }
532
533 if ((magCalProgress.compass_id < 3) && (compassCalCount != 0)) {
534 // Each compass gets a portion of the overall progress
535 _rgCompassCalProgress[magCalProgress.compass_id] = magCalProgress.completion_pct / compassCalCount;
536 }
537
538 if (_progressBar) {
539 (void) _progressBar->setProperty("value", static_cast<float>(_rgCompassCalProgress[0] + _rgCompassCalProgress[1] + _rgCompassCalProgress[2]) / 100.0);
540 }
541}
542
543void APMSensorsComponentController::_handleMagCalReport(const mavlink_message_t &message)
544{
545 if ((_calTypeInProgress != QGCMAVLink::CalibrationMag) || !_magCalStartAccepted) {
546 return;
547 }
548
549 mavlink_mag_cal_report_t magCalReport{};
550 mavlink_msg_mag_cal_report_decode(&message, &magCalReport);
551
552 qCDebug(APMSensorsComponentControllerVerboseLog) << "id:mask:status:fitness"
553 << magCalReport.compass_id << magCalReport.cal_mask << magCalReport.cal_status << magCalReport.fitness;
554
555 bool additionalCompassCompleted = false;
556 if ((magCalReport.compass_id < 3) && !_rgCompassCalComplete[magCalReport.compass_id]) {
557 if (magCalReport.cal_status == MAG_CAL_SUCCESS) {
558 _appendStatusLog(tr("Compass %1 calibration complete").arg(magCalReport.compass_id));
559 } else {
560 _appendStatusLog(tr("Compass %1 calibration below quality threshold").arg(magCalReport.compass_id));
561 }
562 _rgCompassCalComplete[magCalReport.compass_id] = true;
563 _rgCompassCalSucceeded[magCalReport.compass_id] = (magCalReport.cal_status == MAG_CAL_SUCCESS);
564 _rgCompassCalFitness[magCalReport.compass_id] = magCalReport.fitness;
565 additionalCompassCompleted = true;
566 }
567
568 if (_rgCompassCalComplete[0] && _rgCompassCalComplete[1] &&_rgCompassCalComplete[2]) {
569 for (int i = 0; i < 3; i++) {
570 qCDebug(APMSensorsComponentControllerLog) << QString("Onboard compass call report #%1: succeed:fitness %2:%3").arg(i).arg(_rgCompassCalSucceeded[i]).arg(_rgCompassCalFitness[i]);
571 }
572 emit compass1CalFitnessChanged(_rgCompassCalFitness[0]);
573 emit compass2CalFitnessChanged(_rgCompassCalFitness[1]);
574 emit compass3CalFitnessChanged(_rgCompassCalFitness[2]);
575 emit compass1CalSucceededChanged(_rgCompassCalSucceeded[0]);
576 emit compass2CalSucceededChanged(_rgCompassCalSucceeded[1]);
577 emit compass3CalSucceededChanged(_rgCompassCalSucceeded[2]);
578 if (_rgCompassCalSucceeded[0] && _rgCompassCalSucceeded[1] && _rgCompassCalSucceeded[2]) {
579 _appendStatusLog(tr("All compasses calibrated successfully"));
580 _appendStatusLog(tr("YOU MUST REBOOT YOUR VEHICLE NOW FOR NEW SETTINGS TO TAKE AFFECT"));
581 _stopCalibration(StopCalibrationSuccessShowLog);
582 } else {
583 _appendStatusLog(tr("Compass calibration failed"));
584 _appendStatusLog(tr("YOU MUST REBOOT YOUR VEHICLE NOW AND RETRY COMPASS CALIBRATION PRIOR TO FLIGHT"));
585 _stopCalibration(StopCalibrationFailed);
586 }
587 } else if (additionalCompassCompleted) {
588 _appendStatusLog(tr("Continue rotating..."));
589 }
590}
591
592bool APMSensorsComponentController::_handleCmdLongAccelcalVehiclePos(const mavlink_command_long_t &commandLong)
593{
594 bool updateImages = false;
595
596 switch (static_cast<ACCELCAL_VEHICLE_POS>(static_cast<int>(commandLong.param1))) {
597 case ACCELCAL_VEHICLE_POS_LEVEL:
598 if (!_orientationCalDownSideInProgress) {
599 updateImages = true;
600 _orientationCalDownSideInProgress = true;
601 _nextButton->setEnabled(true);
602 }
603 break;
604 case ACCELCAL_VEHICLE_POS_LEFT:
605 if (!_orientationCalLeftSideInProgress) {
606 updateImages = true;
607 _orientationCalDownSideDone = true;
608 _orientationCalDownSideInProgress = false;
609 _orientationCalLeftSideInProgress = true;
610 (void) _progressBar->setProperty("value", static_cast<qreal>(17 / 100.0));
611 }
612 break;
613 case ACCELCAL_VEHICLE_POS_RIGHT:
614 if (!_orientationCalRightSideInProgress) {
615 updateImages = true;
616 _orientationCalLeftSideDone = true;
617 _orientationCalLeftSideInProgress = false;
618 _orientationCalRightSideInProgress = true;
619 (void) _progressBar->setProperty("value", static_cast<qreal>(34 / 100.0));
620 }
621 break;
622 case ACCELCAL_VEHICLE_POS_NOSEDOWN:
623 if (!_orientationCalNoseDownSideInProgress) {
624 updateImages = true;
625 _orientationCalRightSideDone = true;
626 _orientationCalRightSideInProgress = false;
627 _orientationCalNoseDownSideInProgress = true;
628 (void) _progressBar->setProperty("value", static_cast<qreal>(51 / 100.0));
629 }
630 break;
631 case ACCELCAL_VEHICLE_POS_NOSEUP:
632 if (!_orientationCalTailDownSideInProgress) {
633 updateImages = true;
634 _orientationCalNoseDownSideDone = true;
635 _orientationCalNoseDownSideInProgress = false;
636 _orientationCalTailDownSideInProgress = true;
637 (void) _progressBar->setProperty("value", static_cast<qreal>(68 / 100.0));
638 }
639 break;
640 case ACCELCAL_VEHICLE_POS_BACK:
641 if (!_orientationCalUpsideDownSideInProgress) {
642 updateImages = true;
643 _orientationCalTailDownSideDone = true;
644 _orientationCalTailDownSideInProgress = false;
645 _orientationCalUpsideDownSideInProgress = true;
646 (void) _progressBar->setProperty("value", static_cast<qreal>(85 / 100.0));
647 }
648 break;
649 case ACCELCAL_VEHICLE_POS_SUCCESS:
650 _stopCalibration(StopCalibrationSuccess);
651 break;
652 case ACCELCAL_VEHICLE_POS_FAILED:
653 _stopCalibration(StopCalibrationFailed);
654 break;
655 case ACCELCAL_VEHICLE_POS_ENUM_END:
656 default:
657 break;
658 }
659
660 return updateImages;
661}
662
663void APMSensorsComponentController::_handleCommandLong(const mavlink_message_t &message)
664{
665 bool updateImages = false;
666 mavlink_command_long_t commandLong{};
667
668 mavlink_msg_command_long_decode(&message, &commandLong);
669
670 if (commandLong.command == MAV_CMD_ACCELCAL_VEHICLE_POS) {
671 updateImages = _handleCmdLongAccelcalVehiclePos(commandLong);
672 }
673
674 if (updateImages) {
678 }
679}
680
681void APMSensorsComponentController::_mavlinkMessageReceived(LinkInterface *link, const mavlink_message_t &message)
682{
683 Q_UNUSED(link);
684
685 if (message.sysid != _vehicle->id()) {
686 return;
687 }
688
689 switch (message.msgid) {
690 case MAVLINK_MSG_ID_COMMAND_ACK:
691 _handleCommandAck(message);
692 break;
693 case MAVLINK_MSG_ID_MAG_CAL_PROGRESS:
694 _handleMagCalProgress(message);
695 break;
696 case MAVLINK_MSG_ID_MAG_CAL_REPORT:
697 _handleMagCalReport(message);
698 break;
699 case MAVLINK_MSG_ID_COMMAND_LONG:
700 _handleCommandLong(message);
701 break;
702 }
703}
704
705void APMSensorsComponentController::_restorePreviousCompassCalFitness()
706{
707 if (_restoreCompassCalFitness) {
708 _restoreCompassCalFitness = false;
709 getParameterFact(ParameterManager::defaultComponentId, _compassCalFitnessParam)->setRawValue(_previousCompassCalFitness);
710 }
711}
std::shared_ptr< LinkInterface > SharedLinkInterfacePtr
struct __mavlink_message mavlink_message_t
#define QGC_LOGGING_CATEGORY(name, categoryStr)
struct __mavlink_command_ack_t mavlink_command_ack_t
struct __mavlink_command_long_t mavlink_command_long_t
This is the AutoPilotPlugin implementation for the MAV_AUTOPILOT_ARDUPILOT type.
const QVariantList & vehicleComponents() override
Sensors Component MVC Controller for SensorsComponent.qml.
Q_INVOKABLE void calibrateCompassNorth(float lat, float lon, int mask)
void compass3CalFitnessChanged(double compass3CalFitness)
void compass1CalFitnessChanged(double compass1CalFitness)
void compass2CalFitnessChanged(double compass2CalFitness)
Q_INVOKABLE void calibrateAccel(bool doSimpleAccelCal)
void compass2CalSucceededChanged(bool compass2CalSucceeded)
void setAllCalButtonsEnabled(bool enabled)
void compass3CalSucceededChanged(bool compass3CalSucceeded)
void compass1CalSucceededChanged(bool compass1CalSucceeded)
void calibrationComplete(QGCMAVLink::CalibrationType calType)
Used for handling missing Facts from C++ code.
Q_INVOKABLE Fact * getParameterFact(int componentId, const QString &name, bool reportMissing=true) const
Q_INVOKABLE bool parameterExists(int componentId, const QString &name) const
A Fact is used to hold a single value within the system.
Definition Fact.h:17
void setRawValue(const QVariant &value)
Definition Fact.cc:134
QVariant rawValue() const
Definition Fact.h:90
The link interface defines the interface for all links used to communicate with the ground station ap...
static int getComponentId()
void messageReceived(LinkInterface *link, const mavlink_message_t &message)
static MAVLinkProtocol * instance()
int getSystemId() const
void bulkRefresh(int componentId, const QStringList &names, bool notifyFailure=true)
static constexpr int defaultComponentId
A vehicle component is an object which abstracts the physical portion of a vehicle into a set of conf...
void setupCompleteChanged()
WeakLinkInterfacePtr primaryLink() const
void setCommunicationLostEnabled(bool communicationLostEnabled)
void sendMavCommand(int compId, MAV_CMD command, bool showError, float param1=0.0f, float param2=0.0f, float param3=0.0f, float param4=0.0f, float param5=0.0f, float param6=0.0f, float param7=0.0f)
Definition Vehicle.cc:2140
void textMessageReceived(int sysid, int componentid, int severity, QString text, QString description)
VehicleLinkManager * vehicleLinkManager()
Definition Vehicle.h:579
int id() const
Definition Vehicle.h:429
bool sendMessageOnLinkThreadSafe(LinkInterface *link, mavlink_message_t message)
Definition Vehicle.cc:1386
int defaultComponentId() const
Definition Vehicle.h:682
ParameterManager * parameterManager()
Definition Vehicle.h:577
void startCalibration(QGCMAVLink::CalibrationType calType)
Definition Vehicle.cc:2322
void stopCalibration(bool showError)
Definition Vehicle.cc:2402
void mavCommandResult(int vehicleId, int targetComponent, int command, int ackResult, int failureCode)
void showAppMessage(const QString &message, const QString &title)
Modal application message. Queued if the UI isn't ready yet.
Definition AppMessages.cc:9