From 8484008f50a3c76a7e46aa30237c0b7a7523e39c Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Sat, 27 Feb 2016 23:16:51 -0800 Subject: [PATCH] Add camera trigger support --- src/MissionEditor/SurveyItemEditor.qml | 30 +++++++++++ src/MissionManager/ComplexMissionItem.cc | 69 ++++++++++++++++++++---- src/MissionManager/ComplexMissionItem.h | 11 ++++ 3 files changed, 101 insertions(+), 9 deletions(-) diff --git a/src/MissionEditor/SurveyItemEditor.qml b/src/MissionEditor/SurveyItemEditor.qml index 141b59c21..39c629f06 100644 --- a/src/MissionEditor/SurveyItemEditor.qml +++ b/src/MissionEditor/SurveyItemEditor.qml @@ -71,6 +71,36 @@ Rectangle { } } + QGCCheckBox { + id: cameraTrigger + anchors.left: parent.left + text: "Camera trigger:" + checked: missionItem.cameraTrigger + onClicked: missionItem.cameraTrigger = !missionItem.cameraTrigger + } + + Item { + id: distanceItem + anchors.left: parent.left + anchors.right: parent.right + height: textField.height + enabled: cameraTrigger.checked + + QGCLabel { + anchors.baseline: textField.baseline + anchors.left: parent.left + text: "Distance:" + } + + FactTextField { + id: textField + anchors.right: parent.right + width: _editFieldWidth + showUnits: true + fact: missionItem.cameraTriggerDistance + } + } + QGCButton { text: _addPointsMode ? "Finished" : "Draw Polygon" onClicked: { diff --git a/src/MissionManager/ComplexMissionItem.cc b/src/MissionManager/ComplexMissionItem.cc index 4cd7cffb8..8e04ac673 100644 --- a/src/MissionManager/ComplexMissionItem.cc +++ b/src/MissionManager/ComplexMissionItem.cc @@ -34,6 +34,8 @@ const char* ComplexMissionItem::_jsonIdKey = "id"; const char* ComplexMissionItem::_jsonGridAltitudeKey = "gridAltitude"; const char* ComplexMissionItem::_jsonGridAngleKey = "gridAngle"; const char* ComplexMissionItem::_jsonGridSpacingKey = "gridSpacing"; +const char* ComplexMissionItem::_jsonCameraTriggerKey = "cameraTrigger"; +const char* ComplexMissionItem::_jsonCameraTriggerDistanceKey = "cameraTriggerDistance"; const char* ComplexMissionItem::_complexType = "survey"; @@ -41,23 +43,31 @@ ComplexMissionItem::ComplexMissionItem(Vehicle* vehicle, QObject* parent) : VisualMissionItem(vehicle, parent) , _sequenceNumber(0) , _dirty(false) + , _cameraTrigger(false) , _gridAltitudeFact (0, "Altitude:", FactMetaData::valueTypeDouble) , _gridAngleFact (0, "Grid angle:", FactMetaData::valueTypeDouble) , _gridSpacingFact (0, "Grid spacing:", FactMetaData::valueTypeDouble) + , _cameraTriggerDistanceFact(0, "Camera trigger distance", FactMetaData::valueTypeDouble) { _gridAltitudeFact.setRawValue(25); - _gridSpacingFact.setRawValue(5); + _gridSpacingFact.setRawValue(10); + _cameraTriggerDistanceFact.setRawValue(25); connect(&_gridSpacingFact, &Fact::valueChanged, this, &ComplexMissionItem::_generateGrid); connect(&_gridAngleFact, &Fact::valueChanged, this, &ComplexMissionItem::_generateGrid); + connect(this, &ComplexMissionItem::cameraTriggerChanged, this, &ComplexMissionItem::_signalLastSequenceNumberChanged); } ComplexMissionItem::ComplexMissionItem(const ComplexMissionItem& other, QObject* parent) : VisualMissionItem(other, parent) , _sequenceNumber(other.sequenceNumber()) , _dirty(false) + , _cameraTrigger(other._cameraTrigger) { - + _gridAltitudeFact.setRawValue(other._gridAltitudeFact.rawValue()); + _gridAngleFact.setRawValue(other._gridAngleFact.rawValue()); + _gridSpacingFact.setRawValue(other._gridSpacingFact.rawValue()); + _cameraTriggerDistanceFact.setRawValue(other._cameraTriggerDistanceFact.rawValue()); } void ComplexMissionItem::clearPolygon(void) @@ -102,6 +112,11 @@ int ComplexMissionItem::lastSequenceNumber(void) const if (_gridPoints.count()) { lastSeq += _gridPoints.count() - 1; } + if (_cameraTrigger) { + // Account for two trigger messages + lastSeq += 2; + } + return lastSeq; } @@ -130,6 +145,8 @@ void ComplexMissionItem::save(QJsonObject& saveObject) const saveObject[_jsonGridAltitudeKey] = _gridAltitudeFact.rawValue().toDouble(); saveObject[_jsonGridAngleKey] = _gridAngleFact.rawValue().toDouble(); saveObject[_jsonGridSpacingKey] = _gridSpacingFact.rawValue().toDouble(); + saveObject[_jsonCameraTriggerKey] = _cameraTrigger; + saveObject[_jsonCameraTriggerDistanceKey] = _cameraTriggerDistanceFact.rawValue().toDouble(); // Polygon shape @@ -168,7 +185,8 @@ bool ComplexMissionItem::load(const QJsonObject& complexObject, QString& errorSt // Validate requires keys QStringList requiredKeys; - requiredKeys << _jsonVersionKey << _jsonTypeKey << _jsonIdKey << _jsonPolygonKey << _jsonGridAltitudeKey << _jsonGridAngleKey << _jsonGridSpacingKey; + requiredKeys << _jsonVersionKey << _jsonTypeKey << _jsonIdKey << _jsonPolygonKey << _jsonGridAltitudeKey << _jsonGridAngleKey << _jsonGridSpacingKey << + _jsonCameraTriggerKey << _jsonCameraTriggerDistanceKey; if (!JsonHelper::validateRequiredKeys(complexObject, requiredKeys, errorString)) { _clear(); return false; @@ -177,8 +195,10 @@ bool ComplexMissionItem::load(const QJsonObject& complexObject, QString& errorSt // Validate types QStringList keyList; QList typeList; - keyList << _jsonVersionKey << _jsonTypeKey << _jsonIdKey << _jsonPolygonKey << _jsonGridAltitudeKey << _jsonGridAngleKey << _jsonGridSpacingKey; - typeList << QJsonValue::Double << QJsonValue::String << QJsonValue::Double << QJsonValue::Array << QJsonValue::Double << QJsonValue::Double<< QJsonValue::Double; + keyList << _jsonVersionKey << _jsonTypeKey << _jsonIdKey << _jsonPolygonKey << _jsonGridAltitudeKey << _jsonGridAngleKey << _jsonGridSpacingKey << + _jsonCameraTriggerKey << _jsonCameraTriggerDistanceKey; + typeList << QJsonValue::Double << QJsonValue::String << QJsonValue::Double << QJsonValue::Array << QJsonValue::Double << QJsonValue::Double<< QJsonValue::Double << + QJsonValue::Bool << QJsonValue::Double; if (!JsonHelper::validateKeyTypes(complexObject, keyList, typeList, errorString)) { _clear(); return false; @@ -198,9 +218,11 @@ bool ComplexMissionItem::load(const QJsonObject& complexObject, QString& errorSt } setSequenceNumber(complexObject[_jsonIdKey].toInt()); - _gridAltitudeFact.setRawValue(complexObject[_jsonGridAltitudeKey].toDouble()); - _gridAngleFact.setRawValue(complexObject[_jsonGridAngleKey].toDouble()); - _gridSpacingFact.setRawValue(complexObject[_jsonGridSpacingKey].toDouble()); + _cameraTrigger = complexObject[_jsonCameraTriggerKey].toBool(); + _gridAltitudeFact.setRawValue (complexObject[_jsonGridAltitudeKey].toDouble()); + _gridAngleFact.setRawValue (complexObject[_jsonGridAngleKey].toDouble()); + _gridSpacingFact.setRawValue (complexObject[_jsonGridSpacingKey].toDouble()); + _cameraTriggerDistanceFact.setRawValue(complexObject[_jsonCameraTriggerDistanceKey].toDouble()); // Polygon shape QJsonArray polygonArray(complexObject[_jsonPolygonKey].toArray()); @@ -444,7 +466,7 @@ void ComplexMissionItem::_gridGenerator(const QList& polygonPoints, QL } } -QmlObjectListModel* ComplexMissionItem::getMissionItems(void) const +QmlObjectListModel* ComplexMissionItem::getMissionItems(void) const { QmlObjectListModel* pMissionItems = new QmlObjectListModel; @@ -464,7 +486,36 @@ QmlObjectListModel* ComplexMissionItem::getMissionItems(void) const false, // isCurrentItem pMissionItems); // parent - allow delete on pMissionItems to delete everthing pMissionItems->append(item); + + if (_cameraTrigger && i == 0) { + MissionItem* item = new MissionItem(seqNum++, // sequence number + MAV_CMD_DO_SET_CAM_TRIGG_DIST, // MAV_CMD + MAV_FRAME_MISSION, // MAV_FRAME + _cameraTriggerDistanceFact.rawValue().toDouble(), // trigger distance + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, // param 2-7 + true, // autoContinue + false, // isCurrentItem + pMissionItems); // parent - allow delete on pMissionItems to delete everthing + pMissionItems->append(item); + } + } + + if (_cameraTrigger) { + MissionItem* item = new MissionItem(seqNum++, // sequence number + MAV_CMD_DO_SET_CAM_TRIGG_DIST, // MAV_CMD + MAV_FRAME_MISSION, // MAV_FRAME + 0.0, // trigger distance + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, // param 2-7 + true, // autoContinue + false, // isCurrentItem + pMissionItems); // parent - allow delete on pMissionItems to delete everthing + pMissionItems->append(item); } return pMissionItems; } + +void ComplexMissionItem::_signalLastSequenceNumberChanged(void) +{ + emit lastSequenceNumberChanged(lastSequenceNumber()); +} diff --git a/src/MissionManager/ComplexMissionItem.h b/src/MissionManager/ComplexMissionItem.h index 097df3a06..249ccb57c 100644 --- a/src/MissionManager/ComplexMissionItem.h +++ b/src/MissionManager/ComplexMissionItem.h @@ -39,6 +39,8 @@ public: Q_PROPERTY(Fact* gridAltitude READ gridAltitude CONSTANT) Q_PROPERTY(Fact* gridAngle READ gridAngle CONSTANT) Q_PROPERTY(Fact* gridSpacing READ gridSpacing CONSTANT) + Q_PROPERTY(bool cameraTrigger MEMBER _cameraTrigger NOTIFY cameraTriggerChanged) + Q_PROPERTY(Fact* cameraTriggerDistance READ cameraTriggerDistance CONSTANT) Q_PROPERTY(QVariantList polygonPath READ polygonPath NOTIFY polygonPathChanged) Q_PROPERTY(int lastSequenceNumber READ lastSequenceNumber NOTIFY lastSequenceNumberChanged) Q_PROPERTY(QVariantList gridPoints READ gridPoints NOTIFY gridPointsChanged) @@ -52,6 +54,7 @@ public: Fact* gridAltitude(void) { return &_gridAltitudeFact; } Fact* gridAngle(void) { return &_gridAngleFact; } Fact* gridSpacing(void) { return &_gridSpacingFact; } + Fact* cameraTriggerDistance(void) { return &_cameraTriggerDistanceFact; } /// @return The last sequence number used by this item. Takes into account child items of the complex item int lastSequenceNumber(void) const; @@ -93,6 +96,10 @@ signals: void altitudeChanged(double altitude); void gridAngleChanged(double gridAngle); void gridPointsChanged(void); + void cameraTriggerChanged(bool cameraTrigger); + +private slots: + void _signalLastSequenceNumberChanged(void); private: void _clear(void); @@ -112,10 +119,12 @@ private: QGeoCoordinate _exitCoordinate; double _altitude; double _gridAngle; + bool _cameraTrigger; Fact _gridAltitudeFact; Fact _gridAngleFact; Fact _gridSpacingFact; + Fact _cameraTriggerDistanceFact; static const char* _jsonVersionKey; static const char* _jsonTypeKey; @@ -124,6 +133,8 @@ private: static const char* _jsonGridAltitudeKey; static const char* _jsonGridAngleKey; static const char* _jsonGridSpacingKey; + static const char* _jsonCameraTriggerKey; + static const char* _jsonCameraTriggerDistanceKey; static const char* _complexType; }; -- 2.22.0