Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for multiple landing sequences #12313

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions src/FlightDisplay/FlyViewMap.qml
Original file line number Diff line number Diff line change
Expand Up @@ -326,17 +326,6 @@ FlightMap {
}
}

MapItemView {
model: pipMode ? undefined : _missionController.directionArrows

delegate: MapLineArrow {
fromCoord: object ? object.coordinate1 : undefined
toCoord: object ? object.coordinate2 : undefined
arrowPosition: 2
z: QGroundControl.zOrderWaypointLines
}
}

// Allow custom builds to add map items
CustomMapItems {
map: _root
Expand Down
28 changes: 21 additions & 7 deletions src/FlightMap/MapItems/PlanMapItems.qml
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,35 @@ Item {
_missionLineViewComponent = missionLineViewComponent.createObject(map)
if (_missionLineViewComponent.status === Component.Error)
console.log(_missionLineViewComponent.errorString())
map.addMapItem(_missionLineViewComponent)
map.addMapItemGroup(_missionLineViewComponent)
}

Component.onDestruction: {
_missionLineViewComponent.destroy()
if (_missionLineViewComponent) {
// Must remove MapItemGroup before destruction, otherwise we crash on quit
map.removeMapItemGroup(_missionLineViewComponent)
_missionLineViewComponent.destroy()
}
}

Component {
id: missionLineViewComponent

MapPolyline {
line.width: 3
line.color: "#be781c" // Hack, can't get palette to work in here
z: QGroundControl.zOrderWaypointLines
path: _missionController.waypointPath
MapItemGroup {
MissionLineView {
model: _missionController.simpleFlightPathSegments
}

MapItemView {
model: _missionController.directionArrows

delegate: MapLineArrow {
fromCoord: object ? object.coordinate1 : undefined
toCoord: object ? object.coordinate2 : undefined
arrowPosition: 3
z: QGroundControl.zOrderWaypointLines + 1
}
}
}
}
}
4 changes: 2 additions & 2 deletions src/MissionManager/FixedWingLandingComplexItem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ bool FixedWingLandingComplexItem::_isValidLandItem(const MissionItem& missionIte
}
}

bool FixedWingLandingComplexItem::scanForItem(QmlObjectListModel* visualItems, bool flyView, PlanMasterController* masterController)
bool FixedWingLandingComplexItem::scanForItems(QmlObjectListModel* visualItems, bool flyView, PlanMasterController* masterController)
{
return _scanForItem(visualItems, flyView, masterController, _isValidLandItem, _createItem);
return _scanForItems(visualItems, flyView, masterController, _isValidLandItem, _createItem);
}

// Never call this method directly. If you want to update the flight segments you emit _updateFlightPathSegmentsSignal()
Expand Down
2 changes: 1 addition & 1 deletion src/MissionManager/FixedWingLandingComplexItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class FixedWingLandingComplexItem : public LandingComplexItem
Fact* valueSetIsDistance (void) { return &_valueSetIsDistanceFact; }

/// Scans the loaded items for a landing pattern complex item
static bool scanForItem(QmlObjectListModel* visualItems, bool flyView, PlanMasterController* masterController);
static bool scanForItems(QmlObjectListModel* visualItems, bool flyView, PlanMasterController* masterController);

// Overrides from ComplexMissionItem
QString patternName (void) const final { return name; }
Expand Down
29 changes: 22 additions & 7 deletions src/MissionManager/LandingComplexItem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -363,14 +363,31 @@ MissionItem* LandingComplexItem::_createFinalApproachItem(int seqNum, QObject* p
}
}

bool LandingComplexItem::_scanForItem(QmlObjectListModel* visualItems, bool flyView, PlanMasterController* masterController, IsLandItemFunc isLandItemFunc, CreateItemFunc createItemFunc)
bool LandingComplexItem::_scanForItems(QmlObjectListModel* visualItems, bool flyView, PlanMasterController* masterController, IsLandItemFunc isLandItemFunc, CreateItemFunc createItemFunc)
{
qCDebug(LandingComplexItemLog) << "VTOLLandingComplexItem::scanForItem count" << visualItems->count();

if (visualItems->count() < 3) {
return false;
}

// Start looking for the commands in reverse order from the end of the list
int startIndex = visualItems->count();
bool foundAny = false;

while (startIndex >= 0) {
if (_scanForItem(visualItems, startIndex, flyView, masterController, isLandItemFunc, createItemFunc)) {
foundAny = true;
} else {
startIndex--;
}
}

return foundAny;
}

bool LandingComplexItem::_scanForItem(QmlObjectListModel* visualItems, int& startIndex, bool flyView, PlanMasterController* masterController, IsLandItemFunc isLandItemFunc, CreateItemFunc createItemFunc)
{
// A valid landing pattern is comprised of the follow commands in this order at the end of the item list:
// MAV_CMD_DO_LAND_START - required
// MAV_CMD_DO_CHANGE_SPEED - optional
Expand All @@ -379,9 +396,7 @@ bool LandingComplexItem::_scanForItem(QmlObjectListModel* visualItems, bool flyV
// MAV_CMD_NAV_LOITER_TO_ALT or MAV_CMD_NAV_WAYPOINT
// MAV_CMD_NAV_LAND or MAV_CMD_NAV_VTOL_LAND

// Start looking for the commands in reverse order from the end of the list

int scanIndex = visualItems->count() - 1;
int scanIndex = startIndex - 1;

if (scanIndex < 0 || scanIndex > visualItems->count() - 1) {
return false;
Expand Down Expand Up @@ -476,7 +491,6 @@ bool LandingComplexItem::_scanForItem(QmlObjectListModel* visualItems, bool flyV
}

// We made it this far so we do have a Fixed Wing Landing Pattern item at the end of the mission.
// Since we have scanned it we need to remove the items for it fromt the list
int deleteCount = 3;
if (stopTakingPhotos) {
deleteCount += CameraSection::stopTakingPhotosCommandCount();
Expand All @@ -487,7 +501,7 @@ bool LandingComplexItem::_scanForItem(QmlObjectListModel* visualItems, bool flyV
if (useDoChangeSpeed) {
deleteCount++;
}
int firstItem = visualItems->count() - deleteCount;
int firstItem = startIndex - deleteCount;
while (deleteCount--) {
visualItems->removeAt(firstItem)->deleteLater();
}
Expand Down Expand Up @@ -526,7 +540,8 @@ bool LandingComplexItem::_scanForItem(QmlObjectListModel* visualItems, bool flyV
complexItem->_recalcFromCoordinateChange();
complexItem->setDirty(false);

visualItems->append(complexItem);
visualItems->insert(firstItem, complexItem);
startIndex = firstItem;

return true;
}
Expand Down
4 changes: 3 additions & 1 deletion src/MissionManager/LandingComplexItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class LandingComplexItem : public ComplexMissionItem
// Overrides from VisualMissionItem
bool dirty (void) const final { return _dirty; }
bool isSimpleItem (void) const final { return false; }
bool isLandCommand (void) const final { return true; }
bool isStandaloneCoordinate (void) const final { return false; }
bool specifiesCoordinate (void) const final { return true; }
bool specifiesAltitudeOnly (void) const final { return false; }
Expand Down Expand Up @@ -169,7 +170,8 @@ protected slots:
typedef bool (*IsLandItemFunc)(const MissionItem& missionItem);
typedef LandingComplexItem* (*CreateItemFunc)(PlanMasterController* masterController, bool flyView);

static bool _scanForItem(QmlObjectListModel* visualItems, bool flyView, PlanMasterController* masterController, IsLandItemFunc isLandItemFunc, CreateItemFunc createItemFunc);
static bool _scanForItems(QmlObjectListModel* visualItems, bool flyView, PlanMasterController* masterController, IsLandItemFunc isLandItemFunc, CreateItemFunc createItemFunc);
static bool _scanForItem(QmlObjectListModel* visualItems, int& startIndex, bool flyView, PlanMasterController* masterController, IsLandItemFunc isLandItemFunc, CreateItemFunc createItemFunc);

int _sequenceNumber = 0;
bool _dirty = false;
Expand Down
Loading
Loading