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 (void) disconnect(MAVLinkProtocol::instance(), &MAVLinkProtocol::messageReceived, this, &APMSensorsComponentController::_mavlinkMessageReceived);
111
112 (void) disconnect(_vehicle, &Vehicle::textMessageReceived, this, &APMSensorsComponentController::_handleTextMessage);
113
114 emit setAllCalButtonsEnabled(true);
115 _nextButton->setEnabled(false);
116 _cancelButton->setEnabled(false);
117
118 if (_calTypeInProgress == QGCMAVLink::CalibrationMag) {
119 _restorePreviousCompassCalFitness();
120 }
121
122 if (code == StopCalibrationSuccess) {
123 _resetInternalState();
124 (void) _progressBar->setProperty("value", 1);
125 if (parameterExists(ParameterManager::defaultComponentId, QStringLiteral("COMPASS_LEARN"))) {
126 getParameterFact(ParameterManager::defaultComponentId, QStringLiteral("COMPASS_LEARN"))->setRawValue(0);
127 }
128 } else {
129 (void) _progressBar->setProperty("value", 0);
130 }
131
132 _waitingForCancel = false;
134
135 _refreshParams();
136
137 switch (code) {
138 case StopCalibrationSuccess:
139 (void) _orientationCalAreaHelpText->setProperty("text", tr("Calibration complete"));
140 emit resetStatusTextArea();
141 emit calibrationComplete(_calTypeInProgress);
142 break;
143 case StopCalibrationSuccessShowLog:
144 emit calibrationComplete(_calTypeInProgress);
145 break;
146 case StopCalibrationCancelled:
147 emit resetStatusTextArea();
148 _hideAllCalAreas();
149 break;
150 default:
151 // Assume failed
152 _hideAllCalAreas();
153 QGC::showAppMessage(tr("Calibration failed. Calibration log will be displayed."));
154 break;
155 }
156
157 (void) disconnect(_vehicle, &Vehicle::mavCommandResult, this, &APMSensorsComponentController::_mavCommandResult);
158 _calTypeInProgress = QGCMAVLink::CalibrationNone;
160}
161
162void APMSensorsComponentController::_mavCommandResult(int vehicleId, int component, int command, int result, int failureCode)
163{
164 Q_UNUSED(component); Q_UNUSED(failureCode);
165
166 if (_vehicle->id() != vehicleId) {
167 return;
168 }
169
170 switch (command) {
171 case MAV_CMD_DO_START_MAG_CAL:
172 if (result != MAV_RESULT_ACCEPTED) {
173 _appendStatusLog(tr("Failed to start compass calibration"));
174 _stopCalibration(StopCalibrationFailed);
175 }
176 break;
177 case MAV_CMD_FIXED_MAG_CAL_YAW:
178 if (result == MAV_RESULT_ACCEPTED) {
179 _appendStatusLog(tr("Successfully completed"));
180 _stopCalibration(StopCalibrationSuccessShowLog);
181 } else {
182 _appendStatusLog(tr("Failed"));
183 _stopCalibration(StopCalibrationFailed);
184 }
185 break;
186 default:
187 break;
188 }
189}
190
192{
193 _calTypeInProgress = QGCMAVLink::CalibrationMag;
194 _rgCompassCalProgress[0] = 0;
195 _rgCompassCalProgress[1] = 0;
196 _rgCompassCalProgress[2] = 0;
197 _rgCompassCalComplete[0] = false;
198 _rgCompassCalComplete[1] = false;
199 _rgCompassCalComplete[2] = false;
200
201 _startLogCalibration();
202 uint8_t compassBits = 0;
203 if ((getParameterFact(ParameterManager::defaultComponentId, QStringLiteral("COMPASS_DEV_ID"))->rawValue().toInt() > 0) &&
204 getParameterFact(ParameterManager::defaultComponentId, QStringLiteral("COMPASS_USE"))->rawValue().toBool()) {
205 compassBits |= 1 << 0;
206 qCDebug(APMSensorsComponentControllerLog) << "Performing onboard compass cal for compass 1";
207 } else {
208 _rgCompassCalComplete[0] = true;
209 _rgCompassCalSucceeded[0] = true;
210 _rgCompassCalFitness[0] = 0;
211 }
212 if ((getParameterFact(ParameterManager::defaultComponentId, QStringLiteral("COMPASS_DEV_ID2"))->rawValue().toInt() > 0) &&
213 getParameterFact(ParameterManager::defaultComponentId, QStringLiteral("COMPASS_USE2"))->rawValue().toBool()) {
214 compassBits |= 1 << 1;
215 qCDebug(APMSensorsComponentControllerLog) << "Performing onboard compass cal for compass 2";
216 } else {
217 _rgCompassCalComplete[1] = true;
218 _rgCompassCalSucceeded[1] = true;
219 _rgCompassCalFitness[1] = 0;
220 }
221 if ((getParameterFact(ParameterManager::defaultComponentId, QStringLiteral("COMPASS_DEV_ID3"))->rawValue().toInt() > 0) &&
222 getParameterFact(ParameterManager::defaultComponentId, QStringLiteral("COMPASS_USE3"))->rawValue().toBool()) {
223 compassBits |= 1 << 2;
224 qCDebug(APMSensorsComponentControllerLog) << "Performing onboard compass cal for compass 3";
225 } else {
226 _rgCompassCalComplete[2] = true;
227 _rgCompassCalSucceeded[2] = true;
228 _rgCompassCalFitness[2] = 0;
229 }
230
231 // We bump up the fitness value so calibration will always succeed
232 const Fact *const compassCalFitness = getParameterFact(ParameterManager::defaultComponentId, _compassCalFitnessParam);
233 _restoreCompassCalFitness = true;
234 _previousCompassCalFitness = compassCalFitness->rawValue().toFloat();
235 getParameterFact(ParameterManager::defaultComponentId, _compassCalFitnessParam)->setRawValue(100.0);
236
237 _appendStatusLog(tr("Rotate the vehicle randomly around all axes until the progress bar fills all the way to the right."));
238 (void) connect(_vehicle, &Vehicle::mavCommandResult, this, &APMSensorsComponentController::_mavCommandResult, Qt::UniqueConnection);
241 MAV_CMD_DO_START_MAG_CAL,
242 true, // showError
243 compassBits, // which compass(es) to calibrate
244 0, // no retry on failure
245 1, // save values after complete
246 0, // no delayed start
247 0 // no auto-reboot
248 );
249}
250
252{
253 _calTypeInProgress = QGCMAVLink::CalibrationMag;
254 _startLogCalibration();
255 (void) connect(_vehicle, &Vehicle::mavCommandResult, this, &APMSensorsComponentController::_mavCommandResult, Qt::UniqueConnection);
256 _vehicle->sendMavCommand(_vehicle->defaultComponentId(), MAV_CMD_FIXED_MAG_CAL_YAW, true /* showError */, 0 /* north*/, mask, lat, lon);
257}
258
260{
261 _calTypeInProgress = QGCMAVLink::CalibrationAccel;
262 if (doSimpleAccelCal) {
263 _startLogCalibration();
264 _calTypeInProgress = QGCMAVLink::CalibrationAPMAccelSimple;
265 _vehicle->startCalibration(_calTypeInProgress);
266 return;
267 }
269 _startVisualCalibration();
270 _cancelButton->setEnabled(false);
271 (void) _orientationCalAreaHelpText->setProperty("text", tr("Hold still in the current orientation and press Next when ready"));
272
273 // Reset all progress indication
274 _orientationCalDownSideDone = false;
275 _orientationCalUpsideDownSideDone = false;
276 _orientationCalLeftSideDone = false;
277 _orientationCalRightSideDone = false;
278 _orientationCalTailDownSideDone = false;
279 _orientationCalNoseDownSideDone = false;
280 _orientationCalDownSideInProgress = false;
281 _orientationCalUpsideDownSideInProgress = false;
282 _orientationCalLeftSideInProgress = false;
283 _orientationCalRightSideInProgress = false;
284 _orientationCalNoseDownSideInProgress = false;
285 _orientationCalTailDownSideInProgress = false;
286
287 // Reset all visibility
288 _orientationCalDownSideVisible = false;
289 _orientationCalUpsideDownSideVisible = false;
290 _orientationCalLeftSideVisible = false;
291 _orientationCalRightSideVisible = false;
292 _orientationCalTailDownSideVisible = false;
293 _orientationCalNoseDownSideVisible = false;
294
295 _calTypeInProgress = QGCMAVLink::CalibrationAccel;
296 _orientationCalDownSideVisible = true;
297 _orientationCalUpsideDownSideVisible = true;
298 _orientationCalLeftSideVisible = true;
299 _orientationCalRightSideVisible = true;
300 _orientationCalTailDownSideVisible = true;
301 _orientationCalNoseDownSideVisible = true;
302
306 _updateAndEmitShowOrientationCalArea(true);
307
308 _vehicle->startCalibration(_calTypeInProgress);
309}
310
312{
313 _calTypeInProgress = QGCMAVLink::CalibrationAPMCompassMot;
315 _startLogCalibration();
316 _appendStatusLog(tr("Raise the throttle slowly to between 50% ~ 75% (the props will spin!) for 5 ~ 10 seconds."));
317 _appendStatusLog(tr("Quickly bring the throttle back down to zero"));
318 _appendStatusLog(tr("Press the Next button to complete the calibration"));
319 _vehicle->startCalibration(_calTypeInProgress);
320}
321
323{
324 _calTypeInProgress = QGCMAVLink::CalibrationLevel;
326 _startLogCalibration();
327 _appendStatusLog(tr("Hold the vehicle in its level flight position."));
328 _vehicle->startCalibration(_calTypeInProgress);
329}
330
332{
335 _startLogCalibration();
336 _appendStatusLog(tr("Requesting pressure calibration..."));
337 _vehicle->startCalibration(_calTypeInProgress);
338}
339
341{
342 _calTypeInProgress = QGCMAVLink::CalibrationGyro;
344 _startLogCalibration();
345 _appendStatusLog(tr("Requesting gyro calibration..."));
346 _vehicle->startCalibration(_calTypeInProgress);
347}
348
349void APMSensorsComponentController::_handleTextMessage(int sysid, int componentid, int severity, const QString &text, const QString &description)
350{
351 Q_UNUSED(componentid); Q_UNUSED(severity); Q_UNUSED(description);
352
353 if (sysid != _vehicle->id()) {
354 return;
355 }
356
357 const QString originalMessageText = text;
358 const QString messageText = text.toLower();
359
360 const QStringList hidePrefixList = { QStringLiteral("prearm:"), QStringLiteral("ekf"), QStringLiteral("arm"), QStringLiteral("initialising") };
361 for (const QString &hidePrefix : hidePrefixList) {
362 if (messageText.startsWith(hidePrefix)) {
363 return;
364 }
365 }
366
367 _appendStatusLog(originalMessageText);
368 qCDebug(APMSensorsComponentControllerLog) << originalMessageText << severity;
369}
370
371void APMSensorsComponentController::_refreshParams()
372{
374 QStringLiteral("COMPASS_OFS_X"), QStringLiteral("COMPASS_OFS_Y"), QStringLiteral("COMPASS_OFS_Z"),
375 QStringLiteral("INS_ACCOFFS_X"), QStringLiteral("INS_ACCOFFS_Y"), QStringLiteral("INS_ACCOFFS_Z"),
376 QStringLiteral("COMPASS_*"),
377 QStringLiteral("INS_*"),
378 }, false /* notifyFailure */);
379}
380
381void APMSensorsComponentController::_updateAndEmitShowOrientationCalArea(bool show)
382{
383 _showOrientationCalArea = show;
385}
386
387void APMSensorsComponentController::_hideAllCalAreas()
388{
389 _updateAndEmitShowOrientationCalArea(false);
390}
391
393{
394 _cancelButton->setEnabled(false);
395
396 if (_calTypeInProgress == QGCMAVLink::CalibrationMag) {
397 _vehicle->sendMavCommand(_vehicle->defaultComponentId(), MAV_CMD_DO_CANCEL_MAG_CAL, true /* showError */);
398 _stopCalibration(StopCalibrationCancelled);
399 } else {
400 _waitingForCancel = true;
402 // The firmware doesn't always allow us to cancel calibration. The best we can do is wait
403 // for it to timeout.
404 _vehicle->stopCalibration(true /* showError */);
405 }
406}
407
409{
411 if (sharedLink) {
412 mavlink_message_t msg{};
413
414 (void) mavlink_msg_command_ack_pack_chan(
417 sharedLink->mavlinkChannel(),
418 &msg,
419 0, // command
420 1, // result
421 0, // progress
422 0, // result_param2
423 0, // target_system
424 0 // target_component
425 );
426
427 (void) _vehicle->sendMessageOnLinkThreadSafe(sharedLink.get(), msg);
428
429 if (_calTypeInProgress == QGCMAVLink::CalibrationAPMCompassMot) {
430 _stopCalibration(StopCalibrationSuccess);
431 }
432 }
433}
434
436{
437 return _sensorsComponent->compassSetupNeeded();
438}
439
441{
442 return _sensorsComponent->accelSetupNeeded();
443}
444
446{
447 const SharedLinkInterfacePtr sharedLink = _vehicle->vehicleLinkManager()->primaryLink().lock();
448 if (!sharedLink) {
449 return false;
450 }
451
452 return (sharedLink->linkConfiguration()->type() == LinkConfiguration::TypeUdp);
453}
454
455void APMSensorsComponentController::_handleCommandAck(const mavlink_message_t &message)
456{
457 if ((_calTypeInProgress == QGCMAVLink::CalibrationLevel) || (_calTypeInProgress == QGCMAVLink::CalibrationGyro) || (_calTypeInProgress == QGCMAVLink::CalibrationAPMPressureAirspeed) || (_calTypeInProgress == QGCMAVLink::CalibrationAPMAccelSimple)) {
458 mavlink_command_ack_t commandAck{};
459 mavlink_msg_command_ack_decode(&message, &commandAck);
460
461 if (commandAck.command == MAV_CMD_PREFLIGHT_CALIBRATION) {
462 switch (commandAck.result) {
463 case MAV_RESULT_IN_PROGRESS:
464 _appendStatusLog(tr("In progress"));
465 break;
466 case MAV_RESULT_ACCEPTED:
467 _appendStatusLog(tr("Successfully completed"));
468 _stopCalibration(StopCalibrationSuccessShowLog);
469 break;
470 default:
471 _appendStatusLog(tr("Failed"));
472 _stopCalibration(StopCalibrationFailed);
473 break;
474 }
475 }
476 }
477}
478
479void APMSensorsComponentController::_handleMagCalProgress(const mavlink_message_t &message)
480{
481 if (_calTypeInProgress != QGCMAVLink::CalibrationMag) {
482 return;
483 }
484
485 mavlink_mag_cal_progress_t magCalProgress{};
486 mavlink_msg_mag_cal_progress_decode(&message, &magCalProgress);
487
488 qCDebug(APMSensorsComponentControllerVerboseLog) << "id:mask:pct"
489 << magCalProgress.compass_id
490 << magCalProgress.cal_mask
491 << magCalProgress.completion_pct;
492
493 // How many compasses are we calibrating?
494 int compassCalCount = 0;
495 for (int i = 0; i < 3; i++) {
496 if (magCalProgress.cal_mask & (1 << i)) {
497 compassCalCount++;
498 }
499 }
500
501 if ((magCalProgress.compass_id < 3) && (compassCalCount != 0)) {
502 // Each compass gets a portion of the overall progress
503 _rgCompassCalProgress[magCalProgress.compass_id] = magCalProgress.completion_pct / compassCalCount;
504 }
505
506 if (_progressBar) {
507 (void) _progressBar->setProperty("value", static_cast<float>(_rgCompassCalProgress[0] + _rgCompassCalProgress[1] + _rgCompassCalProgress[2]) / 100.0);
508 }
509}
510
511void APMSensorsComponentController::_handleMagCalReport(const mavlink_message_t &message)
512{
513 if (_calTypeInProgress != QGCMAVLink::CalibrationMag) {
514 return;
515 }
516
517 mavlink_mag_cal_report_t magCalReport{};
518 mavlink_msg_mag_cal_report_decode(&message, &magCalReport);
519
520 qCDebug(APMSensorsComponentControllerVerboseLog) << "id:mask:status:fitness"
521 << magCalReport.compass_id << magCalReport.cal_mask << magCalReport.cal_status << magCalReport.fitness;
522
523 bool additionalCompassCompleted = false;
524 if ((magCalReport.compass_id < 3) && !_rgCompassCalComplete[magCalReport.compass_id]) {
525 if (magCalReport.cal_status == MAG_CAL_SUCCESS) {
526 _appendStatusLog(tr("Compass %1 calibration complete").arg(magCalReport.compass_id));
527 } else {
528 _appendStatusLog(tr("Compass %1 calibration below quality threshold").arg(magCalReport.compass_id));
529 }
530 _rgCompassCalComplete[magCalReport.compass_id] = true;
531 _rgCompassCalSucceeded[magCalReport.compass_id] = (magCalReport.cal_status == MAG_CAL_SUCCESS);
532 _rgCompassCalFitness[magCalReport.compass_id] = magCalReport.fitness;
533 additionalCompassCompleted = true;
534 }
535
536 if (_rgCompassCalComplete[0] && _rgCompassCalComplete[1] &&_rgCompassCalComplete[2]) {
537 for (int i = 0; i < 3; i++) {
538 qCDebug(APMSensorsComponentControllerLog) << QString("Onboard compass call report #%1: succeed:fitness %2:%3").arg(i).arg(_rgCompassCalSucceeded[i]).arg(_rgCompassCalFitness[i]);
539 }
540 emit compass1CalFitnessChanged(_rgCompassCalFitness[0]);
541 emit compass2CalFitnessChanged(_rgCompassCalFitness[1]);
542 emit compass3CalFitnessChanged(_rgCompassCalFitness[2]);
543 emit compass1CalSucceededChanged(_rgCompassCalSucceeded[0]);
544 emit compass2CalSucceededChanged(_rgCompassCalSucceeded[1]);
545 emit compass3CalSucceededChanged(_rgCompassCalSucceeded[2]);
546 if (_rgCompassCalSucceeded[0] && _rgCompassCalSucceeded[1] && _rgCompassCalSucceeded[2]) {
547 _appendStatusLog(tr("All compasses calibrated successfully"));
548 _appendStatusLog(tr("YOU MUST REBOOT YOUR VEHICLE NOW FOR NEW SETTINGS TO TAKE AFFECT"));
549 _stopCalibration(StopCalibrationSuccessShowLog);
550 } else {
551 _appendStatusLog(tr("Compass calibration failed"));
552 _appendStatusLog(tr("YOU MUST REBOOT YOUR VEHICLE NOW AND RETRY COMPASS CALIBRATION PRIOR TO FLIGHT"));
553 _stopCalibration(StopCalibrationFailed);
554 }
555 } else if (additionalCompassCompleted) {
556 _appendStatusLog(tr("Continue rotating..."));
557 }
558}
559
560bool APMSensorsComponentController::_handleCmdLongAccelcalVehiclePos(const mavlink_command_long_t &commandLong)
561{
562 bool updateImages = false;
563
564 switch (static_cast<ACCELCAL_VEHICLE_POS>(static_cast<int>(commandLong.param1))) {
565 case ACCELCAL_VEHICLE_POS_LEVEL:
566 if (!_orientationCalDownSideInProgress) {
567 updateImages = true;
568 _orientationCalDownSideInProgress = true;
569 _nextButton->setEnabled(true);
570 }
571 break;
572 case ACCELCAL_VEHICLE_POS_LEFT:
573 if (!_orientationCalLeftSideInProgress) {
574 updateImages = true;
575 _orientationCalDownSideDone = true;
576 _orientationCalDownSideInProgress = false;
577 _orientationCalLeftSideInProgress = true;
578 (void) _progressBar->setProperty("value", static_cast<qreal>(17 / 100.0));
579 }
580 break;
581 case ACCELCAL_VEHICLE_POS_RIGHT:
582 if (!_orientationCalRightSideInProgress) {
583 updateImages = true;
584 _orientationCalLeftSideDone = true;
585 _orientationCalLeftSideInProgress = false;
586 _orientationCalRightSideInProgress = true;
587 (void) _progressBar->setProperty("value", static_cast<qreal>(34 / 100.0));
588 }
589 break;
590 case ACCELCAL_VEHICLE_POS_NOSEDOWN:
591 if (!_orientationCalNoseDownSideInProgress) {
592 updateImages = true;
593 _orientationCalRightSideDone = true;
594 _orientationCalRightSideInProgress = false;
595 _orientationCalNoseDownSideInProgress = true;
596 (void) _progressBar->setProperty("value", static_cast<qreal>(51 / 100.0));
597 }
598 break;
599 case ACCELCAL_VEHICLE_POS_NOSEUP:
600 if (!_orientationCalTailDownSideInProgress) {
601 updateImages = true;
602 _orientationCalNoseDownSideDone = true;
603 _orientationCalNoseDownSideInProgress = false;
604 _orientationCalTailDownSideInProgress = true;
605 (void) _progressBar->setProperty("value", static_cast<qreal>(68 / 100.0));
606 }
607 break;
608 case ACCELCAL_VEHICLE_POS_BACK:
609 if (!_orientationCalUpsideDownSideInProgress) {
610 updateImages = true;
611 _orientationCalTailDownSideDone = true;
612 _orientationCalTailDownSideInProgress = false;
613 _orientationCalUpsideDownSideInProgress = true;
614 (void) _progressBar->setProperty("value", static_cast<qreal>(85 / 100.0));
615 }
616 break;
617 case ACCELCAL_VEHICLE_POS_SUCCESS:
618 _stopCalibration(StopCalibrationSuccess);
619 break;
620 case ACCELCAL_VEHICLE_POS_FAILED:
621 _stopCalibration(StopCalibrationFailed);
622 break;
623 case ACCELCAL_VEHICLE_POS_ENUM_END:
624 default:
625 break;
626 }
627
628 return updateImages;
629}
630
631void APMSensorsComponentController::_handleCommandLong(const mavlink_message_t &message)
632{
633 bool updateImages = false;
634 mavlink_command_long_t commandLong{};
635
636 mavlink_msg_command_long_decode(&message, &commandLong);
637
638 if (commandLong.command == MAV_CMD_ACCELCAL_VEHICLE_POS) {
639 updateImages = _handleCmdLongAccelcalVehiclePos(commandLong);
640 }
641
642 if (updateImages) {
646 }
647}
648
649void APMSensorsComponentController::_mavlinkMessageReceived(LinkInterface *link, const mavlink_message_t &message)
650{
651 Q_UNUSED(link);
652
653 if (message.sysid != _vehicle->id()) {
654 return;
655 }
656
657 switch (message.msgid) {
658 case MAVLINK_MSG_ID_COMMAND_ACK:
659 _handleCommandAck(message);
660 break;
661 case MAVLINK_MSG_ID_MAG_CAL_PROGRESS:
662 _handleMagCalProgress(message);
663 break;
664 case MAVLINK_MSG_ID_MAG_CAL_REPORT:
665 _handleMagCalReport(message);
666 break;
667 case MAVLINK_MSG_ID_COMMAND_LONG:
668 _handleCommandLong(message);
669 break;
670 }
671}
672
673void APMSensorsComponentController::_restorePreviousCompassCalFitness()
674{
675 if (_restoreCompassCalFitness) {
676 _restoreCompassCalFitness = false;
677 getParameterFact(ParameterManager::defaultComponentId, _compassCalFitnessParam)->setRawValue(_previousCompassCalFitness);
678 }
679}
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
Value after translation.
Definition Fact.h:85
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:2144
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:1390
int defaultComponentId() const
Definition Vehicle.h:682
ParameterManager * parameterManager()
Definition Vehicle.h:577
void startCalibration(QGCMAVLink::CalibrationType calType)
Definition Vehicle.cc:2328
void stopCalibration(bool showError)
Definition Vehicle.cc:2408
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