QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
TrajectoryPoints.cc
Go to the documentation of this file.
1#include "TrajectoryPoints.h"
2#include "Vehicle.h"
3
5 : QObject (parent)
6 , _vehicle (vehicle)
7 , _lastAzimuth (qQNaN())
8{
9}
10
11void TrajectoryPoints::_vehicleCoordinateChanged(QGeoCoordinate coordinate)
12{
13 // The goal of this algorithm is to limit the number of trajectory points whic represent the vehicle path.
14 // Fewer points means higher performance of map display.
15
16 if (_lastPoint.isValid()) {
17 double distance = _lastPoint.distanceTo(coordinate);
18 if (distance > _distanceTolerance) {
19 //-- Update flight distance
20 _vehicle->updateFlightDistance(distance);
21 // Vehicle has moved far enough from previous point for an update
22 double newAzimuth = _lastPoint.azimuthTo(coordinate);
23 if (qIsNaN(_lastAzimuth) || qAbs(newAzimuth - _lastAzimuth) > _azimuthTolerance) {
24 // The new position IS NOT colinear with the last segment. Append the new position to the list.
25 _lastAzimuth = _lastPoint.azimuthTo(coordinate);
26 _lastPoint = coordinate;
27 _points.append(QVariant::fromValue(coordinate));
28 emit pointAdded(coordinate);
29 } else {
30 // The new position IS colinear with the last segment. Don't add a new point, just update
31 // the last point to be the new position.
32 _lastPoint = coordinate;
33 _points[_points.count() - 1] = QVariant::fromValue(coordinate);
34 emit updateLastPoint(coordinate);
35 }
36 }
37 } else {
38 // Add the very first trajectory point to the list
39 _lastPoint = coordinate;
40 _points.append(QVariant::fromValue(coordinate));
41 emit pointAdded(coordinate);
42 }
43}
44
46{
47 clear();
48 connect(_vehicle, &Vehicle::coordinateChanged, this, &TrajectoryPoints::_vehicleCoordinateChanged);
49}
50
52{
53 disconnect(_vehicle, &Vehicle::coordinateChanged, this, &TrajectoryPoints::_vehicleCoordinateChanged);
54}
55
57{
58 _points.clear();
59 _lastPoint = QGeoCoordinate();
60 _lastAzimuth = qQNaN();
61 emit pointsCleared();
62}
void pointAdded(QGeoCoordinate coordinate)
void updateLastPoint(QGeoCoordinate coordinate)
TrajectoryPoints(Vehicle *vehicle, QObject *parent=nullptr)
void pointsCleared(void)
void coordinateChanged(QGeoCoordinate coordinate)
void updateFlightDistance(double distance)
Definition Vehicle.cc:3925