Skip to content

Commit

Permalink
Better initial map positions and planned home position support
Browse files Browse the repository at this point in the history
  • Loading branch information
DonLakeFlyer committed Mar 25, 2017
1 parent 079ffd7 commit cff65eb
Show file tree
Hide file tree
Showing 42 changed files with 291 additions and 435 deletions.
6 changes: 3 additions & 3 deletions qgroundcontrol.pro
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ INCLUDEPATH += \
src/FollowMe \
src/GPS \
src/Joystick \
src/MissionEditor \
src/PlanView \
src/MissionManager \
src/PositionManager \
src/QmlControls \
Expand Down Expand Up @@ -462,7 +462,7 @@ HEADERS += \
src/MissionManager/MissionController.h \
src/MissionManager/MissionItem.h \
src/MissionManager/MissionManager.h \
src/MissionManager/MissionSettingsComplexItem.h \
src/MissionManager/MissionSettingsItem.h \
src/MissionManager/PlanElementController.h \
src/MissionManager/QGCMapPolygon.h \
src/MissionManager/RallyPoint.h \
Expand Down Expand Up @@ -640,7 +640,7 @@ SOURCES += \
src/MissionManager/MissionController.cc \
src/MissionManager/MissionItem.cc \
src/MissionManager/MissionManager.cc \
src/MissionManager/MissionSettingsComplexItem.cc \
src/MissionManager/MissionSettingsItem.cc \
src/MissionManager/PlanElementController.cc \
src/MissionManager/QGCMapPolygon.cc \
src/MissionManager/RallyPoint.cc \
Expand Down
40 changes: 20 additions & 20 deletions qgroundcontrol.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<file alias="MainWindowInner.qml">src/ui/MainWindowInner.qml</file>
<file alias="MainWindowNative.qml">src/ui/MainWindowNative.qml</file>
<file alias="MavlinkSettings.qml">src/ui/preferences/MavlinkSettings.qml</file>
<file alias="MissionEditor.qml">src/MissionEditor/MissionEditor.qml</file>
<file alias="PlanView.qml">src/PlanView/PlanView.qml</file>
<file alias="MixersComponent.qml">src/AutoPilotPlugins/Common/MixersComponent.qml</file>
<file alias="MockLink.qml">src/ui/preferences/MockLink.qml</file>
<file alias="MockLinkSettings.qml">src/ui/preferences/MockLinkSettings.qml</file>
Expand All @@ -47,32 +47,32 @@
<file alias="PX4FlowSensor.qml">src/VehicleSetup/PX4FlowSensor.qml</file>
<file alias="QGroundControl/Controls/AnalyzePage.qml">src/AnalyzeView/AnalyzePage.qml</file>
<file alias="QGroundControl/Controls/AppMessages.qml">src/QmlControls/AppMessages.qml</file>
<file alias="QGroundControl/Controls/CameraSection.qml">src/MissionEditor/CameraSection.qml</file>
<file alias="QGroundControl/Controls/CameraSection.qml">src/PlanView/CameraSection.qml</file>
<file alias="QGroundControl/Controls/ClickableColor.qml">src/QmlControls/ClickableColor.qml</file>
<file alias="QGroundControl/Controls/DropButton.qml">src/QmlControls/DropButton.qml</file>
<file alias="QGroundControl/Controls/ExclusiveGroupItem.qml">src/QmlControls/ExclusiveGroupItem.qml</file>
<file alias="QGroundControl/Controls/FactSliderPanel.qml">src/QmlControls/FactSliderPanel.qml</file>
<file alias="QGroundControl/Controls/FlightModeDropdown.qml">src/QmlControls/FlightModeDropdown.qml</file>
<file alias="QGroundControl/Controls/FlightModeMenu.qml">src/QmlControls/FlightModeMenu.qml</file>
<file alias="QGroundControl/Controls/FWLandingPatternMapVisual.qml">src/MissionEditor/FWLandingPatternMapVisual.qml</file>
<file alias="QGroundControl/Controls/GeoFenceEditor.qml">src/MissionEditor/GeoFenceEditor.qml</file>
<file alias="QGroundControl/Controls/GeoFenceMapVisuals.qml">src/MissionEditor/GeoFenceMapVisuals.qml</file>
<file alias="QGroundControl/Controls/FWLandingPatternMapVisual.qml">src/PlanView/FWLandingPatternMapVisual.qml</file>
<file alias="QGroundControl/Controls/GeoFenceEditor.qml">src/PlanView/GeoFenceEditor.qml</file>
<file alias="QGroundControl/Controls/GeoFenceMapVisuals.qml">src/PlanView/GeoFenceMapVisuals.qml</file>
<file alias="QGroundControl/Controls/IndicatorButton.qml">src/QmlControls/IndicatorButton.qml</file>
<file alias="QGroundControl/Controls/JoystickThumbPad.qml">src/QmlControls/JoystickThumbPad.qml</file>
<file alias="QGroundControl/Controls/MainToolBar.qml">src/ui/toolbar/MainToolBar.qml</file>
<file alias="QGroundControl/Controls/MainToolBarIndicators.qml">src/ui/toolbar/MainToolBarIndicators.qml</file>
<file alias="QGroundControl/Controls/MissionCommandDialog.qml">src/QmlControls/MissionCommandDialog.qml</file>
<file alias="QGroundControl/Controls/MissionItemEditor.qml">src/MissionEditor/MissionItemEditor.qml</file>
<file alias="QGroundControl/Controls/MissionItemEditor.qml">src/PlanView/MissionItemEditor.qml</file>
<file alias="QGroundControl/Controls/MissionItemIndexLabel.qml">src/QmlControls/MissionItemIndexLabel.qml</file>
<file alias="QGroundControl/Controls/MissionItemMapVisual.qml">src/MissionEditor/MissionItemMapVisual.qml</file>
<file alias="QGroundControl/Controls/MissionItemStatus.qml">src/MissionEditor/MissionItemStatus.qml</file>
<file alias="QGroundControl/Controls/MissionSettingsMapVisual.qml">src/MissionEditor/MissionSettingsMapVisual.qml</file>
<file alias="QGroundControl/Controls/MissionItemMapVisual.qml">src/PlanView/MissionItemMapVisual.qml</file>
<file alias="QGroundControl/Controls/MissionItemStatus.qml">src/PlanView/MissionItemStatus.qml</file>
<file alias="QGroundControl/Controls/MissionSettingsMapVisual.qml">src/PlanView/MissionSettingsMapVisual.qml</file>
<file alias="QGroundControl/Controls/ModeSwitchDisplay.qml">src/QmlControls/ModeSwitchDisplay.qml</file>
<file alias="QGroundControl/Controls/MultiRotorMotorDisplay.qml">src/QmlControls/MultiRotorMotorDisplay.qml</file>
<file alias="QGroundControl/Controls/OfflineMapButton.qml">src/QmlControls/OfflineMapButton.qml</file>
<file alias="QGroundControl/Controls/ParameterEditor.qml">src/QmlControls/ParameterEditor.qml</file>
<file alias="QGroundControl/Controls/ParameterEditorDialog.qml">src/QmlControls/ParameterEditorDialog.qml</file>
<file alias="QGroundControl/Controls/PlanToolBar.qml">src/MissionEditor/PlanToolBar.qml</file>
<file alias="QGroundControl/Controls/PlanToolBar.qml">src/PlanView/PlanToolBar.qml</file>
<file alias="QGroundControl/Controls/QGCButton.qml">src/QmlControls/QGCButton.qml</file>
<file alias="QGroundControl/Controls/QGCCheckBox.qml">src/QmlControls/QGCCheckBox.qml</file>
<file alias="QGroundControl/Controls/QGCColoredImage.qml">src/QmlControls/QGCColoredImage.qml</file>
Expand All @@ -98,17 +98,17 @@
<file alias="QGroundControl/Controls/QGCViewMessage.qml">src/QmlControls/QGCViewMessage.qml</file>
<file alias="QGroundControl/Controls/QGCViewPanel.qml">src/QmlControls/QGCViewPanel.qml</file>
<file alias="QGroundControl/Controls/qmldir">src/QmlControls/QGroundControl.Controls.qmldir</file>
<file alias="QGroundControl/Controls/RallyPointEditorHeader.qml">src/MissionEditor/RallyPointEditorHeader.qml</file>
<file alias="QGroundControl/Controls/RallyPointItemEditor.qml">src/MissionEditor/RallyPointItemEditor.qml</file>
<file alias="QGroundControl/Controls/RallyPointEditorHeader.qml">src/PlanView/RallyPointEditorHeader.qml</file>
<file alias="QGroundControl/Controls/RallyPointItemEditor.qml">src/PlanView/RallyPointItemEditor.qml</file>
<file alias="QGroundControl/Controls/RCChannelMonitor.qml">src/QmlControls/RCChannelMonitor.qml</file>
<file alias="QGroundControl/Controls/RoundButton.qml">src/QmlControls/RoundButton.qml</file>
<file alias="QGroundControl/Controls/SectionHeader.qml">src/MissionEditor/SectionHeader.qml</file>
<file alias="QGroundControl/Controls/SectionHeader.qml">src/PlanView/SectionHeader.qml</file>
<file alias="QGroundControl/Controls/SetupPage.qml">src/AutoPilotPlugins/Common/SetupPage.qml</file>
<file alias="QGroundControl/Controls/SignalStrength.qml">src/ui/toolbar/SignalStrength.qml</file>
<file alias="QGroundControl/Controls/SimpleItemMapVisual.qml">src/MissionEditor/SimpleItemMapVisual.qml</file>
<file alias="QGroundControl/Controls/SimpleItemMapVisual.qml">src/PlanView/SimpleItemMapVisual.qml</file>
<file alias="QGroundControl/Controls/SliderSwitch.qml">src/QmlControls/SliderSwitch.qml</file>
<file alias="QGroundControl/Controls/SubMenuButton.qml">src/QmlControls/SubMenuButton.qml</file>
<file alias="QGroundControl/Controls/SurveyMapVisual.qml">src/MissionEditor/SurveyMapVisual.qml</file>
<file alias="QGroundControl/Controls/SurveyMapVisual.qml">src/PlanView/SurveyMapVisual.qml</file>
<file alias="QGroundControl/Controls/VehicleRotationCal.qml">src/QmlControls/VehicleRotationCal.qml</file>
<file alias="QGroundControl/Controls/VehicleSummaryRow.qml">src/QmlControls/VehicleSummaryRow.qml</file>
<file alias="QGroundControl/Controls/ToolStrip.qml">src/QmlControls/ToolStrip.qml</file>
Expand Down Expand Up @@ -147,7 +147,7 @@
<file alias="QGroundControl/FlightMap/QGCCompassWidget.qml">src/FlightMap/Widgets/QGCCompassWidget.qml</file>
<file alias="QGCInstrumentWidget.qml">src/FlightMap/Widgets/QGCInstrumentWidget.qml</file>
<file alias="QGCInstrumentWidgetAlternate.qml">src/FlightMap/Widgets/QGCInstrumentWidgetAlternate.qml</file>
<file alias="QGroundControl/FlightMap/QGCMapPolygonControls.qml">src/MissionEditor/QGCMapPolygonControls.qml</file>
<file alias="QGroundControl/FlightMap/QGCMapPolygonControls.qml">src/PlanView/QGCMapPolygonControls.qml</file>
<file alias="QGroundControl/FlightMap/QGCPitchIndicator.qml">src/FlightMap/Widgets/QGCPitchIndicator.qml</file>
<file alias="QGroundControl/FlightMap/QGCVideoBackground.qml">src/FlightMap/QGCVideoBackground.qml</file>
<file alias="QGroundControl/FlightMap/qmldir">src/FlightMap/qmldir</file>
Expand All @@ -168,10 +168,10 @@
<file alias="SerialSettings.qml">src/ui/preferences/SerialSettings.qml</file>
<file alias="SetupParameterEditor.qml">src/VehicleSetup/SetupParameterEditor.qml</file>
<file alias="SetupView.qml">src/VehicleSetup/SetupView.qml</file>
<file alias="SimpleItemEditor.qml">src/MissionEditor/SimpleItemEditor.qml</file>
<file alias="SurveyItemEditor.qml">src/MissionEditor/SurveyItemEditor.qml</file>
<file alias="FWLandingPatternEditor.qml">src/MissionEditor/FWLandingPatternEditor.qml</file>
<file alias="MissionSettingsEditor.qml">src/MissionEditor/MissionSettingsEditor.qml</file>
<file alias="SimpleItemEditor.qml">src/PlanView/SimpleItemEditor.qml</file>
<file alias="SurveyItemEditor.qml">src/PlanView/SurveyItemEditor.qml</file>
<file alias="FWLandingPatternEditor.qml">src/PlanView/FWLandingPatternEditor.qml</file>
<file alias="MissionSettingsEditor.qml">src/PlanView/MissionSettingsEditor.qml</file>
<file alias="TcpSettings.qml">src/ui/preferences/TcpSettings.qml</file>
<file alias="test.qml">src/test.qml</file>
<file alias="UdpSettings.qml">src/ui/preferences/UdpSettings.qml</file>
Expand Down
48 changes: 28 additions & 20 deletions src/FlightDisplay/FlightDisplayViewMap.qml
Original file line number Diff line number Diff line change
Expand Up @@ -34,42 +34,54 @@ FlightMap {
property var qgcView ///< QGCView control which contains this map

property var _activeVehicle: QGroundControl.multiVehicleManager.activeVehicle
property bool _activeVehicleCoordinateValid: _activeVehicle ? _activeVehicle.coordinateValid : false
property var activeVehicleCoordinate: _activeVehicle ? _activeVehicle.coordinate : QtPositioning.coordinate()
property var _activeVehicleCoordinate: _activeVehicle ? _activeVehicle.coordinate : QtPositioning.coordinate()
property var _gotoHereCoordinate: QtPositioning.coordinate()
property int _retaskSequence: 0
property real _toolButtonTopMargin: parent.height - ScreenTools.availableHeight + (ScreenTools.defaultFontPixelHeight / 2)

property bool _disableVehicleTracking: false
property bool _keepVehicleCentered: _mainIsMap ? false : true
property bool _followVehicleSetting: true ///< User facing setting for follow vehicle
property bool _followVehicle: _followVehicleSetting && _activeVehicleCoordinateValid ///< Control map follow vehicle functionality
property bool _firstVehiclePosition: true
property bool _firstVehiclePositionReceived: false
property bool _userPanned: false

Component.onCompleted: {
QGroundControl.flightMapPosition = center
QGroundControl.flightMapZoom = zoomLevel
possibleCenterToGCSPosition()
}

// Track last known map position and zoom in settings
onZoomLevelChanged: QGroundControl.flightMapZoom = zoomLevel
onCenterChanged: QGroundControl.flightMapPosition = center

// When the user pans the map we leave things alone until the panRecenterTimer fires
// We move the map to the gcs position id:
// - We don't have a vehicle position yet
// - The user has not futzed with the map
onGcsPositionChanged: possibleCenterToGCSPosition()

function possibleCenterToGCSPosition() {
if (!_firstVehiclePositionReceived && !_userPanned && gcsPosition.isValid) {
center = gcsPosition
}
}

// When the user pans the map we stop responding to vehicle coordinate updates until the panRecenterTimer fires
Connections {
target: gesture

onPanFinished: {
_userPanned = true
_disableVehicleTracking = true
panRecenterTimer.start()
}

onFlickFinished: {
_userPanned = true
_disableVehicleTracking = true
panRecenterTimer.start()
}
}

onCenterChanged: QGroundControl.flightMapPosition = center

function pointInRect(point, rect) {
return point.x > rect.x &&
point.x < rect.x + rect.width &&
Expand Down Expand Up @@ -100,22 +112,22 @@ FlightMap {
}

function recenterNeeded() {
var vehiclePoint = flightMap.fromCoordinate(activeVehicleCoordinate, false /* clipToViewport */)
var vehiclePoint = flightMap.fromCoordinate(_activeVehicleCoordinate, false /* clipToViewport */)
var centerViewport = Qt.rect(0, 0, width, height)
return !pointInRect(vehiclePoint, centerViewport)
}

function updateMapToVehiclePosition() {
if (_followVehicle && !_disableVehicleTracking) {
if (_activeVehicleCoordinate.isValid && !_disableVehicleTracking) {
if (_keepVehicleCentered) {
_firstVehiclePosition = true
flightMap.center = activeVehicleCoordinate
_firstVehiclePositionReceived = true
flightMap.center = _activeVehicleCoordinate
} else {
if (_firstVehiclePosition) {
_firstVehiclePosition = false
flightMap.center = activeVehicleCoordinate
if (!_firstVehiclePositionReceived) {
_firstVehiclePositionReceived = true
flightMap.center = _activeVehicleCoordinate
} else if (recenterNeeded()) {
animatedMapRecenter(flightMap.center, activeVehicleCoordinate)
animatedMapRecenter(flightMap.center, _activeVehicleCoordinate)
}
}
}
Expand Down Expand Up @@ -266,10 +278,6 @@ FlightMap {
CenterMapDropPanel {
map: _flightMap
fitFunctions: mapFitFunctions
showFollowVehicle: true
followVehicle: _followVehicleSetting

onFollowVehicleChanged: _followVehicleSetting = followVehicle
}
}

Expand Down
55 changes: 20 additions & 35 deletions src/FlightMap/FlightMap.qml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@
*
****************************************************************************/


/**
* @file
* @brief QGC Map Background
* @author Gus Grubba <[email protected]>
*/

import QtQuick 2.3
import QtQuick.Controls 1.2
import QtLocation 5.3
Expand All @@ -27,34 +20,21 @@ import QGroundControl.ScreenTools 1.0
import QGroundControl.MultiVehicleManager 1.0
import QGroundControl.Vehicle 1.0
import QGroundControl.Mavlink 1.0
import QGroundControl.QGCPositionManager 1.0

Map {
id: _map

zoomLevel: QGroundControl.flightMapZoom
center: QGroundControl.flightMapPosition
gesture.flickDeceleration: 3000
plugin: Plugin { name: "QGroundControl" }

property string mapName: 'defaultMap'
property bool isSatelliteMap: activeMapType.name.indexOf("Satellite") > -1 || activeMapType.name.indexOf("Hybrid") > -1
property var gcsPosition: QtPositioning.coordinate()

readonly property real maxZoomLevel: 20
property variant scaleLengths: [5, 10, 25, 50, 100, 150, 250, 500, 1000, 2000, 5000, 10000, 20000, 50000, 100000, 200000, 500000, 1000000, 2000000]

function formatDistance(meters)
{
var dist = Math.round(meters)
if (dist > 1000 ){
if (dist > 100000){
dist = Math.round(dist / 1000)
}
else{
dist = Math.round(dist / 100)
dist = dist / 10
}
dist = dist + " km"
}
else{
dist = dist + " m"
}
return dist
}

function setVisibleRegion(region) {
// This works around a bug on Qt where if you set a visibleRegion and then the user moves or zooms the map
Expand All @@ -64,13 +44,18 @@ Map {
_map.visibleRegion = region
}

zoomLevel: 18
center: QGroundControl.lastKnownHomePosition
gesture.flickDeceleration: 3000
ExclusiveGroup { id: mapTypeGroup }

plugin: Plugin { name: "QGroundControl" }
// Update ground station position
Connections {
target: QGroundControl.qgcPositionManger

ExclusiveGroup { id: mapTypeGroup }
onLastPositionUpdated: {
if (valid && lastPosition.latitude && Math.abs(lastPosition.latitude) > 0.001 && lastPosition.longitude && Math.abs(lastPosition.longitude) > 0.001) {
gcsPosition = QtPositioning.coordinate(lastPosition.latitude,lastPosition.longitude)
}
}
}

function updateActiveMapType() {
var settings = QGroundControl.settingsManager.flightMapSettings
Expand Down Expand Up @@ -99,10 +84,10 @@ Map {
MapQuickItem {
anchorPoint.x: sourceItem.anchorPointX
anchorPoint.y: sourceItem.anchorPointY
visible: mainWindow.gcsPosition.isValid
coordinate: mainWindow.gcsPosition
visible: gcsPosition.isValid
coordinate: gcsPosition
sourceItem: MissionItemIndexLabel {
label: "Q"
label: "Q"
}
}
} // Map
Loading

0 comments on commit cff65eb

Please sign in to comment.