From 04f973690a217260e7a6197dfb7aca6bcadfe673 Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Wed, 14 Sep 2016 11:31:47 -0700 Subject: [PATCH] Move parameter apis to Vehicle --- src/AutoPilotPlugins/APM/APMAirframeComponent.cc | 2 +- src/AutoPilotPlugins/APM/APMCompassCal.cc | 12 +- src/AutoPilotPlugins/APM/APMPowerComponent.cc | 2 +- src/AutoPilotPlugins/APM/APMRadioComponent.cc | 20 +-- src/AutoPilotPlugins/APM/APMSensorsComponent.cc | 14 +- src/AutoPilotPlugins/APM/APMTuningComponent.cc | 2 +- src/AutoPilotPlugins/AutoPilotPlugin.cc | 10 -- src/AutoPilotPlugins/AutoPilotPlugin.h | 184 ++++++++++----------- src/AutoPilotPlugins/PX4/AirframeComponent.cc | 2 +- src/AutoPilotPlugins/PX4/FlightModesComponent.cc | 10 +- src/AutoPilotPlugins/PX4/PX4AutoPilotPlugin.cc | 4 +- src/AutoPilotPlugins/PX4/PX4RadioComponent.cc | 8 +- src/AutoPilotPlugins/PX4/PowerComponent.cc | 6 +- src/AutoPilotPlugins/PX4/SensorsComponent.cc | 6 +- .../PX4/SensorsComponentController.cc | 4 +- src/FactSystem/FactControls/FactPanelController.cc | 10 +- src/FactSystem/FactSystemTestBase.cc | 2 +- src/FirmwarePlugin/APM/ArduCopterFirmwarePlugin.cc | 2 +- src/FlightMap/Widgets/ValuesWidget.qml | 2 +- src/FlightMap/Widgets/VibrationWidget.qml | 2 +- src/QmlControls/ParameterEditorController.cc | 6 +- src/VehicleSetup/VehicleComponent.cc | 4 +- src/qgcunittest/RadioConfigTest.cc | 18 +- src/ui/QGCMapRCToParamDialog.cpp | 7 +- 24 files changed, 158 insertions(+), 181 deletions(-) diff --git a/src/AutoPilotPlugins/APM/APMAirframeComponent.cc b/src/AutoPilotPlugins/APM/APMAirframeComponent.cc index 75ee315..ce09588 100644 --- a/src/AutoPilotPlugins/APM/APMAirframeComponent.cc +++ b/src/AutoPilotPlugins/APM/APMAirframeComponent.cc @@ -52,7 +52,7 @@ bool APMAirframeComponent::requiresSetup(void) const bool APMAirframeComponent::setupComplete(void) const { if (_requiresFrameSetup) { - return _autopilot->getParameterFact(FactSystem::defaultComponentId, QStringLiteral("FRAME"))->rawValue().toInt() >= 0; + return _vehicle->getParameterFact(FactSystem::defaultComponentId, QStringLiteral("FRAME"))->rawValue().toInt() >= 0; } else { return true; } diff --git a/src/AutoPilotPlugins/APM/APMCompassCal.cc b/src/AutoPilotPlugins/APM/APMCompassCal.cc index f2a61da..71a2570 100644 --- a/src/AutoPilotPlugins/APM/APMCompassCal.cc +++ b/src/AutoPilotPlugins/APM/APMCompassCal.cc @@ -609,16 +609,15 @@ void APMCompassCal::startCalibration(void) connect(_calWorkerThread, &CalWorkerThread::vehicleTextMessage, this, &APMCompassCal::vehicleTextMessage); // Clear the offset parameters so we get raw data - AutoPilotPlugin* plugin = _vehicle->autopilotPlugin(); for (int i=0; i<3; i++) { _calWorkerThread->rgCompassAvailable[i] = true; const char* deviceIdParam = CalWorkerThread::rgCompassParams[i][3]; - if (plugin->parameterExists(-1, deviceIdParam)) { - _calWorkerThread->rgCompassAvailable[i] = plugin->getParameterFact(-1, deviceIdParam)->rawValue().toInt() > 0; + if (_vehicle->parameterExists(-1, deviceIdParam)) { + _calWorkerThread->rgCompassAvailable[i] = _vehicle->getParameterFact(-1, deviceIdParam)->rawValue().toInt() > 0; for (int j=0; j<3; j++) { const char* offsetParam = CalWorkerThread::rgCompassParams[i][j]; - Fact* paramFact = plugin->getParameterFact(-1, offsetParam); + Fact* paramFact = _vehicle->getParameterFact(-1, offsetParam); _rgSavedCompassOffsets[i][j] = paramFact->rawValue().toFloat(); paramFact->setRawValue(0.0); @@ -637,12 +636,11 @@ void APMCompassCal::cancelCalibration(void) _stopCalibration(); // Put the original offsets back - AutoPilotPlugin* plugin = _vehicle->autopilotPlugin(); for (int i=0; i<3; i++) { for (int j=0; j<3; j++) { const char* offsetParam = CalWorkerThread::rgCompassParams[i][j]; - if (plugin->parameterExists(-1, offsetParam)) { - plugin->getParameterFact(-1, offsetParam)-> setRawValue(_rgSavedCompassOffsets[i][j]); + if (_vehicle->parameterExists(-1, offsetParam)) { + _vehicle->getParameterFact(-1, offsetParam)-> setRawValue(_rgSavedCompassOffsets[i][j]); } } } diff --git a/src/AutoPilotPlugins/APM/APMPowerComponent.cc b/src/AutoPilotPlugins/APM/APMPowerComponent.cc index f5a8e1d..a63f48b 100644 --- a/src/AutoPilotPlugins/APM/APMPowerComponent.cc +++ b/src/AutoPilotPlugins/APM/APMPowerComponent.cc @@ -40,7 +40,7 @@ bool APMPowerComponent::requiresSetup(void) const bool APMPowerComponent::setupComplete(void) const { - return _autopilot->getParameterFact(FactSystem::defaultComponentId, QStringLiteral("BATT_CAPACITY"))->rawValue().toInt() != 0; + return _vehicle->getParameterFact(FactSystem::defaultComponentId, QStringLiteral("BATT_CAPACITY"))->rawValue().toInt() != 0; } QStringList APMPowerComponent::setupCompleteChangedTriggerList(void) const diff --git a/src/AutoPilotPlugins/APM/APMRadioComponent.cc b/src/AutoPilotPlugins/APM/APMRadioComponent.cc index 5303596..3b1748a 100644 --- a/src/AutoPilotPlugins/APM/APMRadioComponent.cc +++ b/src/AutoPilotPlugins/APM/APMRadioComponent.cc @@ -19,7 +19,7 @@ APMRadioComponent::APMRadioComponent(Vehicle* vehicle, AutoPilotPlugin* autopilo _mapParams << QStringLiteral("RCMAP_ROLL") << QStringLiteral("RCMAP_PITCH") << QStringLiteral("RCMAP_YAW") << QStringLiteral("RCMAP_THROTTLE"); foreach (const QString& mapParam, _mapParams) { - Fact* fact = _autopilot->getParameterFact(-1, mapParam); + Fact* fact = _vehicle->getParameterFact(-1, mapParam); connect(fact, &Fact::valueChanged, this, &APMRadioComponent::_triggerChanged); } @@ -56,7 +56,7 @@ bool APMRadioComponent::setupComplete(void) const // First check for all attitude controls mapped for (int i=0; i<_mapParams.count(); i++) { - mapValues << _autopilot->getParameterFact(FactSystem::defaultComponentId, _mapParams[i])->rawValue().toInt(); + mapValues << _vehicle->getParameterFact(FactSystem::defaultComponentId, _mapParams[i])->rawValue().toInt(); if (mapValues[i] <= 0) { return false; } @@ -64,14 +64,14 @@ bool APMRadioComponent::setupComplete(void) const // Next check RC#_MIN/MAX/TRIM all at defaults foreach (const QString& mapParam, _mapParams) { - int channel = _autopilot->getParameterFact(-1, mapParam)->rawValue().toInt(); - if (_autopilot->getParameterFact(-1, QString("RC%1_MIN").arg(channel))->rawValue().toInt() != 1100) { + int channel = _vehicle->getParameterFact(-1, mapParam)->rawValue().toInt(); + if (_vehicle->getParameterFact(-1, QString("RC%1_MIN").arg(channel))->rawValue().toInt() != 1100) { return true; } - if (_autopilot->getParameterFact(-1, QString("RC%1_MAX").arg(channel))->rawValue().toInt() != 1900) { + if (_vehicle->getParameterFact(-1, QString("RC%1_MAX").arg(channel))->rawValue().toInt() != 1900) { return true; } - if (_autopilot->getParameterFact(-1, QString("RC%1_TRIM").arg(channel))->rawValue().toInt() != 1500) { + if (_vehicle->getParameterFact(-1, QString("RC%1_TRIM").arg(channel))->rawValue().toInt() != 1500) { return true; } } @@ -116,17 +116,17 @@ void APMRadioComponent::_connectSetupTriggers(void) // Get the channels for attitude controls and connect to those values for triggers foreach (const QString& mapParam, _mapParams) { - int channel = _autopilot->getParameterFact(FactSystem::defaultComponentId, mapParam)->rawValue().toInt(); + int channel = _vehicle->getParameterFact(FactSystem::defaultComponentId, mapParam)->rawValue().toInt(); - Fact* fact = _autopilot->getParameterFact(-1, QString("RC%1_MIN").arg(channel)); + Fact* fact = _vehicle->getParameterFact(-1, QString("RC%1_MIN").arg(channel)); _triggerFacts << fact; connect(fact, &Fact::valueChanged, this, &APMRadioComponent::_triggerChanged); - fact = _autopilot->getParameterFact(-1, QString("RC%1_MAX").arg(channel)); + fact = _vehicle->getParameterFact(-1, QString("RC%1_MAX").arg(channel)); _triggerFacts << fact; connect(fact, &Fact::valueChanged, this, &APMRadioComponent::_triggerChanged); - fact = _autopilot->getParameterFact(-1, QString("RC%1_TRIM").arg(channel)); + fact = _vehicle->getParameterFact(-1, QString("RC%1_TRIM").arg(channel)); _triggerFacts << fact; connect(fact, &Fact::valueChanged, this, &APMRadioComponent::_triggerChanged); } diff --git a/src/AutoPilotPlugins/APM/APMSensorsComponent.cc b/src/AutoPilotPlugins/APM/APMSensorsComponent.cc index 74bdc6a..aa353e1 100644 --- a/src/AutoPilotPlugins/APM/APMSensorsComponent.cc +++ b/src/AutoPilotPlugins/APM/APMSensorsComponent.cc @@ -62,7 +62,7 @@ QStringList APMSensorsComponent::setupCompleteChangedTriggerList(void) const // Accelerometer triggers triggers << "INS_ACCOFFS_X" << "INS_ACCOFFS_Y" << "INS_ACCOFFS_Z"; - if (_autopilot->parameterExists(FactSystem::defaultComponentId, QStringLiteral("INS_USE"))) { + if (_vehicle->parameterExists(FactSystem::defaultComponentId, QStringLiteral("INS_USE"))) { triggers << QStringLiteral("INS_USE") << QStringLiteral("INS_USE2") << QStringLiteral("INS_USE3"); triggers << QStringLiteral("INS_ACC2OFFS_X") << QStringLiteral("INS_ACC2OFFS_Y") << QStringLiteral("INS_ACC2OFFS_Z"); triggers << QStringLiteral("INS_ACC3OFFS_X") << QStringLiteral("INS_ACC3OFFS_Y") << QStringLiteral("INS_ACC3OFFS_Z"); @@ -108,10 +108,10 @@ bool APMSensorsComponent::compassSetupNeeded(void) const rgOffsets[2] << QStringLiteral("COMPASS_OFS3_X") << QStringLiteral("COMPASS_OFS3_Y") << QStringLiteral("COMPASS_OFS3_Z"); for (size_t i=0; igetParameterFact(FactSystem::defaultComponentId, rgDevicesIds[i])->rawValue().toInt() != 0 && - _autopilot->getParameterFact(FactSystem::defaultComponentId, rgCompassUse[i])->rawValue().toInt() != 0) { + if (_vehicle->getParameterFact(FactSystem::defaultComponentId, rgDevicesIds[i])->rawValue().toInt() != 0 && + _vehicle->getParameterFact(FactSystem::defaultComponentId, rgCompassUse[i])->rawValue().toInt() != 0) { for (size_t j=0; jgetParameterFact(FactSystem::defaultComponentId, rgOffsets[i][j])->rawValue().toFloat() == 0.0f) { + if (_vehicle->getParameterFact(FactSystem::defaultComponentId, rgOffsets[i][j])->rawValue().toFloat() == 0.0f) { return true; } } @@ -133,7 +133,7 @@ bool APMSensorsComponent::accelSetupNeeded(void) const rgOffsets.clear(); // This parameter is not available in all firmware version. Specifically missing from older Solo firmware. - if (_autopilot->parameterExists(FactSystem::defaultComponentId, QStringLiteral("INS_USE"))) { + if (_vehicle->parameterExists(FactSystem::defaultComponentId, QStringLiteral("INS_USE"))) { rgUse << QStringLiteral("INS_USE") << QStringLiteral("INS_USE2") << QStringLiteral("INS_USE3"); // We have usage information for the remaining accels, so we can test them sa well @@ -147,9 +147,9 @@ bool APMSensorsComponent::accelSetupNeeded(void) const } for (int i=0; igetParameterFact(FactSystem::defaultComponentId, rgUse[i])->rawValue().toInt() != 0) { + if (rgUse.count() == 0 || _vehicle->getParameterFact(FactSystem::defaultComponentId, rgUse[i])->rawValue().toInt() != 0) { for (int j=0; jgetParameterFact(FactSystem::defaultComponentId, rgAccels[i][j])->rawValue().toFloat() == 0.0f) { + if (_vehicle->getParameterFact(FactSystem::defaultComponentId, rgAccels[i][j])->rawValue().toFloat() == 0.0f) { return true; } } diff --git a/src/AutoPilotPlugins/APM/APMTuningComponent.cc b/src/AutoPilotPlugins/APM/APMTuningComponent.cc index d00648d..d2e30b4 100644 --- a/src/AutoPilotPlugins/APM/APMTuningComponent.cc +++ b/src/AutoPilotPlugins/APM/APMTuningComponent.cc @@ -60,7 +60,7 @@ QUrl APMTuningComponent::setupSource(void) const case MAV_TYPE_OCTOROTOR: case MAV_TYPE_TRICOPTER: // Older firmwares do not have CH9_OPT, we don't support Tuning on older firmwares - if (_autopilot->parameterExists(-1, QStringLiteral("CH9_OPT"))) { + if (_vehicle->parameterExists(-1, QStringLiteral("CH9_OPT"))) { qmlFile = QStringLiteral("qrc:/qml/APMTuningComponentCopter.qml"); } break; diff --git a/src/AutoPilotPlugins/AutoPilotPlugin.cc b/src/AutoPilotPlugins/AutoPilotPlugin.cc index 529b1e7..cfbf601 100644 --- a/src/AutoPilotPlugins/AutoPilotPlugin.cc +++ b/src/AutoPilotPlugins/AutoPilotPlugin.cc @@ -117,16 +117,6 @@ void AutoPilotPlugin::refreshParametersPrefix(int componentId, const QString& na _vehicle->getParameterLoader()->refreshParametersPrefix(componentId, namePrefix); } -bool AutoPilotPlugin::parameterExists(int componentId, const QString& name) const -{ - return _vehicle->getParameterLoader()->parameterExists(componentId, name); -} - -Fact* AutoPilotPlugin::getParameterFact(int componentId, const QString& name) -{ - return _vehicle->getParameterLoader()->getFact(componentId, name); -} - bool AutoPilotPlugin::factExists(FactSystem::Provider_t provider, int componentId, const QString& name) { switch (provider) { diff --git a/src/AutoPilotPlugins/AutoPilotPlugin.h b/src/AutoPilotPlugins/AutoPilotPlugin.h index b0910c2..b483368 100644 --- a/src/AutoPilotPlugins/AutoPilotPlugin.h +++ b/src/AutoPilotPlugins/AutoPilotPlugin.h @@ -7,131 +7,119 @@ * ****************************************************************************/ +#ifndef AUTOPILOTPLUGIN_H +#define AUTOPILOTPLUGIN_H - /// @file - /// @author Don Gagne +#include +#include +#include +#include - #ifndef AUTOPILOTPLUGIN_H - #define AUTOPILOTPLUGIN_H +#include "VehicleComponent.h" +#include "FactSystem.h" +#include "Vehicle.h" - #include - #include - #include - #include +class ParameterLoader; +class Vehicle; +class FirmwarePlugin; - #include "VehicleComponent.h" - #include "FactSystem.h" - #include "Vehicle.h" +/// This is the base class for AutoPilot plugins +/// +/// The AutoPilotPlugin class is an abstract base class which represent the methods and objects +/// which are specific to a certain AutoPilot. This is the only place where AutoPilot specific +/// code should reside in QGroundControl. The remainder of the QGroundControl source is +/// generic to a common mavlink implementation. - class ParameterLoader; - class Vehicle; - class FirmwarePlugin; +class AutoPilotPlugin : public QObject +{ + Q_OBJECT - /// This is the base class for AutoPilot plugins - /// - /// The AutoPilotPlugin class is an abstract base class which represent the methods and objects - /// which are specific to a certain AutoPilot. This is the only place where AutoPilot specific - /// code should reside in QGroundControl. The remainder of the QGroundControl source is - /// generic to a common mavlink implementation. +public: + AutoPilotPlugin(Vehicle* vehicle, QObject* parent); + ~AutoPilotPlugin(); - class AutoPilotPlugin : public QObject - { - Q_OBJECT + /// true: parameters are ready for use + Q_PROPERTY(bool parametersReady READ parametersReady NOTIFY parametersReadyChanged) - public: - AutoPilotPlugin(Vehicle* vehicle, QObject* parent); - ~AutoPilotPlugin(); + /// true: parameters are missing from firmware response, false: all parameters received from firmware + Q_PROPERTY(bool missingParameters READ missingParameters NOTIFY missingParametersChanged) - /// true: parameters are ready for use - Q_PROPERTY(bool parametersReady READ parametersReady NOTIFY parametersReadyChanged) + /// List of VehicleComponent objects + Q_PROPERTY(QVariantList vehicleComponents READ vehicleComponents CONSTANT) - /// true: parameters are missing from firmware response, false: all parameters received from firmware - Q_PROPERTY(bool missingParameters READ missingParameters NOTIFY missingParametersChanged) + /// false: One or more vehicle components require setup + Q_PROPERTY(bool setupComplete READ setupComplete NOTIFY setupCompleteChanged) - /// List of VehicleComponent objects - Q_PROPERTY(QVariantList vehicleComponents READ vehicleComponents CONSTANT) + /// Reset all parameters to their default values + Q_INVOKABLE void resetAllParametersToDefaults(void); - /// false: One or more vehicle components require setup - Q_PROPERTY(bool setupComplete READ setupComplete NOTIFY setupCompleteChanged) + /// Re-request the full set of parameters from the autopilot + Q_INVOKABLE void refreshAllParameters(unsigned char componentID = MAV_COMP_ID_ALL); - /// Reset all parameters to their default values - Q_INVOKABLE void resetAllParametersToDefaults(void); + /// Request a refresh on the specific parameter + Q_INVOKABLE void refreshParameter(int componentId, const QString& name); - /// Re-request the full set of parameters from the autopilot - Q_INVOKABLE void refreshAllParameters(unsigned char componentID = MAV_COMP_ID_ALL); + /// Request a refresh on all parameters that begin with the specified prefix + Q_INVOKABLE void refreshParametersPrefix(int componentId, const QString& namePrefix); - /// Request a refresh on the specific parameter - Q_INVOKABLE void refreshParameter(int componentId, const QString& name); + /// Returns all parameter names + QStringList parameterNames(int componentId); - /// Request a refresh on all parameters that begin with the specified prefix - Q_INVOKABLE void refreshParametersPrefix(int componentId, const QString& namePrefix); + /// Writes the parameter facts to the specified stream + void writeParametersToStream(QTextStream &stream); - /// Returns true if the specifed parameter exists from the default component - Q_INVOKABLE bool parameterExists(int componentId, const QString& name) const; + /// Reads the parameters from the stream and updates values + /// @return Errors during load. Empty string for no errors + QString readParametersFromStream(QTextStream &stream); - /// Returns all parameter names - QStringList parameterNames(int componentId); + /// Returns true if the specifed fact exists + Q_INVOKABLE bool factExists(FactSystem::Provider_t provider, ///< fact provider + int componentId, ///< fact component, -1=default component + const QString& name); ///< fact name - /// Returns the specified parameter Fact from the default component - /// WARNING: Returns a default Fact if parameter does not exists. If that possibility exists, check for existence first with - /// parameterExists. - Fact* getParameterFact(int componentId, const QString& name); + /// Returns the specified Fact. + /// WARNING: Will assert if fact does not exists. If that possibility exists, check for existence first with + /// factExists. + Fact* getFact(FactSystem::Provider_t provider, ///< fact provider + int componentId, ///< fact component, -1=default component + const QString& name); ///< fact name - /// Writes the parameter facts to the specified stream - void writeParametersToStream(QTextStream &stream); + const QMap >& getGroupMap(void); - /// Reads the parameters from the stream and updates values - /// @return Errors during load. Empty string for no errors - QString readParametersFromStream(QTextStream &stream); + // Must be implemented by derived class + virtual const QVariantList& vehicleComponents(void) = 0; - /// Returns true if the specifed fact exists - Q_INVOKABLE bool factExists(FactSystem::Provider_t provider, ///< fact provider - int componentId, ///< fact component, -1=default component - const QString& name); ///< fact name + // Property accessors + bool parametersReady(void) { return _parametersReady; } + bool missingParameters(void) { return _missingParameters; } + bool setupComplete(void); - /// Returns the specified Fact. - /// WARNING: Will assert if fact does not exists. If that possibility exists, check for existence first with - /// factExists. - Fact* getFact(FactSystem::Provider_t provider, ///< fact provider - int componentId, ///< fact component, -1=default component - const QString& name); ///< fact name + Vehicle* vehicle(void) { return _vehicle; } + virtual void _parametersReadyPreChecks(bool parametersReady) = 0; - const QMap >& getGroupMap(void); +signals: + void parametersReadyChanged(bool parametersReady); + void missingParametersChanged(bool missingParameters); + void setupCompleteChanged(bool setupComplete); + void parameterListProgress(float value); - // Must be implemented by derived class - virtual const QVariantList& vehicleComponents(void) = 0; +protected: + /// All access to AutoPilotPugin objects is through getInstanceForAutoPilotPlugin + AutoPilotPlugin(QObject* parent = NULL) : QObject(parent) { } - // Property accessors - bool parametersReady(void) { return _parametersReady; } - bool missingParameters(void) { return _missingParameters; } - bool setupComplete(void); + Vehicle* _vehicle; + FirmwarePlugin* _firmwarePlugin; + bool _parametersReady; + bool _missingParameters; + bool _setupComplete; - Vehicle* vehicle(void) { return _vehicle; } - virtual void _parametersReadyPreChecks(bool parametersReady) = 0; - signals: - void parametersReadyChanged(bool parametersReady); - void missingParametersChanged(bool missingParameters); - void setupCompleteChanged(bool setupComplete); - void parameterListProgress(float value); +private slots: + void _uasDisconnected(void); + void _parametersReadyChanged(bool parametersReady); - protected: - /// All access to AutoPilotPugin objects is through getInstanceForAutoPilotPlugin - AutoPilotPlugin(QObject* parent = NULL) : QObject(parent) { } +private: + void _recalcSetupComplete(void); +}; - Vehicle* _vehicle; - FirmwarePlugin* _firmwarePlugin; - bool _parametersReady; - bool _missingParameters; - bool _setupComplete; - - - private slots: - void _uasDisconnected(void); - void _parametersReadyChanged(bool parametersReady); - - private: - void _recalcSetupComplete(void); - }; - - #endif +#endif diff --git a/src/AutoPilotPlugins/PX4/AirframeComponent.cc b/src/AutoPilotPlugins/PX4/AirframeComponent.cc index 2f30fc2..daa0eb4 100644 --- a/src/AutoPilotPlugins/PX4/AirframeComponent.cc +++ b/src/AutoPilotPlugins/PX4/AirframeComponent.cc @@ -129,7 +129,7 @@ bool AirframeComponent::requiresSetup(void) const bool AirframeComponent::setupComplete(void) const { - return _autopilot->getParameterFact(FactSystem::defaultComponentId, "SYS_AUTOSTART")->rawValue().toInt() != 0; + return _vehicle->getParameterFact(FactSystem::defaultComponentId, "SYS_AUTOSTART")->rawValue().toInt() != 0; } QStringList AirframeComponent::setupCompleteChangedTriggerList(void) const diff --git a/src/AutoPilotPlugins/PX4/FlightModesComponent.cc b/src/AutoPilotPlugins/PX4/FlightModesComponent.cc index 38e39a7..da66034 100644 --- a/src/AutoPilotPlugins/PX4/FlightModesComponent.cc +++ b/src/AutoPilotPlugins/PX4/FlightModesComponent.cc @@ -43,17 +43,17 @@ QString FlightModesComponent::iconResource(void) const bool FlightModesComponent::requiresSetup(void) const { - return _autopilot->getParameterFact(-1, "COM_RC_IN_MODE")->rawValue().toInt() == 1 ? false : true; + return _vehicle->getParameterFact(-1, "COM_RC_IN_MODE")->rawValue().toInt() == 1 ? false : true; } bool FlightModesComponent::setupComplete(void) const { - if (_autopilot->getParameterFact(-1, "COM_RC_IN_MODE")->rawValue().toInt() == 1) { + if (_vehicle->getParameterFact(-1, "COM_RC_IN_MODE")->rawValue().toInt() == 1) { return true; } - if (_autopilot->getParameterFact(FactSystem::defaultComponentId, "RC_MAP_MODE_SW")->rawValue().toInt() != 0 || - (_autopilot->parameterExists(FactSystem::defaultComponentId, "RC_MAP_FLTMODE") && _autopilot->getParameterFact(FactSystem::defaultComponentId, "RC_MAP_FLTMODE")->rawValue().toInt() != 0)) { + if (_vehicle->getParameterFact(FactSystem::defaultComponentId, "RC_MAP_MODE_SW")->rawValue().toInt() != 0 || + (_vehicle->parameterExists(FactSystem::defaultComponentId, "RC_MAP_FLTMODE") && _vehicle->getParameterFact(FactSystem::defaultComponentId, "RC_MAP_FLTMODE")->rawValue().toInt() != 0)) { return true; } @@ -81,7 +81,7 @@ QUrl FlightModesComponent::summaryQmlSource(void) const QString FlightModesComponent::prerequisiteSetup(void) const { - if (_autopilot->getParameterFact(-1, "COM_RC_IN_MODE")->rawValue().toInt() == 1) { + if (_vehicle->getParameterFact(-1, "COM_RC_IN_MODE")->rawValue().toInt() == 1) { // No RC input return QString(); } else { diff --git a/src/AutoPilotPlugins/PX4/PX4AutoPilotPlugin.cc b/src/AutoPilotPlugins/PX4/PX4AutoPilotPlugin.cc index a2f91ec..805a9b2 100644 --- a/src/AutoPilotPlugins/PX4/PX4AutoPilotPlugin.cc +++ b/src/AutoPilotPlugins/PX4/PX4AutoPilotPlugin.cc @@ -117,8 +117,8 @@ void PX4AutoPilotPlugin::_parametersReadyPreChecks(bool missingParameters) // Check for older parameter version set // FIXME: Firmware is moving to version stamp parameter set. Once that is complete the version stamp // should be used instead. - if (parameterExists(FactSystem::defaultComponentId, "SENS_GYRO_XOFF") || - parameterExists(FactSystem::defaultComponentId, "COM_DL_LOSS_EN")) { + if (_vehicle->parameterExists(FactSystem::defaultComponentId, "SENS_GYRO_XOFF") || + _vehicle->parameterExists(FactSystem::defaultComponentId, "COM_DL_LOSS_EN")) { _incorrectParameterVersion = true; qgcApp()->showMessage("This version of GroundControl can only perform vehicle setup on a newer version of firmware. " "Please perform a Firmware Upgrade if you wish to use Vehicle Setup."); diff --git a/src/AutoPilotPlugins/PX4/PX4RadioComponent.cc b/src/AutoPilotPlugins/PX4/PX4RadioComponent.cc index 1b2ca35..b0b762d 100644 --- a/src/AutoPilotPlugins/PX4/PX4RadioComponent.cc +++ b/src/AutoPilotPlugins/PX4/PX4RadioComponent.cc @@ -35,18 +35,18 @@ QString PX4RadioComponent::iconResource(void) const bool PX4RadioComponent::requiresSetup(void) const { - return _autopilot->getParameterFact(-1, "COM_RC_IN_MODE")->rawValue().toInt() == 1 ? false : true; + return _vehicle->getParameterFact(-1, "COM_RC_IN_MODE")->rawValue().toInt() == 1 ? false : true; } bool PX4RadioComponent::setupComplete(void) const { - if (_autopilot->getParameterFact(-1, "COM_RC_IN_MODE")->rawValue().toInt() != 1) { + if (_vehicle->getParameterFact(-1, "COM_RC_IN_MODE")->rawValue().toInt() != 1) { // The best we can do to detect the need for a radio calibration is look for attitude // controls to be mapped. QStringList attitudeMappings; attitudeMappings << "RC_MAP_ROLL" << "RC_MAP_PITCH" << "RC_MAP_YAW" << "RC_MAP_THROTTLE"; foreach(const QString &mapParam, attitudeMappings) { - if (_autopilot->getParameterFact(FactSystem::defaultComponentId, mapParam)->rawValue().toInt() == 0) { + if (_vehicle->getParameterFact(FactSystem::defaultComponentId, mapParam)->rawValue().toInt() == 0) { return false; } } @@ -76,7 +76,7 @@ QUrl PX4RadioComponent::summaryQmlSource(void) const QString PX4RadioComponent::prerequisiteSetup(void) const { - if (_autopilot->getParameterFact(-1, "COM_RC_IN_MODE")->rawValue().toInt() != 1) { + if (_vehicle->getParameterFact(-1, "COM_RC_IN_MODE")->rawValue().toInt() != 1) { PX4AutoPilotPlugin* plugin = dynamic_cast(_autopilot); if (!plugin->airframeComponent()->setupComplete()) { diff --git a/src/AutoPilotPlugins/PX4/PowerComponent.cc b/src/AutoPilotPlugins/PX4/PowerComponent.cc index 8c91d5a..fa43c9a 100644 --- a/src/AutoPilotPlugins/PX4/PowerComponent.cc +++ b/src/AutoPilotPlugins/PX4/PowerComponent.cc @@ -44,9 +44,9 @@ bool PowerComponent::requiresSetup(void) const bool PowerComponent::setupComplete(void) const { QVariant cvalue, evalue, nvalue; - return _autopilot->getParameterFact(FactSystem::defaultComponentId, "BAT_V_CHARGED")->rawValue().toFloat() != 0.0f && - _autopilot->getParameterFact(FactSystem::defaultComponentId, "BAT_V_EMPTY")->rawValue().toFloat() != 0.0f && - _autopilot->getParameterFact(FactSystem::defaultComponentId, "BAT_N_CELLS")->rawValue().toInt() != 0; + return _vehicle->getParameterFact(FactSystem::defaultComponentId, "BAT_V_CHARGED")->rawValue().toFloat() != 0.0f && + _vehicle->getParameterFact(FactSystem::defaultComponentId, "BAT_V_EMPTY")->rawValue().toFloat() != 0.0f && + _vehicle->getParameterFact(FactSystem::defaultComponentId, "BAT_N_CELLS")->rawValue().toInt() != 0; } QStringList PowerComponent::setupCompleteChangedTriggerList(void) const diff --git a/src/AutoPilotPlugins/PX4/SensorsComponent.cc b/src/AutoPilotPlugins/PX4/SensorsComponent.cc index 7396bbf..4d8928a 100644 --- a/src/AutoPilotPlugins/PX4/SensorsComponent.cc +++ b/src/AutoPilotPlugins/PX4/SensorsComponent.cc @@ -49,14 +49,14 @@ bool SensorsComponent::requiresSetup(void) const bool SensorsComponent::setupComplete(void) const { foreach (const QString &triggerParam, _deviceIds) { - if (_autopilot->getParameterFact(FactSystem::defaultComponentId, triggerParam)->rawValue().toFloat() == 0.0f) { + if (_vehicle->getParameterFact(FactSystem::defaultComponentId, triggerParam)->rawValue().toFloat() == 0.0f) { return false; } } if (_vehicle->fixedWing() || _vehicle->vtol()) { - if (_autopilot->getParameterFact(FactSystem::defaultComponentId, _airspeedBreaker)->rawValue().toInt() != 162128) { - if (_autopilot->getParameterFact(FactSystem::defaultComponentId, _airspeedCal)->rawValue().toFloat() == 0.0f) { + if (_vehicle->getParameterFact(FactSystem::defaultComponentId, _airspeedBreaker)->rawValue().toInt() != 162128) { + if (_vehicle->getParameterFact(FactSystem::defaultComponentId, _airspeedCal)->rawValue().toFloat() == 0.0f) { return false; } } diff --git a/src/AutoPilotPlugins/PX4/SensorsComponentController.cc b/src/AutoPilotPlugins/PX4/SensorsComponentController.cc index f3b0300..cd1cac9 100644 --- a/src/AutoPilotPlugins/PX4/SensorsComponentController.cc +++ b/src/AutoPilotPlugins/PX4/SensorsComponentController.cc @@ -306,9 +306,9 @@ void SensorsComponentController::_handleUASTextMessage(int uasId, int compId, in // Work out what the autopilot is configured to int sides = 0; - if (_autopilot->parameterExists(FactSystem::defaultComponentId, "CAL_MAG_SIDES")) { + if (_vehicle->parameterExists(FactSystem::defaultComponentId, "CAL_MAG_SIDES")) { // Read the requested calibration directions off the system - sides = _autopilot->getParameterFact(FactSystem::defaultComponentId, "CAL_MAG_SIDES")->rawValue().toFloat(); + sides = _vehicle->getParameterFact(FactSystem::defaultComponentId, "CAL_MAG_SIDES")->rawValue().toFloat(); } else { // There is no valid setting, default to all six sides sides = (1 << 5) | (1 << 4) | (1 << 3) | (1 << 2) | (1 << 1) | (1 << 0); diff --git a/src/FactSystem/FactControls/FactPanelController.cc b/src/FactSystem/FactControls/FactPanelController.cc index 83f6b9d..3ada975 100644 --- a/src/FactSystem/FactControls/FactPanelController.cc +++ b/src/FactSystem/FactControls/FactPanelController.cc @@ -31,6 +31,8 @@ FactPanelController::FactPanelController(bool standaloneUnitTesting) if (_vehicle) { _uas = _vehicle->uas(); _autopilot = _vehicle->autopilotPlugin(); + } else { + _vehicle = qgcApp()->toolbox()->multiVehicleManager()->offlineEditingVehicle(); } if (!standaloneUnitTesting) { @@ -102,7 +104,7 @@ bool FactPanelController::_allParametersExists(int componentId, QStringList name bool noMissingFacts = true; foreach (const QString &name, names) { - if (_autopilot && !_autopilot->parameterExists(componentId, name)) { + if (_vehicle && !_vehicle->parameterExists(componentId, name)) { _reportMissingParameter(componentId, name); noMissingFacts = false; } @@ -120,8 +122,8 @@ void FactPanelController::_checkForMissingFactPanel(void) Fact* FactPanelController::getParameterFact(int componentId, const QString& name, bool reportMissing) { - if (_autopilot && _autopilot->parameterExists(componentId, name)) { - Fact* fact = _autopilot->getParameterFact(componentId, name); + if (_vehicle && _vehicle->parameterExists(componentId, name)) { + Fact* fact = _vehicle->getParameterFact(componentId, name); QQmlEngine::setObjectOwnership(fact, QQmlEngine::CppOwnership); return fact; } else { @@ -133,7 +135,7 @@ Fact* FactPanelController::getParameterFact(int componentId, const QString& name bool FactPanelController::parameterExists(int componentId, const QString& name) { - return _autopilot ? _autopilot->parameterExists(componentId, name) : false; + return _vehicle ? _vehicle->parameterExists(componentId, name) : false; } void FactPanelController::_showInternalError(const QString& errorMsg) diff --git a/src/FactSystem/FactSystemTestBase.cc b/src/FactSystem/FactSystemTestBase.cc index fe73eb1..991d043 100644 --- a/src/FactSystem/FactSystemTestBase.cc +++ b/src/FactSystem/FactSystemTestBase.cc @@ -96,7 +96,7 @@ void FactSystemTestBase::_qmlUpdate_test(void) // Change the value QVariant paramValue = 12; - _plugin->getParameterFact(FactSystem::defaultComponentId, "RC_MAP_THROTTLE")->setRawValue(paramValue); + qgcApp()->toolbox()->multiVehicleManager()->activeVehicle()->getParameterFact(FactSystem::defaultComponentId, "RC_MAP_THROTTLE")->setRawValue(paramValue); QTest::qWait(500); // Let the signals flow through diff --git a/src/FirmwarePlugin/APM/ArduCopterFirmwarePlugin.cc b/src/FirmwarePlugin/APM/ArduCopterFirmwarePlugin.cc index a1cf9da..c2c3dca 100644 --- a/src/FirmwarePlugin/APM/ArduCopterFirmwarePlugin.cc +++ b/src/FirmwarePlugin/APM/ArduCopterFirmwarePlugin.cc @@ -210,7 +210,7 @@ bool ArduCopterFirmwarePlugin::multiRotorCoaxialMotors(Vehicle* vehicle) bool ArduCopterFirmwarePlugin::multiRotorXConfig(Vehicle* vehicle) { - return vehicle->autopilotPlugin()->getParameterFact(FactSystem::defaultComponentId, "FRAME")->rawValue().toInt() != 0; + return vehicle->getParameterFact(FactSystem::defaultComponentId, "FRAME")->rawValue().toInt() != 0; } QString ArduCopterFirmwarePlugin::geoFenceRadiusParam(Vehicle* vehicle) diff --git a/src/FlightMap/Widgets/ValuesWidget.qml b/src/FlightMap/Widgets/ValuesWidget.qml index 74d7f76..e4ba42b 100644 --- a/src/FlightMap/Widgets/ValuesWidget.qml +++ b/src/FlightMap/Widgets/ValuesWidget.qml @@ -30,7 +30,7 @@ QGCFlickable { property color textColor property var maxHeight - property var _activeVehicle: QGroundControl.multiVehicleManager.activeVehicle ? QGroundControl.multiVehicleManager.activeVehicle : QGroundControl.multiVehicleManager.disconnectedVehicle + property var _activeVehicle: QGroundControl.multiVehicleManager.activeVehicle ? QGroundControl.multiVehicleManager.activeVehicle : QGroundControl.multiVehicleManager.offlineEditingVehicle property real _margins: ScreenTools.defaultFontPixelWidth / 2 QGCPalette { id:qgcPal; colorGroupEnabled: true } diff --git a/src/FlightMap/Widgets/VibrationWidget.qml b/src/FlightMap/Widgets/VibrationWidget.qml index 0fc1a39..96cba71 100644 --- a/src/FlightMap/Widgets/VibrationWidget.qml +++ b/src/FlightMap/Widgets/VibrationWidget.qml @@ -29,7 +29,7 @@ QGCFlickable { property color backgroundColor property var maxHeight - property var _activeVehicle: QGroundControl.multiVehicleManager.activeVehicle ? QGroundControl.multiVehicleManager.activeVehicle : QGroundControl.multiVehicleManager.disconnectedVehicle + property var _activeVehicle: QGroundControl.multiVehicleManager.activeVehicle ? QGroundControl.multiVehicleManager.activeVehicle : QGroundControl.multiVehicleManager.offlineEditingVehicle property real _margins: ScreenTools.defaultFontPixelWidth / 2 property real _barWidth: Math.round(ScreenTools.defaultFontPixelWidth * 3) diff --git a/src/QmlControls/ParameterEditorController.cc b/src/QmlControls/ParameterEditorController.cc index 84764bd..88627dc 100644 --- a/src/QmlControls/ParameterEditorController.cc +++ b/src/QmlControls/ParameterEditorController.cc @@ -68,7 +68,7 @@ QStringList ParameterEditorController::searchParametersForComponent(int componen if (searchText.isEmpty()) { list += paramName; } else { - Fact* fact = _autopilot->getParameterFact(componentId, paramName); + Fact* fact = _vehicle->getParameterFact(componentId, paramName); if (searchInName && fact->name().contains(searchText, Qt::CaseInsensitive)) { list += paramName; @@ -189,11 +189,11 @@ void ParameterEditorController::_updateParameters(void) if (_searchText.isEmpty()) { const QMap >& groupMap = _autopilot->getGroupMap(); foreach (const QString& parameter, groupMap[_currentComponentId][_currentGroup]) { - newParameterList.append(_autopilot->getParameterFact(_currentComponentId, parameter)); + newParameterList.append(_vehicle->getParameterFact(_currentComponentId, parameter)); } } else { foreach(const QString ¶meter, _autopilot->parameterNames(_vehicle->defaultComponentId())) { - Fact* fact = _autopilot->getParameterFact(_vehicle->defaultComponentId(), parameter); + Fact* fact = _vehicle->getParameterFact(_vehicle->defaultComponentId(), parameter); if (fact->name().contains(_searchText, Qt::CaseInsensitive) || fact->shortDescription().contains(_searchText, Qt::CaseInsensitive) || fact->longDescription().contains(_searchText, Qt::CaseInsensitive)) { diff --git a/src/VehicleSetup/VehicleComponent.cc b/src/VehicleSetup/VehicleComponent.cc index ef4fb23..b68aff9 100644 --- a/src/VehicleSetup/VehicleComponent.cc +++ b/src/VehicleSetup/VehicleComponent.cc @@ -49,8 +49,8 @@ void VehicleComponent::setupTriggerSignals(void) { // Watch for changed on trigger list params foreach (const QString ¶mName, setupCompleteChangedTriggerList()) { - if (_autopilot->parameterExists(FactSystem::defaultComponentId, paramName)) { - Fact* fact = _autopilot->getParameterFact(FactSystem::defaultComponentId, paramName); + if (_vehicle->parameterExists(FactSystem::defaultComponentId, paramName)) { + Fact* fact = _vehicle->getParameterFact(FactSystem::defaultComponentId, paramName); connect(fact, &Fact::valueChanged, this, &VehicleComponent::_triggerUpdated); } } diff --git a/src/qgcunittest/RadioConfigTest.cc b/src/qgcunittest/RadioConfigTest.cc index edcf97f..6c2d40f 100644 --- a/src/qgcunittest/RadioConfigTest.cc +++ b/src/qgcunittest/RadioConfigTest.cc @@ -378,7 +378,7 @@ void RadioConfigTest::_fullCalibrationWorker(MAV_AUTOPILOT firmwareType) switchList << "RC_MAP_MODE_SW" << "RC_MAP_LOITER_SW" << "RC_MAP_RETURN_SW" << "RC_MAP_POSCTL_SW" << "RC_MAP_ACRO_SW"; foreach (const QString &switchParam, switchList) { - Q_ASSERT(_autopilot->getParameterFact(FactSystem::defaultComponentId, switchParam)->rawValue().toInt() != channel + 1); + Q_ASSERT(_vehicle->getParameterFact(FactSystem::defaultComponentId, switchParam)->rawValue().toInt() != channel + 1); } } @@ -393,7 +393,7 @@ void RadioConfigTest::_fullCalibrationWorker(MAV_AUTOPILOT firmwareType) if (!found) { const char* paramName = _functionInfo()[function].parameterName; if (paramName) { - _rgFunctionChannelMap[function] = _autopilot->getParameterFact(FactSystem::defaultComponentId, paramName)->rawValue().toInt(); + _rgFunctionChannelMap[function] = _vehicle->getParameterFact(FactSystem::defaultComponentId, paramName)->rawValue().toInt(); qCDebug(RadioConfigTestLog) << "Assigning switch" << function << _rgFunctionChannelMap[function]; if (_rgFunctionChannelMap[function] == 0) { _rgFunctionChannelMap[function] = -1; // -1 signals no mapping @@ -469,8 +469,8 @@ void RadioConfigTest::_validateParameters(void) const char* paramName = _functionInfo()[chanFunction].parameterName; if (paramName) { - qCDebug(RadioConfigTestLog) << "Validate" << chanFunction << _autopilot->getParameterFact(FactSystem::defaultComponentId, paramName)->rawValue().toInt(); - QCOMPARE(_autopilot->getParameterFact(FactSystem::defaultComponentId, paramName)->rawValue().toInt(), expectedParameterValue); + qCDebug(RadioConfigTestLog) << "Validate" << chanFunction << _vehicle->getParameterFact(FactSystem::defaultComponentId, paramName)->rawValue().toInt(); + QCOMPARE(_vehicle->getParameterFact(FactSystem::defaultComponentId, paramName)->rawValue().toInt(), expectedParameterValue); } } @@ -485,13 +485,13 @@ void RadioConfigTest::_validateParameters(void) int rcTrimExpected = _channelSettingsValidate()[chan].rcTrim; bool rcReversedExpected = _channelSettingsValidate()[chan].reversed; - int rcMinActual = _autopilot->getParameterFact(FactSystem::defaultComponentId, minTpl.arg(oneBasedChannel))->rawValue().toInt(&convertOk); + int rcMinActual = _vehicle->getParameterFact(FactSystem::defaultComponentId, minTpl.arg(oneBasedChannel))->rawValue().toInt(&convertOk); QCOMPARE(convertOk, true); - int rcMaxActual = _autopilot->getParameterFact(FactSystem::defaultComponentId, maxTpl.arg(oneBasedChannel))->rawValue().toInt(&convertOk); + int rcMaxActual = _vehicle->getParameterFact(FactSystem::defaultComponentId, maxTpl.arg(oneBasedChannel))->rawValue().toInt(&convertOk); QCOMPARE(convertOk, true); - int rcTrimActual = _autopilot->getParameterFact(FactSystem::defaultComponentId, trimTpl.arg(oneBasedChannel))->rawValue().toInt(&convertOk); + int rcTrimActual = _vehicle->getParameterFact(FactSystem::defaultComponentId, trimTpl.arg(oneBasedChannel))->rawValue().toInt(&convertOk); QCOMPARE(convertOk, true); - float rcReversedFloat = _autopilot->getParameterFact(FactSystem::defaultComponentId, revTpl.arg(oneBasedChannel))->rawValue().toFloat(&convertOk); + float rcReversedFloat = _vehicle->getParameterFact(FactSystem::defaultComponentId, revTpl.arg(oneBasedChannel))->rawValue().toFloat(&convertOk); QCOMPARE(convertOk, true); bool rcReversedActual = (rcReversedFloat == -1.0f); @@ -515,7 +515,7 @@ void RadioConfigTest::_validateParameters(void) const char* paramName = _functionInfo()[chanFunction].parameterName; if (paramName) { // qCDebug(RadioConfigTestLog) << chanFunction << expectedValue << mapParamsSet[paramName].toInt(); - QCOMPARE(_autopilot->getParameterFact(FactSystem::defaultComponentId, paramName)->rawValue().toInt(), expectedValue); + QCOMPARE(_vehicle->getParameterFact(FactSystem::defaultComponentId, paramName)->rawValue().toInt(), expectedValue); } } } diff --git a/src/ui/QGCMapRCToParamDialog.cpp b/src/ui/QGCMapRCToParamDialog.cpp index 453ec8d..97fa8d0 100644 --- a/src/ui/QGCMapRCToParamDialog.cpp +++ b/src/ui/QGCMapRCToParamDialog.cpp @@ -30,9 +30,8 @@ QGCMapRCToParamDialog::QGCMapRCToParamDialog(QString param_id, UASInterface *mav ui->setupUi(this); // refresh the parameter from onboard to make sure the current value is used - AutoPilotPlugin* autopilot = _multiVehicleManager->getVehicleById(mav->getUASID())->autopilotPlugin(); - Q_ASSERT(autopilot); - Fact* paramFact = autopilot->getParameterFact(FactSystem::defaultComponentId, param_id); + Vehicle* vehicle = _multiVehicleManager->getVehicleById(mav->getUASID()); + Fact* paramFact = vehicle->getParameterFact(FactSystem::defaultComponentId, param_id); ui->minValueDoubleSpinBox->setValue(paramFact->rawMin().toDouble()); ui->maxValueDoubleSpinBox->setValue(paramFact->rawMax().toDouble()); @@ -44,7 +43,7 @@ QGCMapRCToParamDialog::QGCMapRCToParamDialog(QString param_id, UASInterface *mav ui->paramIdLabel->setText(param_id); connect(paramFact, &Fact::valueChanged, this, &QGCMapRCToParamDialog::_parameterUpdated); - autopilot->refreshParameter(FactSystem::defaultComponentId, param_id); + vehicle->autopilotPlugin()->refreshParameter(FactSystem::defaultComponentId, param_id); } QGCMapRCToParamDialog::~QGCMapRCToParamDialog()