diff --git a/qgroundcontrol.qrc b/qgroundcontrol.qrc index a5ec028432a1104eaec95a265488f52105dcb3a1..4291c82652c4d8d9345cf9197c9888a6382b8c60 100644 --- a/qgroundcontrol.qrc +++ b/qgroundcontrol.qrc @@ -136,6 +136,7 @@ src/ui/qmlcommon/QGCWaypointEditor.qml src/ui/qmlcommon/qmldir src/ui/qmlcommon/QGCWaypoint.qml + src/ui/qmlcommon/VehicleMapItem.qml resources/LeftArrow.svg diff --git a/src/Vehicle/MultiVehicleManager.cc b/src/Vehicle/MultiVehicleManager.cc index 6dd92e73c1ed3ab4dd335b3ae9a37728643af957..c3b741cf90b94cfb2aeb8a3b03dbdaa944e2c415 100644 --- a/src/Vehicle/MultiVehicleManager.cc +++ b/src/Vehicle/MultiVehicleManager.cc @@ -229,3 +229,14 @@ QList MultiVehicleManager::vehicles(void) return list; } + +QVariantList MultiVehicleManager::vehiclesAsVariants(void) +{ + QVariantList list; + + foreach (Vehicle* vehicle, _vehicleMap) { + list += QVariant::fromValue(vehicle); + } + + return list; +} diff --git a/src/Vehicle/MultiVehicleManager.h b/src/Vehicle/MultiVehicleManager.h index e1bd8e5d156d31365a202dd02f51cc7b56cc0d0f..67ac1918f872772c183f089a615eafc986641a6b 100644 --- a/src/Vehicle/MultiVehicleManager.h +++ b/src/Vehicle/MultiVehicleManager.h @@ -42,6 +42,7 @@ public: Q_PROPERTY(bool activeVehicleAvailable READ activeVehicleAvailable NOTIFY activeVehicleAvailableChanged) Q_PROPERTY(bool parameterReadyVehicleAvailable READ parameterReadyVehicleAvailable NOTIFY parameterReadyVehicleAvailableChanged) Q_PROPERTY(Vehicle* activeVehicle READ activeVehicle WRITE setActiveVehicle NOTIFY activeVehicleChanged) + Q_PROPERTY(QVariantList vehicles READ vehiclesAsVariants CONSTANT) // Property accessors bool activeVehicleAvailable(void) { return _activeVehicleAvailable; } @@ -64,6 +65,7 @@ public: UAS* activeUas(void) { return _activeVehicle ? _activeVehicle->uas() : NULL; } QList vehicles(void); + QVariantList vehiclesAsVariants(void); UASWaypointManager* activeWaypointManager(void); diff --git a/src/Vehicle/Vehicle.cc b/src/Vehicle/Vehicle.cc index 4888833614c577797b7917bb637634a8ca61810f..ebe69d2c5be202716d34b84bc463937a9d48325f 100644 --- a/src/Vehicle/Vehicle.cc +++ b/src/Vehicle/Vehicle.cc @@ -45,6 +45,14 @@ Vehicle::Vehicle(LinkInterface* link, int vehicleId, MAV_AUTOPILOT firmwareType) _uas = new UAS(MAVLinkProtocol::instance(), this); + setLatitude(_uas->getLatitude()); + setLongitude(_uas->getLongitude()); + _setYaw(_uas->getYaw()); + + connect(_uas, &UAS::latitudeChanged, this, &Vehicle::setLatitude); + connect(_uas, &UAS::longitudeChanged, this, &Vehicle::setLongitude); + connect(_uas, &UAS::yawChanged, this, &Vehicle::_setYaw); + _firmwarePlugin = FirmwarePluginManager::instance()->firmwarePluginForAutopilot(firmwareType); _autopilotPlugin = AutoPilotPluginManager::instance()->newAutopilotPluginForVehicle(this); } @@ -139,3 +147,20 @@ QList Vehicle::links(void) return list; } + +void Vehicle::setLatitude(double latitude) +{ + _geoCoordinate.setLatitude(latitude); + emit coordinateChanged(_geoCoordinate); +} + +void Vehicle::setLongitude(double longitude){ + _geoCoordinate.setLongitude(longitude); + emit coordinateChanged(_geoCoordinate); +} + +void Vehicle::_setYaw(double yaw) +{ + _heading = yaw * (180.0 / M_PI); + emit headingChanged(_heading); +} \ No newline at end of file diff --git a/src/Vehicle/Vehicle.h b/src/Vehicle/Vehicle.h index 389974f2502c580ab85d177b9fc0e2cc16d619f3..0573924d8bdd5ae471755396819568ef36ae1c45 100644 --- a/src/Vehicle/Vehicle.h +++ b/src/Vehicle/Vehicle.h @@ -28,6 +28,7 @@ #define Vehicle_H #include +#include #include "LinkInterface.h" #include "QGCMAVLink.h" @@ -47,7 +48,11 @@ public: Q_PROPERTY(int id READ id CONSTANT) Q_PROPERTY(AutoPilotPlugin* autopilot MEMBER _autopilotPlugin CONSTANT) - + + Q_PROPERTY(QGeoCoordinate coordinate MEMBER _geoCoordinate NOTIFY coordinateChanged) + + Q_PROPERTY(double heading MEMBER _heading NOTIFY headingChanged) + // Property accesors int id(void) { return _id; } MAV_AUTOPILOT firmwareType(void) { return _firmwareType; } @@ -63,8 +68,14 @@ public: QList links(void); +public slots: + void setLatitude(double latitude); + void setLongitude(double longitude); + signals: void allLinksDisconnected(void); + void coordinateChanged(QGeoCoordinate coordinate); + void headingChanged(double heading); /// Used internally to move sendMessage call to main thread void _sendMessageOnThread(mavlink_message_t message); @@ -73,6 +84,7 @@ private slots: void _mavlinkMessageReceived(LinkInterface* link, mavlink_message_t message); void _linkDisconnected(LinkInterface* link); void _sendMessage(mavlink_message_t message); + void _setYaw(double yaw); private: bool _containsLink(LinkInterface* link); @@ -90,6 +102,10 @@ private: QList _links; UAS* _uas; + + QGeoCoordinate _geoCoordinate; + + double _heading; }; #endif diff --git a/src/ui/qmlcommon/QGCMapBackground.qml b/src/ui/qmlcommon/QGCMapBackground.qml index b82be7958e54e66d3045340333232acfe2cb197c..472698bb70ebe0bebdc47164b7e66219840bb5a2 100644 --- a/src/ui/qmlcommon/QGCMapBackground.qml +++ b/src/ui/qmlcommon/QGCMapBackground.qml @@ -32,10 +32,12 @@ import QtQuick.Controls 1.3 import QtLocation 5.3 import QtPositioning 5.3 -import QGroundControl.Controls 1.0 -import QGroundControl.FlightControls 1.0 -import QGroundControl.ScreenTools 1.0 -import QGroundControl.MavManager 1.0 +import QGroundControl.Controls 1.0 +import QGroundControl.FlightControls 1.0 +import QGroundControl.ScreenTools 1.0 +import QGroundControl.MavManager 1.0 +import QGroundControl.MultiVehicleManager 1.0 +import QGroundControl.Vehicle 1.0 Item { id: root @@ -47,6 +49,7 @@ Item { property real heading: 0 property bool alwaysNorth: true property bool interactive: true + property bool showVehicles: true property bool showWaypoints: false property string mapName: 'defaultMap' property alias mapItem: map @@ -58,6 +61,9 @@ Item { map.zoomLevel = 18 map.markers = [] mapTypeMenu.update(); + if (showVehicles) { + addExistingVehicles() + } } //-- Menu to select supported map types @@ -153,6 +159,44 @@ Item { } } + property var vehicles: [] ///< List of known vehicles + property var vehicleMapItems: [] ///< List of know vehicle map items + + function addVehicle(vehicle) { + var qmlItemTemplate = "VehicleMapItem { " + + "coordinate: vehicles[%1].coordinate; " + + "heading: vehicles[%1].heading " + + "}" + + var i = vehicles.length + qmlItemTemplate = qmlItemTemplate.replace("%1", i) + qmlItemTemplate = qmlItemTemplate.replace("%1", i) + + vehicles.push(vehicle) + var mapItem = Qt.createQmlObject (qmlItemTemplate, map) + vehicleMapItems.push(mapItem) + + mapItem.z = map.z + 1 + map.addMapItem(mapItem) + } + + function removeVehicle(vehicle) { + for (var i=0; i + +This file is part of the QGROUNDCONTROL project + + QGROUNDCONTROL is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + QGROUNDCONTROL is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QGROUNDCONTROL. If not, see . + +======================================================================*/ + +/// @file +/// @author Don Gagne + +import QtQuick 2.4 +import QtLocation 5.3 + +import QGroundControl.ScreenTools 1.0 + +/// Marker for displaying a vehicle location on the map +MapQuickItem { + property real heading: 0 + + anchorPoint.x: vehicleIcon.width / 2 + anchorPoint.y: vehicleIcon.height / 2 + + sourceItem: Image { + id: vehicleIcon + source: "/qmlimages/compassInstrumentAirplane.svg" + mipmap: true + width: ScreenTools.defaultFontPixelHeight * 4 + fillMode: Image.PreserveAspectFit + + transform: Rotation { + origin.x: vehicleIcon.width / 2 + origin.y: vehicleIcon.height / 2 + angle: heading + } + } +} diff --git a/src/ui/qmlcommon/qmldir b/src/ui/qmlcommon/qmldir index 7bd0f9046a03ffe39d30769a79535b77c4f527b5..e7929ffb3c28dd53b4fda28f8363a798eddda76a 100644 --- a/src/ui/qmlcommon/qmldir +++ b/src/ui/qmlcommon/qmldir @@ -17,3 +17,4 @@ QGCSpeedWidget 1.0 QGCSpeedWidget.qml QGCVideoBackground 1.0 QGCVideoBackground.qml QGCWaypoint 1.0 QGCWaypoint.qml QGCWaypointEditor 1.0 QGCWaypointEditor.qml +VehicleMapItem 1.0 VehicleMapItem.qml diff --git a/src/ui/uas/UASQuickView.cc b/src/ui/uas/UASQuickView.cc index 5ec115f17f8f9826f6dbcf2224849b38f591867e..b52ab4a71d23f6f9146524fcb28533c6f3d689c8 100644 --- a/src/ui/uas/UASQuickView.cc +++ b/src/ui/uas/UASQuickView.cc @@ -248,11 +248,11 @@ void UASQuickView::updateTimerTick() void UASQuickView::_activeVehicleChanged(Vehicle* vehicle) { - if (uas) { + if (uas || !vehicle) { return; } this->uas = vehicle->uas(); - connect(uas,SIGNAL(valueChanged(int,QString,QString,QVariant,quint64)),this,SLOT(valueChanged(int,QString,QString,QVariant,quint64))); + connect(uas, SIGNAL(valueChanged(int,QString,QString,QVariant,quint64)),this,SLOT(valueChanged(int,QString,QString,QVariant,quint64))); } void UASQuickView::addSource(MAVLinkDecoder *decoder) {