diff --git a/QGCApplication.pro b/QGCApplication.pro index 46557fc9d2f086cba8c4f504c06987996e396db4..16dda54832d070104a0e5f5c4f8182fcbd331721 100644 --- a/QGCApplication.pro +++ b/QGCApplication.pro @@ -260,9 +260,11 @@ HEADERS += \ src/QGCQuickWidget.h \ src/QGCSingleton.h \ src/QGCTemporaryFile.h \ + src/QmlControls/CoordinateVector.h \ src/QmlControls/MavlinkQmlSingleton.h \ src/QmlControls/ParameterEditorController.h \ src/QmlControls/ScreenToolsController.h \ + src/QmlControls/QGCQGeoCoordinate.h \ src/QmlControls/QGroundControlQmlGlobal.h \ src/QmlControls/QmlObjectListModel.h \ src/SerialPortIds.h \ @@ -390,8 +392,10 @@ SOURCES += \ src/QGCQuickWidget.cc \ src/QGCSingleton.cc \ src/QGCTemporaryFile.cc \ + src/QmlControls/CoordinateVector.cc \ src/QmlControls/ParameterEditorController.cc \ src/QmlControls/ScreenToolsController.cc \ + src/QmlControls/QGCQGeoCoordinate.cc \ src/QmlControls/QGroundControlQmlGlobal.cc \ src/QmlControls/QmlObjectListModel.cc \ src/uas/FileManager.cc \ diff --git a/src/FlightDisplay/FlightDisplayView.qml b/src/FlightDisplay/FlightDisplayView.qml index 5f476822c4e12043b165dfa04c31d604e7bcfc4c..f0159577d60e283dfa72a6a8f8c2039fe4f1524d 100644 --- a/src/FlightDisplay/FlightDisplayView.qml +++ b/src/FlightDisplay/FlightDisplayView.qml @@ -120,6 +120,22 @@ Item { visible: _activeVehicle ? _activeVehicle.homePositionAvailable : false } + // Add trajectory points to the map + MapItemView { + model: multiVehicleManager.activeVehicle ? multiVehicleManager.activeVehicle.trajectoryPoints : 0 + + delegate: + MapPolyline { + line.width: 3 + line.color: "orange" + + path: [ + { latitude: object.coordinate1.latitude, longitude: object.coordinate1.longitude }, + { latitude: object.coordinate2.latitude, longitude: object.coordinate2.longitude }, + ] + } + } + // Add the vehicles to the map MapItemView { model: multiVehicleManager.vehicles diff --git a/src/QGCApplication.cc b/src/QGCApplication.cc index 0e313c377b79ea476041dd3591a139398ecc959c..e192efb9d32dcb05430ec1ad98fedbef391e9139 100644 --- a/src/QGCApplication.cc +++ b/src/QGCApplication.cc @@ -84,6 +84,8 @@ #include "QGroundControlQmlGlobal.h" #include "HomePositionManager.h" #include "FlightMapSettings.h" +#include "QGCQGeoCoordinate.h" +#include "CoordinateVector.h" #ifndef __ios__ #include "SerialLink.h" @@ -343,6 +345,8 @@ void QGCApplication::_initCommon(void) qmlRegisterUncreatableType ("QGroundControl.JoystickManager", 1, 0, "JoystickManager", "Reference only"); qmlRegisterUncreatableType ("QGroundControl.JoystickManager", 1, 0, "Joystick", "Reference only"); qmlRegisterUncreatableType ("QGroundControl", 1, 0, "QmlObjectListModel", "Reference only"); + qmlRegisterUncreatableType ("QGroundControl", 1, 0, "QGCQGeoCoordinate", "Reference only"); + qmlRegisterUncreatableType ("QGroundControl", 1, 0, "CoordinateVector", "Reference only"); qmlRegisterType ("QGroundControl.Controllers", 1, 0, "ViewWidgetController"); qmlRegisterType ("QGroundControl.Controllers", 1, 0, "ParameterEditorController"); diff --git a/src/QmlControls/CoordinateVector.cc b/src/QmlControls/CoordinateVector.cc new file mode 100644 index 0000000000000000000000000000000000000000..8f6379b5f1f0bb00bf7086a9eed813fed6748fa2 --- /dev/null +++ b/src/QmlControls/CoordinateVector.cc @@ -0,0 +1,54 @@ +/*===================================================================== + + QGroundControl Open Source Ground Control Station + + (c) 2009, 2015 QGROUNDCONTROL PROJECT + + 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 + +#include "CoordinateVector.h" + +CoordinateVector::CoordinateVector(QObject* parent) + : QObject(parent) +{ + +} + +CoordinateVector::CoordinateVector(const QGeoCoordinate& coordinate1, const QGeoCoordinate& coordinate2, QObject* parent) + : QObject(parent) + , _coordinate1(coordinate1) + , _coordinate2(coordinate2) +{ + +} + +CoordinateVector::~CoordinateVector() +{ + +} + +void CoordinateVector::setCoordinates(const QGeoCoordinate& coordinate1, const QGeoCoordinate& coordinate2) +{ + _coordinate1 = coordinate1; + _coordinate2 = coordinate2; + emit coordinate1Changed(_coordinate1); + emit coordinate2Changed(_coordinate2); +} diff --git a/src/QmlControls/CoordinateVector.h b/src/QmlControls/CoordinateVector.h new file mode 100644 index 0000000000000000000000000000000000000000..390dfd3691b869067a8cb03f228f9f525ad40f58 --- /dev/null +++ b/src/QmlControls/CoordinateVector.h @@ -0,0 +1,53 @@ +/*===================================================================== + + QGroundControl Open Source Ground Control Station + + (c) 2009, 2015 QGROUNDCONTROL PROJECT + + 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 . + + ======================================================================*/ + +#ifndef CoordinateVector_H +#define CoordinateVector_H + +#include +#include + +class CoordinateVector : public QObject +{ + Q_OBJECT + +public: + CoordinateVector(QObject* parent = NULL); + CoordinateVector(const QGeoCoordinate& coordinate1, const QGeoCoordinate& coordinate2, QObject* parent = NULL); + ~CoordinateVector(); + + Q_PROPERTY(QGeoCoordinate coordinate1 MEMBER _coordinate1 NOTIFY coordinate1Changed) + Q_PROPERTY(QGeoCoordinate coordinate2 MEMBER _coordinate2 NOTIFY coordinate2Changed) + + void setCoordinates(const QGeoCoordinate& coordinate1, const QGeoCoordinate& coordinate2); + +signals: + void coordinate1Changed(QGeoCoordinate coordinate); + void coordinate2Changed(QGeoCoordinate coordinate); + +private: + QGeoCoordinate _coordinate1; + QGeoCoordinate _coordinate2; +}; + +#endif diff --git a/src/QmlControls/QGCQGeoCoordinate.cc b/src/QmlControls/QGCQGeoCoordinate.cc new file mode 100644 index 0000000000000000000000000000000000000000..56e0b4902907876785215879a751c21b4d2f68ae --- /dev/null +++ b/src/QmlControls/QGCQGeoCoordinate.cc @@ -0,0 +1,51 @@ +/*===================================================================== + + QGroundControl Open Source Ground Control Station + + (c) 2009, 2015 QGROUNDCONTROL PROJECT + + 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 + +#include "QGCQGeoCoordinate.h" + +QGCQGeoCoordinate::QGCQGeoCoordinate(QObject* parent) + : QObject(parent) +{ + +} + +QGCQGeoCoordinate::QGCQGeoCoordinate(const QGeoCoordinate& coordinate, QObject* parent) + : QObject(parent) + , _coordinate(coordinate) +{ + +} + +QGCQGeoCoordinate::~QGCQGeoCoordinate() +{ + +} + +void QGCQGeoCoordinate::setCoordinate(const QGeoCoordinate& coordinate) +{ + _coordinate = coordinate; + emit coordinateChanged(_coordinate); +} diff --git a/src/QmlControls/QGCQGeoCoordinate.h b/src/QmlControls/QGCQGeoCoordinate.h new file mode 100644 index 0000000000000000000000000000000000000000..4cba3d16d107586125335168993ea3183da394aa --- /dev/null +++ b/src/QmlControls/QGCQGeoCoordinate.h @@ -0,0 +1,53 @@ +/*===================================================================== + + QGroundControl Open Source Ground Control Station + + (c) 2009, 2015 QGROUNDCONTROL PROJECT + + 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 . + + ======================================================================*/ + +#ifndef QGCQGeoCoordinate_H +#define QGCQGeoCoordinate_H + +#include +#include + + +/// This class wraps a QGeoCoordinate in a QObject so that it can be used from within a +/// QmlObjectListModel. +class QGCQGeoCoordinate : public QObject +{ + Q_OBJECT + +public: + QGCQGeoCoordinate(QObject* parent = NULL); + QGCQGeoCoordinate(const QGeoCoordinate& coordinate, QObject* parent = NULL); + ~QGCQGeoCoordinate(); + + Q_PROPERTY(QGeoCoordinate coordinate MEMBER _coordinate NOTIFY coordinateChanged) + + void setCoordinate(const QGeoCoordinate& coordinate); + +signals: + void coordinateChanged(QGeoCoordinate coordinate); + +private: + QGeoCoordinate _coordinate; +}; + +#endif diff --git a/src/Vehicle/Vehicle.cc b/src/Vehicle/Vehicle.cc index 78d4377e00d4f2f6274737f28b56e1cae45382a8..578dabfa134197f46b5a89be2f44c473dd956e31 100644 --- a/src/Vehicle/Vehicle.cc +++ b/src/Vehicle/Vehicle.cc @@ -31,6 +31,7 @@ #include "UAS.h" #include "JoystickManager.h" #include "MissionManager.h" +#include "CoordinateVector.h" QGC_LOGGING_CATEGORY(VehicleLog, "VehicleLog") @@ -169,6 +170,9 @@ Vehicle::Vehicle(LinkInterface* link, int vehicleId, MAV_AUTOPILOT firmwareType, _sendMultipleTimer.start(_sendMessageMultipleIntraMessageDelay); connect(&_sendMultipleTimer, &QTimer::timeout, this, &Vehicle::_sendMessageMultipleNext); + + _mapTrajectoryTimer.setInterval(_mapTrajectoryMsecsBetweenPoints); + connect(&_mapTrajectoryTimer, &QTimer::timeout, this, &Vehicle::_addNewMapTrajectoryPoint); } Vehicle::~Vehicle() @@ -257,6 +261,13 @@ void Vehicle::_handleHeartbeat(mavlink_message_t& message) if (_armed != newArmed) { _armed = newArmed; emit armedChanged(_armed); + + // We are transitioning to the armed state, begin tracking trajectory points for the map + if (_armed) { + _mapTrajectoryStart(); + } else { + _mapTrajectoryStop(); + } } if (heartbeat.base_mode != _base_mode || heartbeat.custom_mode != _custom_mode) { @@ -1129,3 +1140,24 @@ void Vehicle::_missionManagerError(int errorCode, const QString& errorMsg) Q_UNUSED(errorCode); qgcApp()->showToolBarMessage(QString("Error during Mission communication with Vehicle: %1").arg(errorMsg)); } + +void Vehicle::_addNewMapTrajectoryPoint(void) +{ + if (_mapTrajectoryHaveFirstCoordinate) { + _mapTrajectoryList.append(new CoordinateVector(_mapTrajectoryLastCoordinate, _geoCoordinate, this)); + } + _mapTrajectoryHaveFirstCoordinate = true; + _mapTrajectoryLastCoordinate = _geoCoordinate; +} + +void Vehicle::_mapTrajectoryStart(void) +{ + _mapTrajectoryHaveFirstCoordinate = false; + _mapTrajectoryList.clear(); + _mapTrajectoryTimer.start(); +} + +void Vehicle::_mapTrajectoryStop() +{ + _mapTrajectoryTimer.stop(); +} diff --git a/src/Vehicle/Vehicle.h b/src/Vehicle/Vehicle.h index 1e29cfcb30be6332b41318852e289dd2fdf14f43..aef3c6c44db938f212aa0ac0fd6d1803019a0db8 100644 --- a/src/Vehicle/Vehicle.h +++ b/src/Vehicle/Vehicle.h @@ -73,6 +73,8 @@ public: Q_PROPERTY(bool missingParameters READ missingParameters NOTIFY missingParametersChanged) + Q_PROPERTY(QmlObjectListModel* trajectoryPoints READ trajectoryPoints CONSTANT) + Q_INVOKABLE QString getMavIconColor(); //-- System Messages @@ -185,6 +187,8 @@ public: bool hilMode(void); void setHilMode(bool hilMode); + QmlObjectListModel* trajectoryPoints(void) { return &_mapTrajectoryList; } + /// Requests the specified data stream from the vehicle /// @param stream Stream which is being requested /// @param rate Rate at which to send stream in Hz @@ -300,6 +304,7 @@ private slots: void _linkDisconnected(LinkInterface* link); void _sendMessage(mavlink_message_t message); void _sendMessageMultipleNext(void); + void _addNewMapTrajectoryPoint(void); void _handleTextMessage (int newCount); /** @brief Attitude from main autopilot / system state */ @@ -335,6 +340,8 @@ private: void _handleHomePosition(mavlink_message_t& message); void _handleHeartbeat(mavlink_message_t& message); void _missionManagerError(int errorCode, const QString& errorMsg); + void _mapTrajectoryStart(void); + void _mapTrajectoryStop(void); bool _isAirplane (); void _addChange (int id); @@ -425,6 +432,12 @@ private: QTimer _sendMultipleTimer; int _nextSendMessageMultipleIndex; + QTimer _mapTrajectoryTimer; + QmlObjectListModel _mapTrajectoryList; + QGeoCoordinate _mapTrajectoryLastCoordinate; + bool _mapTrajectoryHaveFirstCoordinate; + static const int _mapTrajectoryMsecsBetweenPoints = 1000; + // Settings keys static const char* _settingsGroup; static const char* _joystickModeSettingsKey;