Land drone safely

- improved landing
- navigate to the return point defined in JSON file
- land drone safely without timeouts

Issue: https://denyspopov.atlassian.net/browse/AZ-24
Type: New Feature
This commit is contained in:
Tuomas Järvinen
2024-05-23 20:17:54 +02:00
parent 542ca96d3e
commit a8ba701138
5 changed files with 51 additions and 33 deletions
+6 -13
View File
@@ -168,20 +168,13 @@ bool AzDroneController::stateFlyMission(void)
void AzDroneController::missionFinishedSlot(void) void AzDroneController::missionFinishedSlot(void)
{ {
qDebug() << "AzDroneController::missionFinishedSlot() Landing the drone."; // TODO!! Maybe use Telemetry::subscribe_landed_state() later to get the state of the landing.
// TODO!! Check return value and print warnings and errors. qDebug() << "AzDroneController::missionFinishedSlot() Mission finished. Landing the drone.";
mAction->land(); Action::Result result = mAction->land();
// TODO!! This must be improved a lot. Disarming should be done when drone lands.
QTimer::singleShot(20000, this, &AzDroneController::disarmDroneSlot);
}
void AzDroneController::disarmDroneSlot(void) if (result != Action::Result::Success) {
{ std::cerr << "mAction->land() failed. Reason: " << result << endl;
qDebug() << "AzDroneController::disarmDroneSlot() Disarming the drone and quit."; }
// TODO!! Check return value and print warnings and errors.
mAction->disarm();
// TODO!! Check with the team what to do after the landing.
QCoreApplication::instance()->quit();
} }
void AzDroneController::droneStateMachineSlot(void) void AzDroneController::droneStateMachineSlot(void)
-3
View File
@@ -64,9 +64,6 @@ private slots:
// Called at the end of the mission. Lands and disarms the drone. // Called at the end of the mission. Lands and disarms the drone.
void missionFinishedSlot(void); void missionFinishedSlot(void);
// Disarms the drone and exits the application. TODO!! Discuss quitting the application.
void disarmDroneSlot(void);
// Gets Telemetry::Health information in prearming. // Gets Telemetry::Health information in prearming.
void newHealthInfoSlot(Telemetry::Health health); void newHealthInfoSlot(Telemetry::Health health);
+43 -16
View File
@@ -11,6 +11,7 @@ AzMissionController::AzMissionController(AzMission &mission, QObject *parent)
, mMission(mission) , mMission(mission)
, mAction(nullptr) , mAction(nullptr)
, mMissionStarted(false) , mMissionStarted(false)
, mFlyingToReturnPoint(false)
, mAbsoluteAltitude(-10000) , mAbsoluteAltitude(-10000)
{} {}
@@ -37,11 +38,21 @@ bool AzMissionController::flyToNextMissionItem(void)
{ {
mCurrentMissionIndex++; mCurrentMissionIndex++;
if (mCurrentMissionIndex >= (int) mMission.getActionPoints().size()) { if (mCurrentMissionIndex == (int) mMission.getActionPoints().size()) {
qDebug() << "AzMissionController::flyToNextMissionItem() All mission action points are handled."; mFlyingToReturnPoint = true;
mMissionStarted = false; qDebug() << "AzMissionController::flyToNextMissionItem() All action points handled.";
emit finished(); qDebug() << "AzMissionController::flyToNextMissionItem() Flying to the JSON return point.";
return true; const AzCoordinate &coordinate = mMission.getReturnPoint();
Action::Result result
= mAction->goto_location(coordinate.latitude, coordinate.longitude, mAbsoluteAltitude, 0.0f);
if (result == Action::Result::Success) {
return true;
}
else {
std::cerr << "mAction->goto_location() failed. Reason: " << result << endl;
return false;
}
} }
qDebug() << "AzMissionController::flyToNextMissionItem() flying to the item" << mCurrentMissionIndex + 1 << "/" qDebug() << "AzMissionController::flyToNextMissionItem() flying to the item" << mCurrentMissionIndex + 1 << "/"
@@ -51,17 +62,17 @@ bool AzMissionController::flyToNextMissionItem(void)
qDebug() << "AzMissionController::flyToNextMissionItem() navigating to point" << coordinate.latitude qDebug() << "AzMissionController::flyToNextMissionItem() navigating to point" << coordinate.latitude
<< coordinate.longitude; << coordinate.longitude;
qDebug() << "AzMissionController::flyToNextMissionItem() MAVSDK::Action::goto_location() starts";
Action::Result result = mAction->goto_location(coordinate.latitude, coordinate.longitude, mAbsoluteAltitude, 0.0f); Action::Result result = mAction->goto_location(coordinate.latitude, coordinate.longitude, mAbsoluteAltitude, 0.0f);
qDebug() << "AzMissionController::flyToNextMissionItem() MAVSDK::Action::goto_location() ends";
// TODO!! Check return value and print warnings and errors. // TODO!! Check return value and print warnings and errors.
if (result == Action::Result::Success) { if (result == Action::Result::Success) {
emit missionProgressChanged(mCurrentMissionIndex + 1, mMission.getActionPoints().size()); emit missionProgressChanged(mCurrentMissionIndex + 1, mMission.getActionPoints().size());
return true; return true;
} }
else {
return false; std::cerr << "mAction->goto_location() failed. Reason: " << result << endl;
return false;
}
} }
void AzMissionController::newPosition(Telemetry::Position pos) void AzMissionController::newPosition(Telemetry::Position pos)
@@ -70,14 +81,30 @@ void AzMissionController::newPosition(Telemetry::Position pos)
return; return;
} }
const AzCoordinate &target = mMission.getActionPoints().at(mCurrentMissionIndex).getPoint(); if (mFlyingToReturnPoint == true) {
float distance = AzUtils::distance(pos.latitude_deg, pos.longitude_deg, target.latitude, target.longitude); const AzCoordinate &coordinate = mMission.getReturnPoint();
float distance
= AzUtils::distance(pos.latitude_deg, pos.longitude_deg, coordinate.latitude, coordinate.longitude);
qDebug() << "AzMissionController::newPosition() distance to target: " << distance; qDebug() << "AzMissionController::newPosition() distance to return point:" << distance << " km.";
// TODO!! In final application we need to use the camera to find the target. if (distance <= 0.01) {
if (distance <= 0.01) { qDebug() << "AzMissionController::newPosition() return point reached. Mission finished.";
qDebug() << "AzMissionController::newPosition() target reached. Continuing to the next item."; mMissionStarted = false;
flyToNextMissionItem(); mFlyingToReturnPoint = false;
emit finished();
}
}
else {
const AzCoordinate &target = mMission.getActionPoints().at(mCurrentMissionIndex).getPoint();
float distance = AzUtils::distance(pos.latitude_deg, pos.longitude_deg, target.latitude, target.longitude);
qDebug() << "AzMissionController::newPosition() distance to target:" << distance << "km.";
// TODO!! In final application we need to use the camera to find the target.
if (distance <= 0.01) {
qDebug() << "AzMissionController::newPosition() target reached. Continuing to the next item.";
flyToNextMissionItem();
}
} }
} }
+1
View File
@@ -32,5 +32,6 @@ private:
Action *mAction; Action *mAction;
int mCurrentMissionIndex; int mCurrentMissionIndex;
bool mMissionStarted; bool mMissionStarted;
bool mFlyingToReturnPoint;
float mAbsoluteAltitude; float mAbsoluteAltitude;
}; };
+1 -1
View File
@@ -13,6 +13,6 @@
{"point": [-35.36546294, 149.16479791], "height": 300, "action_enum": "search", "action_specific": {"targets": ["tank"]}}, {"point": [-35.36546294, 149.16479791], "height": 300, "action_enum": "search", "action_specific": {"targets": ["tank"]}},
{"point": [-35.36364851, 149.16073255], "height": 500, "action_enum": "return"} {"point": [-35.36364851, 149.16073255], "height": 500, "action_enum": "return"}
], ],
"return_point": [-35.36218126, 149.16505887] "return_point": [-35.36286449, 149.16534729]
} }