diff --git a/src/AutoPilotPlugins/APM/APMRadioComponent.cc b/src/AutoPilotPlugins/APM/APMRadioComponent.cc index d7338294117d9740f7720866138efe5f2da507f5..52421d5632b39cb0677b80325bbd946a10a05dcb 100644 --- a/src/AutoPilotPlugins/APM/APMRadioComponent.cc +++ b/src/AutoPilotPlugins/APM/APMRadioComponent.cc @@ -29,6 +29,14 @@ APMRadioComponent::APMRadioComponent(Vehicle* vehicle, AutoPilotPlugin* autopilo APMComponent(vehicle, autopilot, parent), _name(tr("Radio")) { + _mapParams << QStringLiteral("RCMAP_ROLL") << QStringLiteral("RCMAP_PITCH") << QStringLiteral("RCMAP_YAW") << QStringLiteral("RCMAP_THROTTLE"); + + foreach (const QString& mapParam, _mapParams) { + Fact* fact = _autopilot->getParameterFact(-1, mapParam); + connect(fact, &Fact::valueChanged, this, &APMRadioComponent::_triggerChanged); + } + + _connectSetupTriggers(); } QString APMRadioComponent::name(void) const @@ -56,25 +64,38 @@ bool APMRadioComponent::requiresSetup(void) const bool APMRadioComponent::setupComplete(void) const { // The best we can do to detect the need for a radio calibration is look for attitude - // controls to be mapped. - QStringList attitudeMappings; - attitudeMappings << "RCMAP_ROLL" << "RCMAP_PITCH" << "RCMAP_YAW" << "RCMAP_THROTTLE"; - foreach(const QString &mapParam, attitudeMappings) { - if (_autopilot->getParameterFact(FactSystem::defaultComponentId, mapParam)->rawValue().toInt() == 0) { + // controls to be mapped as well as all attitude control rc min/max/trim still at defaults. + QList mapValues; + + // First check for all attitude controls mapped + for (int i=0; i<_mapParams.count(); i++) { + mapValues << _autopilot->getParameterFact(FactSystem::defaultComponentId, _mapParams[i])->rawValue().toInt(); + if (mapValues[i] <= 0) { return false; } } + + // 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) { + return true; + } + if (_autopilot->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) { + return true; + } + } - return true; + return false; } QStringList APMRadioComponent::setupCompleteChangedTriggerList(void) const { - QStringList triggers; - - triggers << "RCMAP_ROLL" << "RCMAP_PITCH" << "RCMAP_YAW" << "RCMAP_THROTTLE"; - - return triggers; + // APMRadioComponent manages it's own triggers + return QStringList(); } QUrl APMRadioComponent::setupSource(void) const @@ -93,8 +114,41 @@ QString APMRadioComponent::prerequisiteSetup(void) const if (!plugin->airframeComponent()->setupComplete()) { return plugin->airframeComponent()->name(); - } return QString(); } + +void APMRadioComponent::_connectSetupTriggers(void) +{ + // Disconnect previous triggers + foreach(Fact* fact, _triggerFacts) { + disconnect(fact, &Fact::valueChanged, this, &APMRadioComponent::_triggerChanged); + } + _triggerFacts.clear(); + + // 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(); + + Fact* fact = _autopilot->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)); + _triggerFacts << fact; + connect(fact, &Fact::valueChanged, this, &APMRadioComponent::_triggerChanged); + + fact = _autopilot->getParameterFact(-1, QString("RC%1_TRIM").arg(channel)); + _triggerFacts << fact; + connect(fact, &Fact::valueChanged, this, &APMRadioComponent::_triggerChanged); + } +} + +void APMRadioComponent::_triggerChanged(void) +{ + emit setupCompleteChanged(setupComplete()); + + // Control mapping may have changed so we need to reset triggers + _connectSetupTriggers(); +} diff --git a/src/AutoPilotPlugins/APM/APMRadioComponent.h b/src/AutoPilotPlugins/APM/APMRadioComponent.h index 0a179430d8d4af92960d247a5ddb6d55be091160..3724f88d3c8dfc0e6b3c5e0a6f3a8f7c63a3ad44 100644 --- a/src/AutoPilotPlugins/APM/APMRadioComponent.h +++ b/src/AutoPilotPlugins/APM/APMRadioComponent.h @@ -25,6 +25,7 @@ #define APMRadioComponent_H #include "APMComponent.h" +#include "Fact.h" class APMRadioComponent : public APMComponent { @@ -45,10 +46,16 @@ public: virtual QUrl setupSource(void) const; virtual QUrl summaryQmlSource(void) const; virtual QString prerequisiteSetup(void) const; + +private slots: + void _triggerChanged(void); private: + void _connectSetupTriggers(void); + const QString _name; - QVariantList _summaryItems; + QStringList _mapParams; + QList _triggerFacts; }; #endif diff --git a/src/comm/APMArduCopterMockLink.params b/src/comm/APMArduCopterMockLink.params index ec18defe9243a4f7b3c341dc30f6a33ca3bb823e..efd9b002e0895673f697e0f531f1a4ea48fa3135 100644 --- a/src/comm/APMArduCopterMockLink.params +++ b/src/comm/APMArduCopterMockLink.params @@ -331,7 +331,7 @@ 1 1 RC14_TRIM 1500 4 1 1 RC1_DZ 30 4 1 1 RC1_MAX 1900 4 -1 1 RC1_MIN 1100 4 +1 1 RC1_MIN 1101 4 1 1 RC1_REV 1 2 1 1 RC1_TRIM 1500 4 1 1 RC2_DZ 30 4 diff --git a/src/comm/APMArduPlaneMockLink.params b/src/comm/APMArduPlaneMockLink.params index 4eb713d18851df6c6b791d8175f8d5ee9c4353b3..baa098a3d0b1e109bc90edee5724390702451368 100644 --- a/src/comm/APMArduPlaneMockLink.params +++ b/src/comm/APMArduPlaneMockLink.params @@ -366,7 +366,7 @@ 1 1 RC14_TRIM 1500 4 1 1 RC1_DZ 30 4 1 1 RC1_MAX 1900 4 -1 1 RC1_MIN 1100 4 +1 1 RC1_MIN 1101 4 1 1 RC1_REV 1 2 1 1 RC1_TRIM 1500 4 1 1 RC2_DZ 30 4