Commit 8b6aa1ed authored by Don Gagne's avatar Don Gagne

Merge pull request #1293 from DonLakeFlyer/RadioCalTrigger

Update Radio Cal trigger
parents 677fff3e 10b60459
......@@ -27,9 +27,6 @@
#include "AirframeComponent.h"
#include "QGCPX4AirframeConfig.h"
/// @brief Parameters which signal a change in setupComplete state
static const char* triggerParams[] = { "SYS_AUTOSTART", NULL };
#if 0
// Broken by latest mavlink module changes. Not used yet. Comment out for now.
// Discussing mavlink fix.
......@@ -146,7 +143,7 @@ bool AirframeComponent::requiresSetup(void) const
bool AirframeComponent::setupComplete(void) const
{
QVariant value;
if (_paramMgr->getParameterValue(_paramMgr->getDefaultComponentId(), triggerParams[0], value)) {
if (_paramMgr->getParameterValue(_paramMgr->getDefaultComponentId(), "SYS_AUTOSTART", value)) {
return value.toInt() != 0;
} else {
Q_ASSERT(false);
......@@ -166,9 +163,9 @@ QString AirframeComponent::setupStateDescription(void) const
return QString(stateDescription);
}
const char** AirframeComponent::setupCompleteChangedTriggerList(void) const
QStringList AirframeComponent::setupCompleteChangedTriggerList(void) const
{
return triggerParams;
return QStringList("SYS_AUTOSTART");
}
QStringList AirframeComponent::paramFilterList(void) const
......
......@@ -38,7 +38,7 @@ public:
AirframeComponent(UASInterface* uas, AutoPilotPlugin* autopilot, QObject* parent = NULL);
// Virtuals from PX4Component
virtual const char** setupCompleteChangedTriggerList(void) const;
virtual QStringList setupCompleteChangedTriggerList(void) const;
// Virtuals from VehicleComponent
virtual QString name(void) const;
......
......@@ -28,9 +28,6 @@
#include "FlightModeConfig.h"
#include "PX4AutoPilotPlugin.h"
/// @brief Parameters which signal a change in setupComplete state
static const char* triggerParams[] = { "RC_MAP_MODE_SW", NULL };
struct SwitchListItem {
const char* param;
const char* name;
......@@ -76,7 +73,7 @@ bool FlightModesComponent::requiresSetup(void) const
bool FlightModesComponent::setupComplete(void) const
{
QVariant value;
if (_paramMgr->getParameterValue(_paramMgr->getDefaultComponentId(), triggerParams[0], value)) {
if (_paramMgr->getParameterValue(_paramMgr->getDefaultComponentId(), "RC_MAP_MODE_SW", value)) {
return value.toInt() != 0;
} else {
Q_ASSERT(false);
......@@ -96,9 +93,9 @@ QString FlightModesComponent::setupStateDescription(void) const
return QString(stateDescription);
}
const char** FlightModesComponent::setupCompleteChangedTriggerList(void) const
QStringList FlightModesComponent::setupCompleteChangedTriggerList(void) const
{
return triggerParams;
return QStringList("RC_MAP_MODE_SW");
}
QStringList FlightModesComponent::paramFilterList(void) const
......
......@@ -38,7 +38,7 @@ public:
FlightModesComponent(UASInterface* uas, AutoPilotPlugin* autopilot, QObject* parent = NULL);
// Virtuals from PX4Component
virtual const char** setupCompleteChangedTriggerList(void) const;
virtual QStringList setupCompleteChangedTriggerList(void) const;
// Virtuals from VehicleComponent
virtual QString name(void) const;
......
......@@ -27,7 +27,7 @@ Column {
QGCLabel {
horizontalAlignment: Text.AlignRight
width: parent.width - posctl.contentWidth
text: autopilot.parameters["RC_MAP_POSCTL_SW"].value == 0 ? "Not mapped" : autopilot.parameters["RC_MAP_POSCTL_SW"].value
text: autopilot.parameters["RC_MAP_POSCTL_SW"].value == 0 ? "Disabled" : autopilot.parameters["RC_MAP_POSCTL_SW"].value
}
}
......@@ -38,7 +38,7 @@ Column {
QGCLabel {
horizontalAlignment: Text.AlignRight
width: parent.width - loiter.contentWidth
text: autopilot.parameters["RC_MAP_LOITER_SW"].value == 0 ? "Not mapped" : autopilot.parameters["RC_MAP_LOITER_SW"].value
text: autopilot.parameters["RC_MAP_LOITER_SW"].value == 0 ? "Disabled" : autopilot.parameters["RC_MAP_LOITER_SW"].value
}
}
......@@ -49,7 +49,7 @@ Column {
QGCLabel {
horizontalAlignment: Text.AlignRight
width: parent.width - rtl.contentWidth
text: autopilot.parameters["RC_MAP_RETURN_SW"].value == 0 ? "Not mapped" : autopilot.parameters["RC_MAP_RETURN_SW"].value
text: autopilot.parameters["RC_MAP_RETURN_SW"].value == 0 ? "Disabled" : autopilot.parameters["RC_MAP_RETURN_SW"].value
}
}
}
......@@ -39,15 +39,12 @@ void PX4Component::_parameterUpdated(int compId, QString paramName, QVariant val
Q_UNUSED(value);
if (compId == _paramMgr->getDefaultComponentId()) {
const char** prgTriggers = setupCompleteChangedTriggerList();
Q_ASSERT(prgTriggers);
while (*prgTriggers != NULL) {
if (paramName == *prgTriggers) {
QStringList triggerList = setupCompleteChangedTriggerList();
foreach(QString triggerParam, triggerList) {
if (paramName == triggerParam) {
emit setupCompleteChanged(setupComplete());
return;
}
prgTriggers++;
}
}
}
......@@ -26,6 +26,8 @@
#include "VehicleComponent.h"
#include <QStringList>
/// @file
/// @brief This class is used as an abstract base class for all PX4 VehicleComponent objects.
/// @author Don Gagne <don@thegagnes.com>
......@@ -37,9 +39,9 @@ class PX4Component : public VehicleComponent
public:
PX4Component(UASInterface* uas, AutoPilotPlugin* autopilot, QObject* parent = NULL);
/// @brief Returns an array of parameter names for which a change should cause the setupCompleteChanged
/// signal to be emitted. Last element is signalled by NULL. Must be implemented by upper level class.
virtual const char** setupCompleteChangedTriggerList(void) const = 0;
/// @brief Returns an list of parameter names for which a change should cause the setupCompleteChanged
/// signal to be emitted. Last element is signalled by NULL.
virtual QStringList setupCompleteChangedTriggerList(void) const = 0;
private slots:
/// @brief Connected to QGCUASParamManagerInterface::parameterUpdated signal in order to signal
......
......@@ -28,9 +28,6 @@
#include "PX4RCCalibration.h"
#include "PX4AutoPilotPlugin.h"
/// @brief Parameters which signal a change in setupComplete state
static const char* triggerParams[] = { "RC_MAP_ROLL", "RC_MAP_PITCH", "RC_MAP_YAW", "RC_MAP_THROTTLE", NULL };
RadioComponent::RadioComponent(UASInterface* uas, AutoPilotPlugin* autopilot, QObject* parent) :
PX4Component(uas, autopilot, parent),
_name(tr("Radio"))
......@@ -61,9 +58,12 @@ bool RadioComponent::requiresSetup(void) const
bool RadioComponent::setupComplete(void) const
{
for (size_t i=0; triggerParams[i] != NULL; i++) {
// Check for mapped attitude controls
QStringList attitudeMappings;
attitudeMappings << "RC_MAP_ROLL" << "RC_MAP_PITCH" << "RC_MAP_YAW" << "RC_MAP_THROTTLE";
foreach(QString mapParam, attitudeMappings) {
QVariant value;
if (_paramMgr->getParameterValue(_paramMgr->getDefaultComponentId(), triggerParams[0], value)) {
if (_paramMgr->getParameterValue(_paramMgr->getDefaultComponentId(), mapParam, value)) {
if (value.toInt() == 0) {
return false;
}
......@@ -73,6 +73,47 @@ bool RadioComponent::setupComplete(void) const
}
}
// Check for min/max/trim defaults for channel 1-4
static const int rcMinDefault = 1000;
static const int rcMaxDefault = 2000;
static const int rcTrimDefault = 1500;
for (int i=1; i<5; i++) {
QVariant value;
int rcMin, rcMax, rcTrim;
QString param;
param = QString("RC%1_MIN").arg(i);
if (_paramMgr->getParameterValue(_paramMgr->getDefaultComponentId(), param, value)) {
rcMin = value.toInt();
} else {
Q_ASSERT(false);
return false;
}
param = QString("RC%1_MAX").arg(i);
if (_paramMgr->getParameterValue(_paramMgr->getDefaultComponentId(), param, value)) {
rcMax = value.toInt();
} else {
Q_ASSERT(false);
return false;
}
param = QString("RC%1_TRIM").arg(i);
if (_paramMgr->getParameterValue(_paramMgr->getDefaultComponentId(), param, value)) {
rcTrim = value.toInt();
} else {
Q_ASSERT(false);
return false;
}
if (rcMin == rcMinDefault && rcMax == rcMaxDefault && rcTrim == rcTrimDefault) {
return false;
}
}
return true;
}
......@@ -88,9 +129,25 @@ QString RadioComponent::setupStateDescription(void) const
return QString(stateDescription);
}
const char** RadioComponent::setupCompleteChangedTriggerList(void) const
QStringList RadioComponent::setupCompleteChangedTriggerList(void) const
{
return triggerParams;
QStringList triggers;
// The best we can do to detect the need for a radio calibration is look for trim/min/max still being
// at defaults. We also look for attitude controls to be mapped. But since they default to channels
// they are not a very reliable source.
// Attitude control mapping is always a trigger
triggers << "RC_MAP_ROLL" << "RC_MAP_PITCH" << "RC_MAP_YAW" << "RC_MAP_THROTTLE";
// We also trigger on min/max/trim for channels 1-4 which would normally be the attitude
// control channels. This may not always be the case, but it's the best we can
triggers << "RC1_MIN" << "RC1_MAX" << "RC1_TRIM";
triggers << "RC2_MIN" << "RC2_MAX" << "RC2_TRIM";
triggers << "RC3_MIN" << "RC3_MAX" << "RC3_TRIM";
triggers << "RC4_MIN" << "RC4_MAX" << "RC4_TRIM";
return triggers;
}
QStringList RadioComponent::paramFilterList(void) const
......
......@@ -39,7 +39,7 @@ public:
RadioComponent(UASInterface* uas, AutoPilotPlugin* autopilot, QObject* parent = NULL);
// Virtuals from PX4Component
virtual const char** setupCompleteChangedTriggerList(void) const;
virtual QStringList setupCompleteChangedTriggerList(void) const;
// Virtuals from VehicleComponent
virtual QString name(void) const;
......
......@@ -56,11 +56,33 @@ Column {
Row {
width: parent.width
QGCLabel { id: mode; text: "Mode switch:" }
QGCLabel { id: flaps; text: "Flaps:" }
QGCLabel {
horizontalAlignment: Text.AlignRight
width: parent.width - mode.contentWidth
text: autopilot.parameters["RC_MAP_MODE_SW"].value == 0 ? "Setup required" : autopilot.parameters["RC_MAP_MODE_SW"].value
width: parent.width - flaps.contentWidth
text: autopilot.parameters["RC_MAP_FLAPS"].value == 0 ? "Disabled" : autopilot.parameters["RC_MAP_FLAPS"].value
}
}
Row {
width: parent.width
QGCLabel { id: aux1; text: "Aux1:" }
QGCLabel {
horizontalAlignment: Text.AlignRight
width: parent.width - aux1.contentWidth
text: autopilot.parameters["RC_MAP_AUX1"].value == 0 ? "Disabled" : autopilot.parameters["RC_MAP_AUX1"].value
}
}
Row {
width: parent.width
QGCLabel { id: aux2; text: "Aux2:" }
QGCLabel {
horizontalAlignment: Text.AlignRight
width: parent.width - aux2.contentWidth
text: autopilot.parameters["RC_MAP_AUX2"].value == 0 ? "Disabled" : autopilot.parameters["RC_MAP_AUX2"].value
}
}
}
......@@ -29,9 +29,6 @@
#include "QGCQmlWidgetHolder.h"
#include "PX4AutoPilotPlugin.h"
/// @brief Parameters which signal a change in setupComplete state
static const char* triggerParams[] = { NULL };
SafetyComponent::SafetyComponent(UASInterface* uas, AutoPilotPlugin* autopilot, QObject* parent) :
PX4Component(uas, autopilot, parent),
_name(tr("Safety"))
......@@ -76,9 +73,9 @@ QString SafetyComponent::setupStateDescription(void) const
return QString(stateDescription);
}
const char** SafetyComponent::setupCompleteChangedTriggerList(void) const
QStringList SafetyComponent::setupCompleteChangedTriggerList(void) const
{
return triggerParams;
return QStringList();
}
QStringList SafetyComponent::paramFilterList(void) const
......
......@@ -39,7 +39,7 @@ public:
SafetyComponent(UASInterface* uas, AutoPilotPlugin* autopilot, QObject* parent = NULL);
// Virtuals from PX4Component
virtual const char** setupCompleteChangedTriggerList(void) const;
virtual QStringList setupCompleteChangedTriggerList(void) const;
// Virtuals from VehicleComponent
virtual QString name(void) const;
......
......@@ -31,10 +31,6 @@
// These two list must be kept in sync
/// @brief Parameters which signal a change in setupComplete state
static const char* triggerParams[] = { "CAL_MAG0_ID", "CAL_GYRO0_ID", "CAL_ACC0_ID", NULL };
static const char* triggerParamsFixedWing[] = { "CAL_MAG0_ID", "CAL_GYRO0_ID", "CAL_ACC0_ID", "SENS_DPRES_OFF", NULL };
SensorsComponent::SensorsComponent(UASInterface* uas, AutoPilotPlugin* autopilot, QObject* parent) :
PX4Component(uas, autopilot, parent),
_name(tr("Sensors"))
......@@ -65,13 +61,10 @@ bool SensorsComponent::requiresSetup(void) const
bool SensorsComponent::setupComplete(void) const
{
const char** prgTriggers = setupCompleteChangedTriggerList();
Q_ASSERT(prgTriggers);
while (*prgTriggers != NULL) {
foreach(QString triggerParam, setupCompleteChangedTriggerList()) {
QVariant value;
if (!_paramMgr->getParameterValue(_paramMgr->getDefaultComponentId(), *prgTriggers, value)) {
if (!_paramMgr->getParameterValue(_paramMgr->getDefaultComponentId(), triggerParam, value)) {
Q_ASSERT(false);
return false;
}
......@@ -79,8 +72,6 @@ bool SensorsComponent::setupComplete(void) const
if (value.toFloat() == 0.0f) {
return false;
}
prgTriggers++;
}
return true;
......@@ -98,9 +89,16 @@ QString SensorsComponent::setupStateDescription(void) const
return QString(stateDescription);
}
const char** SensorsComponent::setupCompleteChangedTriggerList(void) const
QStringList SensorsComponent::setupCompleteChangedTriggerList(void) const
{
return _uas->getSystemType() == MAV_TYPE_FIXED_WING ? triggerParamsFixedWing : triggerParams;
QStringList triggers;
triggers << "CAL_MAG0_ID" << "CAL_GYRO0_ID" << "CAL_ACC0_ID";
if (_uas->getSystemType() == MAV_TYPE_FIXED_WING) {
triggers << "SENS_DPRES_OFF";
}
return triggers;
}
QStringList SensorsComponent::paramFilterList(void) const
......
......@@ -38,7 +38,7 @@ public:
SensorsComponent(UASInterface* uas, AutoPilotPlugin* autopilot, QObject* parent = NULL);
// Virtuals from PX4Component
virtual const char** setupCompleteChangedTriggerList(void) const;
virtual QStringList setupCompleteChangedTriggerList(void) const;
// Virtuals from VehicleComponent
virtual QString name(void) const;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment