Commit 74e57ec4 authored by Don Gagne's avatar Don Gagne

Add default value support

Also friendly editor for MAV_CMD_NAV_ROI and MAV_CMD_DO_SET_SERVO
parent 9bb8f7e7
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
"param1": { "param1": {
"label": "Hold:", "label": "Hold:",
"units": "seconds", "units": "seconds",
"default": 0,
"decimalPlaces": 0 "decimalPlaces": 0
} }
}, },
...@@ -34,6 +35,7 @@ ...@@ -34,6 +35,7 @@
"param3": { "param3": {
"label": "Radius:", "label": "Radius:",
"units": "meters", "units": "meters",
"default": 10.0,
"decimalPlaces": 2 "decimalPlaces": 2
} }
}, },
...@@ -46,11 +48,13 @@ ...@@ -46,11 +48,13 @@
"friendlyEdit": true, "friendlyEdit": true,
"param1": { "param1": {
"label": "Turns:", "label": "Turns:",
"default": 1,
"decimalPlaces": 0 "decimalPlaces": 0
}, },
"param3": { "param3": {
"label": "Radius:", "label": "Radius:",
"units": "meters", "units": "meters",
"default": 10.0,
"decimalPlaces": 2 "decimalPlaces": 2
} }
}, },
...@@ -64,11 +68,13 @@ ...@@ -64,11 +68,13 @@
"param1": { "param1": {
"label": "Hold:", "label": "Hold:",
"units": "seconds", "units": "seconds",
"default": 30,
"decimalPlaces": 0 "decimalPlaces": 0
}, },
"param3": { "param3": {
"label": "Radius:", "label": "Radius:",
"units": "meters", "units": "meters",
"default": 10.0,
"decimalPlaces": 2 "decimalPlaces": 2
} }
}, },
...@@ -89,11 +95,13 @@ ...@@ -89,11 +95,13 @@
"param1": { "param1": {
"label": "Abort Alt:", "label": "Abort Alt:",
"units": "meters", "units": "meters",
"default": 25.0,
"decimalPlaces": 3 "decimalPlaces": 3
}, },
"param4": { "param4": {
"label": "Heading:", "label": "Heading:",
"units": "degrees", "units": "degrees",
"default": 0.0,
"decimalPlaces": 2 "decimalPlaces": 2
} }
}, },
...@@ -107,11 +115,13 @@ ...@@ -107,11 +115,13 @@
"param1": { "param1": {
"label": "Pitch:", "label": "Pitch:",
"units": "degrees", "units": "degrees",
"default": 0.26179939,
"decimalPlaces": 2 "decimalPlaces": 2
}, },
"param4": { "param4": {
"label": "Heading:", "label": "Heading:",
"units": "degrees", "units": "degrees",
"default": 0.0,
"decimalPlaces": 2 "decimalPlaces": 2
} }
}, },
...@@ -120,7 +130,31 @@ ...@@ -120,7 +130,31 @@
{ "id": 25, "rawName": "MAV_CMD_NAV_FOLLOW", "friendlyName": "MAV_CMD_NAV_FOLLOW" }, { "id": 25, "rawName": "MAV_CMD_NAV_FOLLOW", "friendlyName": "MAV_CMD_NAV_FOLLOW" },
{ "id": 30, "rawName": "MAV_CMD_NAV_CONTINUE_AND_CHANGE_ALT", "friendlyName": "MAV_CMD_NAV_CONTINUE_AND_CHANGE_ALT" }, { "id": 30, "rawName": "MAV_CMD_NAV_CONTINUE_AND_CHANGE_ALT", "friendlyName": "MAV_CMD_NAV_CONTINUE_AND_CHANGE_ALT" },
{ "id": 31, "rawName": "MAV_CMD_NAV_LOITER_TO_ALT" }, { "id": 31, "rawName": "MAV_CMD_NAV_LOITER_TO_ALT" },
{ "id": 80, "rawName": "MAV_CMD_NAV_ROI", "friendlyName": "MAV_CMD_NAV_ROI" }, {
"id": 80,
"rawName": "MAV_CMD_NAV_ROI",
"friendlyName": "Region of interest",
"description": "Sets the region of interest for cameras.",
"specifiesCoordinate": true,
"friendlyEdit": true,
"param1": {
"label": "Mode:",
"enumStrings": "None,Next waypoint,Mission item,Location,ROI item",
"enumValues": "0,1,2,3,4",
"default": 3,
"decimalPlaces": 0
},
"param2": {
"label": "Mission Index:",
"default": 0,
"decimalPlaces": 0
},
"param3": {
"label": "ROI index:",
"default": 0,
"decimalPlaces": 0
}
},
{ "id": 81, "rawName": "MAV_CMD_NAV_PATHPLANNING", "friendlyName": "MAV_CMD_NAV_PATHPLANNING" }, { "id": 81, "rawName": "MAV_CMD_NAV_PATHPLANNING", "friendlyName": "MAV_CMD_NAV_PATHPLANNING" },
{ "id": 82, "rawName": "MAV_CMD_NAV_SPLINE_WAYPOINT", "friendlyName": "MAV_CMD_NAV_SPLINE_WAYPOINT" }, { "id": 82, "rawName": "MAV_CMD_NAV_SPLINE_WAYPOINT", "friendlyName": "MAV_CMD_NAV_SPLINE_WAYPOINT" },
{ "id": 83, "rawName": "MAV_CMD_NAV_ALTITUDE_WAIT", "friendlyName": "MAV_CMD_NAV_ALTITUDE_WAIT" }, { "id": 83, "rawName": "MAV_CMD_NAV_ALTITUDE_WAIT", "friendlyName": "MAV_CMD_NAV_ALTITUDE_WAIT" },
...@@ -134,6 +168,7 @@ ...@@ -134,6 +168,7 @@
"param1": { "param1": {
"label": "Hold:", "label": "Hold:",
"units": "seconds", "units": "seconds",
"default": 30,
"decimalPlaces": 0 "decimalPlaces": 0
} }
}, },
...@@ -149,11 +184,13 @@ ...@@ -149,11 +184,13 @@
"description": "Mission will continue at the specified item.", "description": "Mission will continue at the specified item.",
"friendlyEdit": true, "friendlyEdit": true,
"param1": { "param1": {
"label": "Seq #:", "label": "Item #:",
"default": 1,
"decimalPlaces": 0 "decimalPlaces": 0
}, },
"param2": { "param2": {
"label": "Repeat:", "label": "Repeat:",
"default": 0,
"decimalPlaces": 0 "decimalPlaces": 0
} }
}, },
...@@ -162,7 +199,23 @@ ...@@ -162,7 +199,23 @@
{ "id": 180, "rawName": "MAV_CMD_DO_SET_PARAMETER", "friendlyName": "MAV_CMD_DO_SET_PARAMETER" }, { "id": 180, "rawName": "MAV_CMD_DO_SET_PARAMETER", "friendlyName": "MAV_CMD_DO_SET_PARAMETER" },
{ "id": 181, "rawName": "MAV_CMD_DO_SET_RELAY", "friendlyName": "MAV_CMD_DO_SET_RELAY" }, { "id": 181, "rawName": "MAV_CMD_DO_SET_RELAY", "friendlyName": "MAV_CMD_DO_SET_RELAY" },
{ "id": 182, "rawName": "MAV_CMD_DO_REPEAT_RELAY", "friendlyName": "MAV_CMD_DO_REPEAT_RELAY" }, { "id": 182, "rawName": "MAV_CMD_DO_REPEAT_RELAY", "friendlyName": "MAV_CMD_DO_REPEAT_RELAY" },
{ "id": 183, "rawName": "MAV_CMD_DO_SET_SERVO", "friendlyName": "MAV_CMD_DO_SET_SERVO" }, {
"id": 183,
"rawName": "MAV_CMD_DO_SET_SERVO",
"friendlyName": "Set servo",
"description": "Set servo to specified PWM value.",
"friendlyEdit": true,
"param1": {
"label": "Servo:",
"default": 1,
"decimalPlaces": 0
},
"param2": {
"label": "PWM:",
"default": 1000,
"decimalPlaces": 0
}
},
{ "id": 184, "rawName": "MAV_CMD_DO_REPEAT_SERVO", "friendlyName": "MAV_CMD_DO_REPEAT_SERVO" }, { "id": 184, "rawName": "MAV_CMD_DO_REPEAT_SERVO", "friendlyName": "MAV_CMD_DO_REPEAT_SERVO" },
{ "id": 185, "rawName": "MAV_CMD_DO_FLIGHTTERMINATION", "friendlyName": "MAV_CMD_DO_FLIGHTTERMINATION" }, { "id": 185, "rawName": "MAV_CMD_DO_FLIGHTTERMINATION", "friendlyName": "MAV_CMD_DO_FLIGHTTERMINATION" },
{ "id": 189, "rawName": "MAV_CMD_DO_LAND_START", "friendlyName": "MAV_CMD_DO_LAND_START" }, { "id": 189, "rawName": "MAV_CMD_DO_LAND_START", "friendlyName": "MAV_CMD_DO_LAND_START" },
......
...@@ -47,6 +47,7 @@ FactMetaData* MissionItem::_longitudeMetaData = NULL; ...@@ -47,6 +47,7 @@ FactMetaData* MissionItem::_longitudeMetaData = NULL;
FactMetaData* MissionItem::_supportedCommandMetaData = NULL; FactMetaData* MissionItem::_supportedCommandMetaData = NULL;
const QString MissionItem::_decimalPlacesJsonKey (QStringLiteral("decimalPlaces")); const QString MissionItem::_decimalPlacesJsonKey (QStringLiteral("decimalPlaces"));
const QString MissionItem::_defaultJsonKey (QStringLiteral("default"));
const QString MissionItem::_descriptionJsonKey (QStringLiteral("description")); const QString MissionItem::_descriptionJsonKey (QStringLiteral("description"));
const QString MissionItem::_friendlyEditJsonKey (QStringLiteral("friendlyEdit")); const QString MissionItem::_friendlyEditJsonKey (QStringLiteral("friendlyEdit"));
const QString MissionItem::_friendlyNameJsonKey (QStringLiteral("friendlyName")); const QString MissionItem::_friendlyNameJsonKey (QStringLiteral("friendlyName"));
...@@ -246,8 +247,8 @@ void MissionItem::_connectSignals(void) ...@@ -246,8 +247,8 @@ void MissionItem::_connectSignals(void)
connect(&_param5Fact, &Fact::valueChanged, this, &MissionItem::_setDirtyFromSignal); connect(&_param5Fact, &Fact::valueChanged, this, &MissionItem::_setDirtyFromSignal);
connect(&_param6Fact, &Fact::valueChanged, this, &MissionItem::_setDirtyFromSignal); connect(&_param6Fact, &Fact::valueChanged, this, &MissionItem::_setDirtyFromSignal);
connect(&_param7Fact, &Fact::valueChanged, this, &MissionItem::_setDirtyFromSignal); connect(&_param7Fact, &Fact::valueChanged, this, &MissionItem::_setDirtyFromSignal);
connect(this, &MissionItem::commandChanged, this, &MissionItem::_setDirtyFromSignal); connect(&_frameFact, &Fact::valueChanged, this, &MissionItem::_setDirtyFromSignal);
connect(this, &MissionItem::frameChanged, this, &MissionItem::_setDirtyFromSignal); connect(&_commandFact, &Fact::valueChanged, this, &MissionItem::_setDirtyFromSignal);
connect(this, &MissionItem::sequenceNumberChanged, this, &MissionItem::_setDirtyFromSignal); connect(this, &MissionItem::sequenceNumberChanged, this, &MissionItem::_setDirtyFromSignal);
// Values from these facts must propogate back and forth between the real object storage // Values from these facts must propogate back and forth between the real object storage
...@@ -264,14 +265,18 @@ void MissionItem::_connectSignals(void) ...@@ -264,14 +265,18 @@ void MissionItem::_connectSignals(void)
// The following changes may also change friendlyEditAllowed // The following changes may also change friendlyEditAllowed
connect(&_autoContinueFact, &Fact::valueChanged, this, &MissionItem::_sendFriendlyEditAllowedChanged); connect(&_autoContinueFact, &Fact::valueChanged, this, &MissionItem::_sendFriendlyEditAllowedChanged);
connect(&_commandFact, &Fact::valueChanged, this, &MissionItem::_sendFriendlyEditAllowedChanged); connect(&_commandFact, &Fact::valueChanged, this, &MissionItem::_sendFriendlyEditAllowedChanged);
connect(this, &MissionItem::frameChanged, this, &MissionItem::_sendFriendlyEditAllowedChanged); connect(&_frameFact, &Fact::valueChanged, this, &MissionItem::_sendFriendlyEditAllowedChanged);
// Whenever these properties change the ui model changes as well // Whenever these properties change the ui model changes as well
connect(this, &MissionItem::commandChanged, this, &MissionItem::_sendUiModelChanged); connect(this, &MissionItem::commandChanged, this, &MissionItem::_sendUiModelChanged);
connect(this, &MissionItem::rawEditChanged, this, &MissionItem::_sendUiModelChanged); connect(this, &MissionItem::rawEditChanged, this, &MissionItem::_sendUiModelChanged);
// These fact signals must alway signal out through MissionItem signals
connect(&_commandFact, &Fact::valueChanged, this, &MissionItem::_sendCommandChanged); connect(&_commandFact, &Fact::valueChanged, this, &MissionItem::_sendCommandChanged);
connect(&_frameFact, &Fact::valueChanged, this, &MissionItem::_sendFrameChanged); connect(&_frameFact, &Fact::valueChanged, this, &MissionItem::_sendFrameChanged);
// When the command changes we need to set defaults
connect(&_commandFact, &Fact::valueChanged, this, &MissionItem::setDefaultsForCommand);
} }
bool MissionItem::_validateKeyTypes(QJsonObject& jsonObject, const QStringList& keys, const QList<QJsonValue::Type>& types) bool MissionItem::_validateKeyTypes(QJsonObject& jsonObject, const QStringList& keys, const QList<QJsonValue::Type>& types)
...@@ -376,8 +381,8 @@ bool MissionItem::_loadMavCmdInfoJson(void) ...@@ -376,8 +381,8 @@ bool MissionItem::_loadMavCmdInfoJson(void)
// Validate key types // Validate key types
QStringList keys; QStringList keys;
QList<QJsonValue::Type> types; QList<QJsonValue::Type> types;
keys << _labelJsonKey << _unitsJsonKey << _decimalPlacesJsonKey; keys << _labelJsonKey << _unitsJsonKey << _defaultJsonKey << _decimalPlacesJsonKey;
types << QJsonValue::String << QJsonValue::String<< QJsonValue::Double; types << QJsonValue::String << QJsonValue::String << QJsonValue::Double << QJsonValue::Double;
if (!_validateKeyTypes(paramObject, keys, types)) { if (!_validateKeyTypes(paramObject, keys, types)) {
return false; return false;
} }
...@@ -389,7 +394,9 @@ bool MissionItem::_loadMavCmdInfoJson(void) ...@@ -389,7 +394,9 @@ bool MissionItem::_loadMavCmdInfoJson(void)
return false; return false;
} }
_mavCmdInfoMap[mavCmdInfo.command].paramInfoMap[i].param = i;
_mavCmdInfoMap[mavCmdInfo.command].paramInfoMap[i].units = paramObject.value(_unitsJsonKey).toString(); _mavCmdInfoMap[mavCmdInfo.command].paramInfoMap[i].units = paramObject.value(_unitsJsonKey).toString();
_mavCmdInfoMap[mavCmdInfo.command].paramInfoMap[i].defaultValue = paramObject.value(_defaultJsonKey).toDouble(0.0);
_mavCmdInfoMap[mavCmdInfo.command].paramInfoMap[i].decimalPlaces = paramObject.value(_decimalPlacesJsonKey).toInt(FactMetaData::defaultDecimalPlaces); _mavCmdInfoMap[mavCmdInfo.command].paramInfoMap[i].decimalPlaces = paramObject.value(_decimalPlacesJsonKey).toInt(FactMetaData::defaultDecimalPlaces);
} }
} }
...@@ -519,6 +526,7 @@ void MissionItem::setCommand(MAV_CMD command) ...@@ -519,6 +526,7 @@ void MissionItem::setCommand(MAV_CMD command)
{ {
if ((MAV_CMD)this->command() != command) { if ((MAV_CMD)this->command() != command) {
_commandFact.setValue(command); _commandFact.setValue(command);
setDefaultsForCommand();
emit commandChanged(this->command()); emit commandChanged(this->command());
} }
} }
...@@ -533,6 +541,7 @@ void MissionItem::setFrame(MAV_FRAME frame) ...@@ -533,6 +541,7 @@ void MissionItem::setFrame(MAV_FRAME frame)
{ {
if (this->frame() != frame) { if (this->frame() != frame) {
_frameFact.setValue(frame); _frameFact.setValue(frame);
frameChanged(frame);
} }
} }
...@@ -837,7 +846,6 @@ void MissionItem::_syncSupportedCommandToCommand(const QVariant& value) ...@@ -837,7 +846,6 @@ void MissionItem::_syncSupportedCommandToCommand(const QVariant& value)
qDebug() << value.toInt(); qDebug() << value.toInt();
_syncingSupportedCommandAndCommand = true; _syncingSupportedCommandAndCommand = true;
_commandFact.setValue(value.toInt()); _commandFact.setValue(value.toInt());
qDebug() << _commandFact.value().toInt();
_syncingSupportedCommandAndCommand = false; _syncingSupportedCommandAndCommand = false;
} }
} }
...@@ -853,29 +861,29 @@ void MissionItem::_syncCommandToSupportedCommand(const QVariant& value) ...@@ -853,29 +861,29 @@ void MissionItem::_syncCommandToSupportedCommand(const QVariant& value)
void MissionItem::setDefaultsForCommand(void) void MissionItem::setDefaultsForCommand(void)
{ {
switch ((MAV_CMD)command()) { foreach (ParamInfo_t paramInfo, _mavCmdInfoMap[(MAV_CMD)command()].paramInfoMap) {
case MavlinkQmlSingleton::MAV_CMD_NAV_TAKEOFF: double defaultValue = paramInfo.defaultValue;
setParam1(_degreesToRadians(defaultTakeoffPitch).toDouble());
break; switch (paramInfo.param) {
case MavlinkQmlSingleton::MAV_CMD_NAV_WAYPOINT: case 1:
setParam2(defaultAcceptanceRadius); _param1Fact.setRawValue(defaultValue);
break; break;
case MavlinkQmlSingleton::MAV_CMD_NAV_LOITER_UNLIM: case 2:
case MavlinkQmlSingleton::MAV_CMD_NAV_LOITER_TIME: _param2Fact.setRawValue(defaultValue);
setParam3(defaultLoiterOrbitRadius);
break; break;
case MavlinkQmlSingleton::MAV_CMD_NAV_LOITER_TURNS: case 3:
setParam1(defaultLoiterTurns); _param3Fact.setRawValue(defaultValue);
setParam3(defaultLoiterOrbitRadius);
break; break;
default: case 4:
_param4Fact.setRawValue(defaultValue);
break; break;
} }
}
setParam4(_degreesToRadians(defaultHeading).toDouble());
setParam7(defaultAltitude); setParam7(defaultAltitude);
setAutoContinue(true);
setFrame(specifiesCoordinate() ? MAV_FRAME_GLOBAL_RELATIVE_ALT : MAV_FRAME_MISSION); setFrame(specifiesCoordinate() ? MAV_FRAME_GLOBAL_RELATIVE_ALT : MAV_FRAME_MISSION);
setRawEdit(false);
} }
void MissionItem::_sendUiModelChanged(void) void MissionItem::_sendUiModelChanged(void)
......
...@@ -93,8 +93,6 @@ public: ...@@ -93,8 +93,6 @@ public:
/// are shown next to the part item in the ui. /// are shown next to the part item in the ui.
Q_PROPERTY(QmlObjectListModel* childItems READ childItems CONSTANT) Q_PROPERTY(QmlObjectListModel* childItems READ childItems CONSTANT)
Q_INVOKABLE void setDefaultsForCommand(void);
// Property accesors // Property accesors
MavlinkQmlSingleton::Qml_MAV_CMD command(void) const { return (MavlinkQmlSingleton::Qml_MAV_CMD)_commandFact.value().toInt(); }; MavlinkQmlSingleton::Qml_MAV_CMD command(void) const { return (MavlinkQmlSingleton::Qml_MAV_CMD)_commandFact.value().toInt(); };
...@@ -172,6 +170,9 @@ public: ...@@ -172,6 +170,9 @@ public:
static const double defaultLoiterOrbitRadius; static const double defaultLoiterOrbitRadius;
static const double defaultLoiterTurns; static const double defaultLoiterTurns;
public slots:
void setDefaultsForCommand(void);
signals: signals:
void commandChanged (MavlinkQmlSingleton::Qml_MAV_CMD command); void commandChanged (MavlinkQmlSingleton::Qml_MAV_CMD command);
void coordinateChanged (const QGeoCoordinate& coordinate); void coordinateChanged (const QGeoCoordinate& coordinate);
...@@ -210,8 +211,10 @@ private: ...@@ -210,8 +211,10 @@ private:
private: private:
typedef struct { typedef struct {
int param;
QString label; QString label;
QString units; QString units;
double defaultValue;
int decimalPlaces; int decimalPlaces;
} ParamInfo_t; } ParamInfo_t;
...@@ -269,6 +272,7 @@ private: ...@@ -269,6 +272,7 @@ private:
static QMap<MAV_CMD, MavCmdInfo_t> _mavCmdInfoMap; static QMap<MAV_CMD, MavCmdInfo_t> _mavCmdInfoMap;
static const QString _decimalPlacesJsonKey; static const QString _decimalPlacesJsonKey;
static const QString _defaultJsonKey;
static const QString _descriptionJsonKey; static const QString _descriptionJsonKey;
static const QString _friendlyNameJsonKey; static const QString _friendlyNameJsonKey;
static const QString _friendlyEditJsonKey; static const QString _friendlyEditJsonKey;
......
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