Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Q
qgroundcontrol
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Valentin Platzgummer
qgroundcontrol
Commits
f4731132
Commit
f4731132
authored
Feb 16, 2018
by
Gus Grubba
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Attempt and updating a flight plan (API seems broken)
parent
abbb4d4c
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
163 additions
and
19 deletions
+163
-19
AirMapFlightManager.h
src/Airmap/AirMapFlightManager.h
+12
-0
AirMapFlightPlanManager.cc
src/Airmap/AirMapFlightPlanManager.cc
+121
-8
AirMapFlightPlanManager.h
src/Airmap/AirMapFlightPlanManager.h
+11
-2
AirspaceFlightPlanProvider.h
src/AirspaceManagement/AirspaceFlightPlanProvider.h
+16
-6
MissionController.cc
src/MissionManager/MissionController.cc
+3
-3
No files found.
src/Airmap/AirMapFlightManager.h
View file @
f4731132
...
...
@@ -20,6 +20,18 @@
class
MissionItem
;
/*
* TODO: This is here for reference. It will have to modifed quite a bit before it
* can be used. This was the original file that combined both the creation of a
* flight plan and immediate submission of a flight. The flight plan is now handled
* by its own class. This now needs to be made into a proper "Flight Manager".
*/
//-----------------------------------------------------------------------------
/// class to upload a flight
class
AirMapFlightManager
:
public
QObject
,
public
LifetimeChecker
...
...
src/Airmap/AirMapFlightPlanManager.cc
View file @
f4731132
...
...
@@ -29,11 +29,42 @@ AirMapFlightPlanManager::AirMapFlightPlanManager(AirMapSharedState& shared, QObj
,
_shared
(
shared
)
{
connect
(
&
_pollTimer
,
&
QTimer
::
timeout
,
this
,
&
AirMapFlightPlanManager
::
_pollBriefing
);
//-- Set some valid, initial start/end time
_flightStartTime
=
QDateTime
::
currentDateTime
().
addSecs
(
10
*
60
);
_flightEndTime
=
_flightStartTime
.
addSecs
(
30
*
60
);
}
//-----------------------------------------------------------------------------
void
AirMapFlightPlanManager
::
createFlight
(
MissionController
*
missionController
)
AirMapFlightPlanManager
::
setFlightStartTime
(
QDateTime
start
)
{
if
(
_flightStartTime
!=
start
)
{
//-- Can't start in the past
if
(
start
<
QDateTime
::
currentDateTime
())
{
start
=
QDateTime
::
currentDateTime
().
addSecs
(
5
*
60
);
}
_flightStartTime
=
start
;
emit
flightStartTimeChanged
();
}
}
//-----------------------------------------------------------------------------
void
AirMapFlightPlanManager
::
setFlightEndTime
(
QDateTime
end
)
{
if
(
_flightEndTime
!=
end
)
{
//-- End has to be after start
if
(
end
<
_flightStartTime
)
{
end
=
_flightStartTime
.
addSecs
(
30
*
60
);
}
_flightEndTime
=
end
;
emit
flightEndTimeChanged
();
}
}
//-----------------------------------------------------------------------------
void
AirMapFlightPlanManager
::
createFlightPlan
(
MissionController
*
missionController
)
{
if
(
!
_shared
.
client
())
{
qCDebug
(
AirMapManagerLog
)
<<
"No AirMap client instance. Will not create a flight"
;
...
...
@@ -49,7 +80,8 @@ AirMapFlightPlanManager::createFlight(MissionController* missionController)
_createPlan
=
true
;
if
(
!
_controller
)
{
_controller
=
missionController
;
connect
(
missionController
,
&
MissionController
::
missionBoundingCubeChanged
,
this
,
&
AirMapFlightPlanManager
::
_missionBoundingCubeChanged
);
//-- Get notified of mission changes
connect
(
missionController
,
&
MissionController
::
missionBoundingCubeChanged
,
this
,
&
AirMapFlightPlanManager
::
_missionChanged
);
}
}
...
...
@@ -72,11 +104,21 @@ AirMapFlightPlanManager::_createFlightPlan()
_flight
.
coords
.
append
(
QGeoCoordinate
(
bc
.
pointSE
.
latitude
(),
bc
.
pointNW
.
longitude
(),
_flight
.
maxAltitude
));
_flight
.
coords
.
append
(
QGeoCoordinate
(
bc
.
pointNW
.
latitude
(),
bc
.
pointNW
.
longitude
(),
_flight
.
maxAltitude
));
_flight
.
maxAltitude
+=
5
;
// Add a safety buffer
if
(
_flightStartTime
.
isNull
()
||
_flightStartTime
<
QDateTime
::
currentDateTime
())
{
_flightStartTime
=
QDateTime
::
currentDateTime
().
addSecs
(
5
*
60
);
emit
flightStartTimeChanged
();
}
if
(
_flightEndTime
.
isNull
()
||
_flightEndTime
<
_flightStartTime
)
{
_flightEndTime
=
_flightStartTime
.
addSecs
(
30
*
60
);
emit
flightEndTimeChanged
();
}
qCDebug
(
AirMapManagerLog
)
<<
"About to create flight plan"
;
qCDebug
(
AirMapManagerLog
)
<<
"Takeoff: "
<<
_flight
.
takeoffCoord
;
qCDebug
(
AirMapManagerLog
)
<<
"Bounding box:"
<<
bc
.
pointNW
<<
bc
.
pointSE
;
qCDebug
(
AirMapManagerLog
)
<<
"Flight Start:"
<<
_flightStartTime
;
qCDebug
(
AirMapManagerLog
)
<<
"Flight End: "
<<
_flightEndTime
;
return
;
...
...
@@ -102,6 +144,7 @@ AirMapFlightPlanManager::_createFlightPlan()
_state
=
State
::
Idle
;
QString
description
=
QString
::
fromStdString
(
result
.
error
().
description
()
?
result
.
error
().
description
().
get
()
:
""
);
emit
error
(
"Failed to create Flight Plan"
,
QString
::
fromStdString
(
result
.
error
().
message
()),
description
);
return
;
}
});
});
...
...
@@ -129,8 +172,16 @@ AirMapFlightPlanManager::_uploadFlightPlan()
params
.
latitude
=
_flight
.
takeoffCoord
.
latitude
();
params
.
longitude
=
_flight
.
takeoffCoord
.
longitude
();
params
.
pilot
.
id
=
_pilotID
.
toStdString
();
/*
TODO: Convert this to fucking boost
quint64 start = _flightStartTime.toUTC().toMSecsSinceEpoch();
quint64 end = _flightEndTime.toUTC().toMSecsSinceEpoch();
*/
params
.
start_time
=
Clock
::
universal_time
()
+
Minutes
{
5
};
params
.
end_time
=
Clock
::
universal_time
()
+
Hours
{
2
};
// TODO: user-configurable?
params
.
end_time
=
Clock
::
universal_time
()
+
Hours
{
2
};
//-- Rules
AirMapRulesetsManager
*
pRulesMgr
=
dynamic_cast
<
AirMapRulesetsManager
*>
(
qgcApp
()
->
toolbox
()
->
airspaceManager
()
->
ruleSets
());
if
(
pRulesMgr
)
{
...
...
@@ -165,6 +216,70 @@ AirMapFlightPlanManager::_uploadFlightPlan()
});
}
//-----------------------------------------------------------------------------
void
AirMapFlightPlanManager
::
_updateFlightPlan
()
{
qCDebug
(
AirMapManagerLog
)
<<
"Updating flight plan"
;
_state
=
State
::
FlightUpdate
;
std
::
weak_ptr
<
LifetimeChecker
>
isAlive
(
_instance
);
_shared
.
doRequestWithLogin
([
this
,
isAlive
](
const
QString
&
login_token
)
{
if
(
!
isAlive
.
lock
())
return
;
if
(
_state
!=
State
::
FlightUpdate
)
return
;
FlightPlans
::
Update
::
Parameters
params
;
params
.
authorization
=
login_token
.
toStdString
();
params
.
flight_plan
.
id
=
_flightPlan
.
toStdString
();
params
.
flight_plan
.
pilot
.
id
=
_pilotID
.
toStdString
();
//-- TODO: This is broken as the parameters for updating the plan have
// little to do with those used when creating it.
params
.
flight_plan
.
altitude_agl
.
max
=
_flight
.
maxAltitude
;
params
.
flight_plan
.
buffer
=
2.
f
;
params
.
flight_plan
.
takeoff
.
latitude
=
_flight
.
takeoffCoord
.
latitude
();
params
.
flight_plan
.
takeoff
.
longitude
=
_flight
.
takeoffCoord
.
longitude
();
/*
TODO: Convert this to fucking boost
quint64 start = _flightStartTime.toUTC().toMSecsSinceEpoch();
quint64 end = _flightEndTime.toUTC().toMSecsSinceEpoch();
*/
params
.
flight_plan
.
start_time
=
Clock
::
universal_time
()
+
Minutes
{
5
};
params
.
flight_plan
.
end_time
=
Clock
::
universal_time
()
+
Hours
{
2
};
//-- Rules
/*
AirMapRulesetsManager* pRulesMgr = dynamic_cast<AirMapRulesetsManager*>(qgcApp()->toolbox()->airspaceManager()->ruleSets());
if(pRulesMgr) {
foreach(QString ruleset, pRulesMgr->rulesetsIDs()) {
params.flight_plan.rulesets.push_back(ruleset.toStdString());
}
}
*/
//-- Geometry: LineString
Geometry
::
LineString
lineString
;
for
(
const
auto
&
qcoord
:
_flight
.
coords
)
{
Geometry
::
Coordinate
coord
;
coord
.
latitude
=
qcoord
.
latitude
();
coord
.
longitude
=
qcoord
.
longitude
();
lineString
.
coordinates
.
push_back
(
coord
);
}
params
.
flight_plan
.
geometry
=
Geometry
(
lineString
);
//-- Update flight plan
_shared
.
client
()
->
flight_plans
().
update
(
params
,
[
this
,
isAlive
](
const
FlightPlans
::
Update
::
Result
&
result
)
{
if
(
!
isAlive
.
lock
())
return
;
if
(
_state
!=
State
::
FlightUpdate
)
return
;
if
(
result
)
{
qCDebug
(
AirMapManagerLog
)
<<
"Flight plan updated:"
<<
_flightPlan
;
_state
=
State
::
FlightPolling
;
_pollBriefing
();
}
else
{
QString
description
=
QString
::
fromStdString
(
result
.
error
().
description
()
?
result
.
error
().
description
().
get
()
:
""
);
emit
error
(
"Flight Plan creation failed"
,
QString
::
fromStdString
(
result
.
error
().
message
()),
description
);
}
});
});
}
//-----------------------------------------------------------------------------
void
AirMapFlightPlanManager
::
_pollBriefing
()
...
...
@@ -259,7 +374,7 @@ AirMapFlightPlanManager::_deleteFlightPlan()
//-----------------------------------------------------------------------------
void
AirMapFlightPlanManager
::
_mission
BoundingCube
Changed
()
AirMapFlightPlanManager
::
_missionChanged
()
{
//-- Creating a new flight plan?
if
(
_createPlan
)
{
...
...
@@ -267,7 +382,5 @@ AirMapFlightPlanManager::_missionBoundingCubeChanged()
_createFlightPlan
();
}
//-- Plan is being modified
// _updateFlightPlan();
}
src/Airmap/AirMapFlightPlanManager.h
View file @
f4731132
...
...
@@ -27,18 +27,24 @@ public:
AirMapFlightPlanManager
(
AirMapSharedState
&
shared
,
QObject
*
parent
=
nullptr
);
PermitStatus
flightPermitStatus
()
const
override
{
return
_flightPermitStatus
;
}
void
createFlight
(
MissionController
*
missionController
)
override
;
QString
flightID
()
{
return
_flightPlan
;
}
QDateTime
flightStartTime
()
const
override
{
return
_flightStartTime
;
}
QDateTime
flightEndTime
()
const
override
{
return
_flightEndTime
;
}
void
createFlightPlan
(
MissionController
*
missionController
)
override
;
void
setFlightStartTime
(
QDateTime
start
)
override
;
void
setFlightEndTime
(
QDateTime
end
)
override
;
signals:
void
error
(
const
QString
&
what
,
const
QString
&
airmapdMessage
,
const
QString
&
airmapdDetails
);
private
slots
:
void
_pollBriefing
();
void
_mission
BoundingCube
Changed
();
void
_missionChanged
();
private:
void
_uploadFlightPlan
();
void
_updateFlightPlan
();
void
_createFlightPlan
();
void
_deleteFlightPlan
();
...
...
@@ -47,6 +53,7 @@ private:
Idle
,
GetPilotID
,
FlightUpload
,
FlightUpdate
,
FlightPolling
,
FlightDelete
};
...
...
@@ -69,6 +76,8 @@ private:
QString
_pilotID
;
///< Pilot ID in the form "auth0|abc123"
MissionController
*
_controller
=
nullptr
;
bool
_createPlan
=
true
;
QDateTime
_flightStartTime
;
QDateTime
_flightEndTime
;
AirspaceFlightPlanProvider
::
PermitStatus
_flightPermitStatus
=
AirspaceFlightPlanProvider
::
PermitUnknown
;
...
...
src/AirspaceManagement/AirspaceFlightPlanProvider.h
View file @
f4731132
...
...
@@ -15,6 +15,7 @@
*/
#include <QObject>
#include <QDateTime>
class
MissionController
;
...
...
@@ -33,15 +34,24 @@ public:
Q_ENUM
(
PermitStatus
)
AirspaceFlightPlanProvider
(
QObject
*
parent
=
nullptr
);
virtual
~
AirspaceFlightPlanProvider
()
{}
AirspaceFlightPlanProvider
(
QObject
*
parent
=
nullptr
);
virtual
~
AirspaceFlightPlanProvider
()
{}
Q_PROPERTY
(
PermitStatus
flightPermitStatus
READ
flightPermitStatus
NOTIFY
flightPermitStatusChanged
)
///< state of flight permission
Q_PROPERTY
(
PermitStatus
flightPermitStatus
READ
flightPermitStatus
NOTIFY
flightPermitStatusChanged
)
///< State of flight permission
Q_PROPERTY
(
QDateTime
flightStartTime
READ
flightStartTime
WRITE
setFlightStartTime
NOTIFY
flightStartTimeChanged
)
///< Start of flight
Q_PROPERTY
(
QDateTime
flightEndTime
READ
flightEndTime
WRITE
setFlightEndTime
NOTIFY
flightEndTimeChanged
)
///< End of flight
virtual
PermitStatus
flightPermitStatus
()
const
{
return
PermitUnknown
;
}
virtual
void
createFlight
(
MissionController
*
missionController
)
=
0
;
virtual
PermitStatus
flightPermitStatus
()
const
{
return
PermitUnknown
;
}
virtual
QDateTime
flightStartTime
()
const
=
0
;
virtual
QDateTime
flightEndTime
()
const
=
0
;
virtual
void
setFlightStartTime
(
QDateTime
start
)
=
0
;
virtual
void
setFlightEndTime
(
QDateTime
end
)
=
0
;
virtual
void
createFlightPlan
(
MissionController
*
missionController
)
=
0
;
signals:
void
flightPermitStatusChanged
();
void
flightPermitStatusChanged
();
void
flightStartTimeChanged
();
void
flightEndTimeChanged
();
};
src/MissionManager/MissionController.cc
View file @
f4731132
...
...
@@ -203,7 +203,7 @@ void MissionController::_newMissionItemsAvailableFromVehicle(bool removeAllReque
//-- If airspace management enabled, create new flight
#if defined(QGC_AIRMAP_ENABLED)
if
(
qgcApp
()
->
toolbox
()
->
settingsManager
()
->
airMapSettings
()
->
enableAirMap
()
->
rawValue
().
toBool
())
{
qgcApp
()
->
toolbox
()
->
airspaceManager
()
->
flightPlan
()
->
createFlight
(
this
);
qgcApp
()
->
toolbox
()
->
airspaceManager
()
->
flightPlan
()
->
createFlight
Plan
(
this
);
}
#endif
}
...
...
@@ -371,7 +371,7 @@ int MissionController::insertSimpleMissionItem(QGeoCoordinate coordinate, int i)
//-- If airspace management enabled and this is the first item, create new flight
#if defined(QGC_AIRMAP_ENABLED)
if
(
_visualItems
->
count
()
==
2
&&
qgcApp
()
->
toolbox
()
->
settingsManager
()
->
airMapSettings
()
->
enableAirMap
()
->
rawValue
().
toBool
())
{
qgcApp
()
->
toolbox
()
->
airspaceManager
()
->
flightPlan
()
->
createFlight
(
this
);
qgcApp
()
->
toolbox
()
->
airspaceManager
()
->
flightPlan
()
->
createFlight
Plan
(
this
);
}
#endif
...
...
@@ -464,7 +464,7 @@ int MissionController::insertComplexMissionItem(QString itemName, QGeoCoordinate
//-- If airspace management enabled and this is the first item, create new flight
#if defined(QGC_AIRMAP_ENABLED)
if
(
_visualItems
->
count
()
==
2
&&
qgcApp
()
->
toolbox
()
->
settingsManager
()
->
airMapSettings
()
->
enableAirMap
()
->
rawValue
().
toBool
())
{
qgcApp
()
->
toolbox
()
->
airspaceManager
()
->
flightPlan
()
->
createFlight
(
this
);
qgcApp
()
->
toolbox
()
->
airspaceManager
()
->
flightPlan
()
->
createFlight
Plan
(
this
);
}
#endif
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment