From a8af57ee73269cdcc918a3acca5fab52eb1f0ec9 Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Fri, 3 Apr 2015 18:41:43 -0700 Subject: [PATCH] Handle parameters not being available --- src/AutoPilotPlugins/PX4/SensorsComponent.qml | 22 ++++----------- .../PX4/SensorsComponentController.cc | 28 ++++++++++++++++--- .../PX4/SensorsComponentController.h | 8 ++++++ 3 files changed, 38 insertions(+), 20 deletions(-) diff --git a/src/AutoPilotPlugins/PX4/SensorsComponent.qml b/src/AutoPilotPlugins/PX4/SensorsComponent.qml index 558adca64..74c1d3db4 100644 --- a/src/AutoPilotPlugins/PX4/SensorsComponent.qml +++ b/src/AutoPilotPlugins/PX4/SensorsComponent.qml @@ -272,16 +272,6 @@ Rectangle { } Column { - property Fact cal_mag0_rot: Fact { name: "CAL_MAG0_ROT" } - property Fact cal_mag1_rot: Fact { name: "CAL_MAG1_ROT" } - property Fact cal_mag2_rot: Fact { name: "CAL_MAG2_ROT" } - - // Compass rotation parameter < 0 indicates either internal compass, or no compass. So in - // both those cases we do not show a rotation combo. - property bool showCompass0: cal_mag0_rot.value >= 0 - property bool showCompass1: cal_mag1_rot.value >= 0 - property bool showCompass2: cal_mag2_rot.value >= 0 - x: parent.width - rotationColumnWidth QGCLabel { text: "Autpilot Orientation" } @@ -309,8 +299,8 @@ Rectangle { fact: Fact { name: "CAL_MAG0_ROT" } } } - Loader { sourceComponent: parent.showCompass0 ? compass0ComponentLabel : null } - Loader { sourceComponent: parent.showCompass0 ? compass0ComponentCombo : null } + Loader { sourceComponent: controller.showCompass0 ? compass0ComponentLabel : null } + Loader { sourceComponent: controller.showCompass0 ? compass0ComponentCombo : null } // Compass 1 rotation Component { @@ -328,8 +318,8 @@ Rectangle { fact: Fact { name: "CAL_MAG1_ROT" } } } - Loader { sourceComponent: parent.showCompass1 ? compass1ComponentLabel : null } - Loader { sourceComponent: parent.showCompass1 ? compass1ComponentCombo : null } + Loader { sourceComponent: controller.showCompass1 ? compass1ComponentLabel : null } + Loader { sourceComponent: controller.showCompass1 ? compass1ComponentCombo : null } // Compass 2 rotation Component { @@ -347,8 +337,8 @@ Rectangle { fact: Fact { name: "CAL_MAG2_ROT" } } } - Loader { sourceComponent: parent.showCompass2 ? compass2ComponentLabel : null } - Loader { sourceComponent: parent.showCompass2 ? compass2ComponentCombo : null } + Loader { sourceComponent: controller.showCompass2 ? compass2ComponentLabel : null } + Loader { sourceComponent: controller.showCompass2 ? compass2ComponentCombo : null } } } } diff --git a/src/AutoPilotPlugins/PX4/SensorsComponentController.cc b/src/AutoPilotPlugins/PX4/SensorsComponentController.cc index ecd356595..a95b48fc5 100644 --- a/src/AutoPilotPlugins/PX4/SensorsComponentController.cc +++ b/src/AutoPilotPlugins/PX4/SensorsComponentController.cc @@ -38,6 +38,9 @@ SensorsComponentController::SensorsComponentController(AutoPilotPlugin* autopilo _progressBar(NULL), _showGyroCalArea(false), _showAccelCalArea(false), + _showCompass0(false), + _showCompass1(false), + _showCompass2(false), _gyroCalInProgress(false), _accelCalDownSideDone(false), _accelCalUpsideDownSideDone(false), @@ -54,7 +57,16 @@ SensorsComponentController::SensorsComponentController(AutoPilotPlugin* autopilo _textLoggingStarted(false), _autopilot(autopilot) { - Q_ASSERT(autopilot); + Q_ASSERT(_autopilot); + Q_ASSERT(_autopilot->pluginReady()); + + // Mag rotation parameters are optional + _showCompass0 = _autopilot->parameterExists("CAL_MAG0_ROT") && + _autopilot->getParameterFact("CAL_MAG0_ROT")->value().toInt() >= 0; + _showCompass1 = _autopilot->parameterExists("CAL_MAG1_ROT") && + _autopilot->getParameterFact("CAL_MAG1_ROT")->value().toInt() >= 0; + _showCompass2 = _autopilot->parameterExists("CAL_MAG2_ROT") && + _autopilot->getParameterFact("CAL_MAG2_ROT")->value().toInt() >= 0; } /// Appends the specified text to the status log area in the ui @@ -273,11 +285,19 @@ void SensorsComponentController::_refreshParams(void) _autopilot->refreshParameter(FactSystem::defaultComponentId, "CAL_ACC0_ID"); _autopilot->refreshParameter(FactSystem::defaultComponentId, "SENS_DPRES_OFF"); - _autopilot->refreshParameter(FactSystem::defaultComponentId, "CAL_MAG0_ROT"); - _autopilot->refreshParameter(FactSystem::defaultComponentId, "CAL_MAG1_ROT"); - _autopilot->refreshParameter(FactSystem::defaultComponentId, "CAL_MAG2_ROT"); _autopilot->refreshParameter(FactSystem::defaultComponentId, "SENS_BOARD_ROT"); + // Mag rotation parameters are optional + if (_autopilot->parameterExists("CAL_MAG0_ROT")) { + _autopilot->refreshParameter(FactSystem::defaultComponentId, "CAL_MAG0_ROT"); + } + if (_autopilot->parameterExists("CAL_MAG1_ROT")) { + _autopilot->refreshParameter(FactSystem::defaultComponentId, "CAL_MAG1_ROT"); + } + if (_autopilot->parameterExists("CAL_MAG2_ROT")) { + _autopilot->refreshParameter(FactSystem::defaultComponentId, "CAL_MAG2_ROT"); + } + // Pull full set in order to get all cal values back _autopilot->refreshAllParameters(); } diff --git a/src/AutoPilotPlugins/PX4/SensorsComponentController.h b/src/AutoPilotPlugins/PX4/SensorsComponentController.h index 560dd2f55..6d92cb46c 100644 --- a/src/AutoPilotPlugins/PX4/SensorsComponentController.h +++ b/src/AutoPilotPlugins/PX4/SensorsComponentController.h @@ -51,6 +51,10 @@ public: Q_PROPERTY(QQuickItem* accelButton MEMBER _accelButton) Q_PROPERTY(QQuickItem* airspeedButton MEMBER _airspeedButton) + Q_PROPERTY(bool showCompass0 MEMBER _showCompass0 CONSTANT) + Q_PROPERTY(bool showCompass1 MEMBER _showCompass1 CONSTANT) + Q_PROPERTY(bool showCompass2 MEMBER _showCompass2 CONSTANT) + Q_PROPERTY(bool showGyroCalArea MEMBER _showGyroCalArea NOTIFY showGyroCalAreaChanged) Q_PROPERTY(bool showAccelCalArea MEMBER _showAccelCalArea NOTIFY showAccelCalAreaChanged) @@ -110,6 +114,10 @@ private: bool _showGyroCalArea; bool _showAccelCalArea; + bool _showCompass0; + bool _showCompass1; + bool _showCompass2; + bool _gyroCalInProgress; bool _accelCalDownSideDone; -- 2.22.0