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