Commit abbb4d4c authored by Gus Grubba's avatar Gus Grubba

Set takeoff position

Add flight plan deletion
parent b3c506ed
......@@ -228,6 +228,35 @@ AirMapFlightPlanManager::_pollBriefing()
});
}
//-----------------------------------------------------------------------------
void
AirMapFlightPlanManager::_deleteFlightPlan()
{
if(_flightPlan.isEmpty()) {
qCDebug(AirMapManagerLog) << "Delete non existing flight plan";
return;
}
qCDebug(AirMapManagerLog) << "Deleting flight plan";
_state = State::FlightDelete;
std::weak_ptr<LifetimeChecker> isAlive(_instance);
FlightPlans::Delete::Parameters params;
params.authorization = _shared.loginToken().toStdString();
params.id = _flightPlan.toStdString();
//-- Delete flight plan
_shared.client()->flight_plans().delete_(params, [this, isAlive](const FlightPlans::Delete::Result& result) {
if (!isAlive.lock()) return;
if (_state != State::FlightDelete) return;
if (result) {
_flightPlan.clear();
qCDebug(AirMapManagerLog) << "Flight plan deleted";
_state = State::Idle;
} else {
QString description = QString::fromStdString(result.error().description() ? result.error().description().get() : "");
emit error("Flight Plan deletion failed", QString::fromStdString(result.error().message()), description);
}
});
}
//-----------------------------------------------------------------------------
void
AirMapFlightPlanManager::_missionBoundingCubeChanged()
......
......@@ -40,6 +40,7 @@ private slots:
private:
void _uploadFlightPlan ();
void _createFlightPlan ();
void _deleteFlightPlan ();
private:
enum class State {
......@@ -47,6 +48,7 @@ private:
GetPilotID,
FlightUpload,
FlightPolling,
FlightDelete
};
struct Flight {
......
......@@ -2018,6 +2018,7 @@ void MissionController::setCurrentPlanViewIndex(int sequenceNumber, bool force)
void MissionController::_updateTimeout()
{
QGeoCoordinate firstCoordinate;
QGeoCoordinate takeoffCoordinate;
QGCGeoBoundingCube boundingCube;
double north = 0.0;
......@@ -2033,11 +2034,14 @@ void MissionController::_updateTimeout()
if(pSimpleItem) {
switch(pSimpleItem->command()) {
case MAV_CMD_NAV_TAKEOFF:
takeoffCoordinate = pSimpleItem->coordinate();
// Fall through
case MAV_CMD_NAV_WAYPOINT:
case MAV_CMD_NAV_LAND:
if(pSimpleItem->coordinate().isValid()) {
if(pSimpleItem->command() == MAV_CMD_NAV_TAKEOFF) {
takeoffCoordinate = pSimpleItem->coordinate();
} else if(!firstCoordinate.isValid()) {
firstCoordinate = pSimpleItem->coordinate();
}
double lat = pSimpleItem->coordinate().latitude() + 90.0;
double lon = pSimpleItem->coordinate().longitude() + 180.0;
double alt = pSimpleItem->coordinate().altitude();
......@@ -2058,6 +2062,9 @@ void MissionController::_updateTimeout()
if(pComplexItem) {
QGCGeoBoundingCube bc = pComplexItem->boundingCube();
if(bc.isValid()) {
if(!firstCoordinate.isValid() && pComplexItem->coordinate().isValid()) {
firstCoordinate = pComplexItem->coordinate();
}
north = fmax(north, bc.pointNW.latitude() + 90.0);
south = fmin(south, bc.pointSE.latitude() + 90.0);
east = fmax(east, bc.pointNW.longitude() + 180.0);
......@@ -2068,6 +2075,15 @@ void MissionController::_updateTimeout()
}
}
}
//-- Figure out where this thing is taking off from
if(!takeoffCoordinate.isValid()) {
if(firstCoordinate.isValid()) {
takeoffCoordinate = firstCoordinate;
} else {
takeoffCoordinate = plannedHomePosition();
}
}
//-- Build bounding "cube"
boundingCube = QGCGeoBoundingCube(
QGeoCoordinate(north - 90.0, west - 180.0, minAlt),
QGeoCoordinate(south - 90.0, east - 180.0, maxAlt));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment