Browse Source

AMSL altitude support

QGC4.4
Don Gagne 9 years ago
parent
commit
3b3b49d916
  1. 8
      src/MissionEditor/MissionEditor.qml
  2. 11
      src/MissionEditor/SurveyItemEditor.qml
  3. 42
      src/MissionManager/ComplexMissionItem.cc
  4. 12
      src/MissionManager/ComplexMissionItem.h

8
src/MissionEditor/MissionEditor.qml

@ -368,13 +368,7 @@ QGCView { @@ -368,13 +368,7 @@ QGCView {
// Add the complex mission item polygon to the map
MapItemView {
model: controller.complexVisualItems
delegate: polygonItemComponent
}
Component {
id: polygonItemComponent
MapPolygon {
delegate: MapPolygon {
color: 'green'
path: object.polygonPath
opacity: 0.5

11
src/MissionEditor/SurveyItemEditor.qml

@ -72,11 +72,18 @@ Rectangle { @@ -72,11 +72,18 @@ Rectangle {
}
QGCCheckBox {
anchors.left: parent.left
text: "Relative altitude"
checked: missionItem.gridAltitudeRelative
onClicked: missionItem.gridAltitudeRelative = checked
}
QGCCheckBox {
id: cameraTrigger
anchors.left: parent.left
text: "Camera trigger:"
checked: missionItem.cameraTrigger
onClicked: missionItem.cameraTrigger = !missionItem.cameraTrigger
onClicked: missionItem.cameraTrigger = checked
}
Item {
@ -102,7 +109,7 @@ Rectangle { @@ -102,7 +109,7 @@ Rectangle {
}
QGCButton {
text: _addPointsMode ? "Finished" : "Draw Polygon"
text: _addPointsMode ? "Finish Polygon" : "Draw Polygon"
onClicked: {
if (_addPointsMode) {
_addPointsMode = false

42
src/MissionManager/ComplexMissionItem.cc

@ -27,11 +27,14 @@ This file is part of the QGROUNDCONTROL project @@ -27,11 +27,14 @@ This file is part of the QGROUNDCONTROL project
#include <QPolygonF>
QGC_LOGGING_CATEGORY(ComplexMissionItemLog, "ComplexMissionItemLog")
const char* ComplexMissionItem::_jsonVersionKey = "version";
const char* ComplexMissionItem::_jsonTypeKey = "type";
const char* ComplexMissionItem::_jsonPolygonKey = "polygon";
const char* ComplexMissionItem::_jsonIdKey = "id";
const char* ComplexMissionItem::_jsonGridAltitudeKey = "gridAltitude";
const char* ComplexMissionItem::_jsonGridAltitudeRelativeKey = "gridAltitudeRelative";
const char* ComplexMissionItem::_jsonGridAngleKey = "gridAngle";
const char* ComplexMissionItem::_jsonGridSpacingKey = "gridSpacing";
const char* ComplexMissionItem::_jsonCameraTriggerKey = "cameraTrigger";
@ -44,6 +47,7 @@ ComplexMissionItem::ComplexMissionItem(Vehicle* vehicle, QObject* parent) @@ -44,6 +47,7 @@ ComplexMissionItem::ComplexMissionItem(Vehicle* vehicle, QObject* parent)
, _sequenceNumber(0)
, _dirty(false)
, _cameraTrigger(false)
, _gridAltitudeRelative(true)
, _gridAltitudeFact (0, "Altitude:", FactMetaData::valueTypeDouble)
, _gridAngleFact (0, "Grid angle:", FactMetaData::valueTypeDouble)
, _gridSpacingFact (0, "Grid spacing:", FactMetaData::valueTypeDouble)
@ -58,18 +62,6 @@ ComplexMissionItem::ComplexMissionItem(Vehicle* vehicle, QObject* parent) @@ -58,18 +62,6 @@ ComplexMissionItem::ComplexMissionItem(Vehicle* vehicle, QObject* parent)
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)
{
// Bug workaround, see below
@ -143,6 +135,7 @@ void ComplexMissionItem::save(QJsonObject& saveObject) const @@ -143,6 +135,7 @@ void ComplexMissionItem::save(QJsonObject& saveObject) const
saveObject[_jsonTypeKey] = _complexType;
saveObject[_jsonIdKey] = sequenceNumber();
saveObject[_jsonGridAltitudeKey] = _gridAltitudeFact.rawValue().toDouble();
saveObject[_jsonGridAltitudeRelativeKey] = _gridAltitudeRelative;
saveObject[_jsonGridAngleKey] = _gridAngleFact.rawValue().toDouble();
saveObject[_jsonGridSpacingKey] = _gridSpacingFact.rawValue().toDouble();
saveObject[_jsonCameraTriggerKey] = _cameraTrigger;
@ -186,7 +179,7 @@ bool ComplexMissionItem::load(const QJsonObject& complexObject, QString& errorSt @@ -186,7 +179,7 @@ bool ComplexMissionItem::load(const QJsonObject& complexObject, QString& errorSt
// Validate requires keys
QStringList requiredKeys;
requiredKeys << _jsonVersionKey << _jsonTypeKey << _jsonIdKey << _jsonPolygonKey << _jsonGridAltitudeKey << _jsonGridAngleKey << _jsonGridSpacingKey <<
_jsonCameraTriggerKey << _jsonCameraTriggerDistanceKey;
_jsonCameraTriggerKey << _jsonCameraTriggerDistanceKey << _jsonGridAltitudeRelativeKey;
if (!JsonHelper::validateRequiredKeys(complexObject, requiredKeys, errorString)) {
_clear();
return false;
@ -196,9 +189,9 @@ bool ComplexMissionItem::load(const QJsonObject& complexObject, QString& errorSt @@ -196,9 +189,9 @@ bool ComplexMissionItem::load(const QJsonObject& complexObject, QString& errorSt
QStringList keyList;
QList<QJsonValue::Type> typeList;
keyList << _jsonVersionKey << _jsonTypeKey << _jsonIdKey << _jsonPolygonKey << _jsonGridAltitudeKey << _jsonGridAngleKey << _jsonGridSpacingKey <<
_jsonCameraTriggerKey << _jsonCameraTriggerDistanceKey;
_jsonCameraTriggerKey << _jsonCameraTriggerDistanceKey << _jsonGridAltitudeRelativeKey;
typeList << QJsonValue::Double << QJsonValue::String << QJsonValue::Double << QJsonValue::Array << QJsonValue::Double << QJsonValue::Double<< QJsonValue::Double <<
QJsonValue::Bool << QJsonValue::Double;
QJsonValue::Bool << QJsonValue::Double << QJsonValue::Bool;
if (!JsonHelper::validateKeyTypes(complexObject, keyList, typeList, errorString)) {
_clear();
return false;
@ -218,7 +211,10 @@ bool ComplexMissionItem::load(const QJsonObject& complexObject, QString& errorSt @@ -218,7 +211,10 @@ bool ComplexMissionItem::load(const QJsonObject& complexObject, QString& errorSt
}
setSequenceNumber(complexObject[_jsonIdKey].toInt());
_cameraTrigger = complexObject[_jsonCameraTriggerKey].toBool();
_gridAltitudeRelative = complexObject[_jsonGridAltitudeRelativeKey].toBool();
_gridAltitudeFact.setRawValue (complexObject[_jsonGridAltitudeKey].toDouble());
_gridAngleFact.setRawValue (complexObject[_jsonGridAngleKey].toDouble());
_gridSpacingFact.setRawValue (complexObject[_jsonGridSpacingKey].toDouble());
@ -280,13 +276,13 @@ void ComplexMissionItem::_generateGrid(void) @@ -280,13 +276,13 @@ void ComplexMissionItem::_generateGrid(void)
QList<QPointF> gridPoints;
// Convert polygon to Qt coordinate system (y positive is down)
qDebug() << "Convert polygon";
qCDebug(ComplexMissionItemLog) << "Convert polygon";
QGeoCoordinate tangentOrigin = _polygonPath[0].value<QGeoCoordinate>();
for (int i=0; i<_polygonPath.count(); i++) {
double y, x, down;
convertGeoToNed(_polygonPath[i].value<QGeoCoordinate>(), tangentOrigin, &y, &x, &down);
polygonPoints += QPointF(x, -y);
qDebug() << _polygonPath[i].value<QGeoCoordinate>() << polygonPoints.last().x() << polygonPoints.last().y();
qCDebug(ComplexMissionItemLog) << _polygonPath[i].value<QGeoCoordinate>() << polygonPoints.last().x() << polygonPoints.last().y();
}
// Generate grid
@ -413,16 +409,16 @@ void ComplexMissionItem::_gridGenerator(const QList<QPointF>& polygonPoints, QL @@ -413,16 +409,16 @@ void ComplexMissionItem::_gridGenerator(const QList<QPointF>& polygonPoints, QL
// Convert polygon to bounding rect
qDebug() << "Polygon";
qCDebug(ComplexMissionItemLog) << "Polygon";
QPolygonF polygon;
for (int i=0; i<polygonPoints.count(); i++) {
qDebug() << polygonPoints[i];
qCDebug(ComplexMissionItemLog) << polygonPoints[i];
polygon << polygonPoints[i];
}
polygon << polygonPoints[0];
QRectF smallBoundRect = polygon.boundingRect();
QPointF center = smallBoundRect.center();
qDebug() << "Bounding rect" << smallBoundRect.topLeft().x() << smallBoundRect.topLeft().y() << smallBoundRect.bottomRight().x() << smallBoundRect.bottomRight().y();
qCDebug(ComplexMissionItemLog) << "Bounding rect" << smallBoundRect.topLeft().x() << smallBoundRect.topLeft().y() << smallBoundRect.bottomRight().x() << smallBoundRect.bottomRight().y();
// Rotate the bounding rect around it's center to generate the larger bounding rect
QPolygonF boundPolygon;
@ -432,7 +428,7 @@ void ComplexMissionItem::_gridGenerator(const QList<QPointF>& polygonPoints, QL @@ -432,7 +428,7 @@ void ComplexMissionItem::_gridGenerator(const QList<QPointF>& polygonPoints, QL
boundPolygon << _rotatePoint(smallBoundRect.bottomLeft(), center, gridAngle);
boundPolygon << boundPolygon[0];
QRectF largeBoundRect = boundPolygon.boundingRect();
qDebug() << "Rotated bounding rect" << largeBoundRect.topLeft().x() << largeBoundRect.topLeft().y() << largeBoundRect.bottomRight().x() << largeBoundRect.bottomRight().y();
qCDebug(ComplexMissionItemLog) << "Rotated bounding rect" << largeBoundRect.topLeft().x() << largeBoundRect.topLeft().y() << largeBoundRect.bottomRight().x() << largeBoundRect.bottomRight().y();
// Create set of rotated parallel lines within the expanded bounding rect. Make the lines larger than the
// bounding box to guarantee intersection.
@ -444,7 +440,7 @@ void ComplexMissionItem::_gridGenerator(const QList<QPointF>& polygonPoints, QL @@ -444,7 +440,7 @@ void ComplexMissionItem::_gridGenerator(const QList<QPointF>& polygonPoints, QL
float yBottom = largeBoundRect.bottomRight().y() + 100.0;
lineList += QLineF(_rotatePoint(QPointF(x, yTop), center, gridAngle), _rotatePoint(QPointF(x, yBottom), center, gridAngle));
qDebug() << "line" << lineList.last().x1() << lineList.last().y1() << lineList.last().x2() << lineList.last().y2();
qCDebug(ComplexMissionItemLog) << "line" << lineList.last().x1() << lineList.last().y1() << lineList.last().x2() << lineList.last().y2();
x += gridSpacing;
}
@ -477,7 +473,7 @@ QmlObjectListModel* ComplexMissionItem::getMissionItems(void) const @@ -477,7 +473,7 @@ QmlObjectListModel* ComplexMissionItem::getMissionItems(void) const
MissionItem* item = new MissionItem(seqNum++, // sequence number
MAV_CMD_NAV_WAYPOINT, // MAV_CMD
MAV_FRAME_GLOBAL_RELATIVE_ALT, // MAV_FRAME
_gridAltitudeRelative ? MAV_FRAME_GLOBAL_RELATIVE_ALT : MAV_FRAME_GLOBAL, // MAV_FRAME
0.0, 0.0, 0.0, 0.0, // param 1-4
coord.latitude(),
coord.longitude(),

12
src/MissionManager/ComplexMissionItem.h

@ -27,6 +27,9 @@ @@ -27,6 +27,9 @@
#include "VisualMissionItem.h"
#include "MissionItem.h"
#include "Fact.h"
#include "QGCLoggingCategory.h"
Q_DECLARE_LOGGING_CATEGORY(ComplexMissionItemLog)
class ComplexMissionItem : public VisualMissionItem
{
@ -34,9 +37,9 @@ class ComplexMissionItem : public VisualMissionItem @@ -34,9 +37,9 @@ class ComplexMissionItem : public VisualMissionItem
public:
ComplexMissionItem(Vehicle* vehicle, QObject* parent = NULL);
ComplexMissionItem(const ComplexMissionItem& other, QObject* parent = NULL);
Q_PROPERTY(Fact* gridAltitude READ gridAltitude CONSTANT)
Q_PROPERTY(bool gridAltitudeRelative MEMBER _gridAltitudeRelative NOTIFY gridAltitudeRelativeChanged)
Q_PROPERTY(Fact* gridAngle READ gridAngle CONSTANT)
Q_PROPERTY(Fact* gridSpacing READ gridSpacing CONSTANT)
Q_PROPERTY(bool cameraTrigger MEMBER _cameraTrigger NOTIFY cameraTriggerChanged)
@ -81,8 +84,8 @@ public: @@ -81,8 +84,8 @@ public:
QGeoCoordinate exitCoordinate (void) const final { return _exitCoordinate; }
int sequenceNumber (void) const final { return _sequenceNumber; }
bool coordinateHasRelativeAltitude (void) const final { return true; }
bool exitCoordinateHasRelativeAltitude (void) const final { return true; }
bool coordinateHasRelativeAltitude (void) const final { return _gridAltitudeRelative; }
bool exitCoordinateHasRelativeAltitude (void) const final { return _gridAltitudeRelative; }
bool exitCoordinateSameAsEntry (void) const final { return false; }
void setDirty (bool dirty) final;
@ -97,6 +100,7 @@ signals: @@ -97,6 +100,7 @@ signals:
void gridAngleChanged (double gridAngle);
void gridPointsChanged (void);
void cameraTriggerChanged (bool cameraTrigger);
void gridAltitudeRelativeChanged (bool gridAltitudeRelative);
private slots:
void _signalLastSequenceNumberChanged(void);
@ -120,6 +124,7 @@ private: @@ -120,6 +124,7 @@ private:
double _altitude;
double _gridAngle;
bool _cameraTrigger;
bool _gridAltitudeRelative;
Fact _gridAltitudeFact;
Fact _gridAngleFact;
@ -131,6 +136,7 @@ private: @@ -131,6 +136,7 @@ private:
static const char* _jsonPolygonKey;
static const char* _jsonIdKey;
static const char* _jsonGridAltitudeKey;
static const char* _jsonGridAltitudeRelativeKey;
static const char* _jsonGridAngleKey;
static const char* _jsonGridSpacingKey;
static const char* _jsonCameraTriggerKey;

Loading…
Cancel
Save