Unverified Commit 2d706e6c authored by Don Gagne's avatar Don Gagne Committed by GitHub

Merge pull request #6293 from DonLakeFlyer/ArduPlaneStartMission

ArduPlane Start Mission support
parents 1a0b34f1 79b4c383
...@@ -951,7 +951,6 @@ bool APMFirmwarePlugin::_guidedModeTakeoff(Vehicle* vehicle, double altitudeRel) ...@@ -951,7 +951,6 @@ bool APMFirmwarePlugin::_guidedModeTakeoff(Vehicle* vehicle, double altitudeRel)
return false; return false;
} }
// FIXME: Is this needed?
if (!_armVehicleAndValidate(vehicle)) { if (!_armVehicleAndValidate(vehicle)) {
qgcApp()->showMessage(tr("Unable to takeoff: Vehicle failed to arm.")); qgcApp()->showMessage(tr("Unable to takeoff: Vehicle failed to arm."));
return false; return false;
...@@ -966,36 +965,43 @@ bool APMFirmwarePlugin::_guidedModeTakeoff(Vehicle* vehicle, double altitudeRel) ...@@ -966,36 +965,43 @@ bool APMFirmwarePlugin::_guidedModeTakeoff(Vehicle* vehicle, double altitudeRel)
return true; return true;
} }
// FIXME: Review for a better way to do this
void APMFirmwarePlugin::startMission(Vehicle* vehicle) void APMFirmwarePlugin::startMission(Vehicle* vehicle)
{ {
double currentAlt = vehicle->altitudeRelative()->rawValue().toDouble(); if (vehicle->flying()) {
// Vehicle already in the air, we just need to switch to auto
if (!vehicle->flying()) { if (!_setFlightModeAndValidate(vehicle, "Auto")) {
if (_guidedModeTakeoff(vehicle, qQNaN())) { qgcApp()->showMessage(tr("Unable to start mission: Vehicle failed to change to Auto mode."));
}
return;
}
// Wait for vehicle to get off ground before switching to auto (10 seconds) if (vehicle->fixedWing()) {
bool didTakeoff = false; // Fixed wing will automatically start a mission if you switch to Auto while armed
for (int i=0; i<100; i++) { if (!vehicle->armed()) {
if (vehicle->altitudeRelative()->rawValue().toDouble() >= currentAlt + 1.0) { // First switch to flight mode we can arm from
didTakeoff = true; if (!_setFlightModeAndValidate(vehicle, "Guided")) {
break; qgcApp()->showMessage(tr("Unable to start mission: Vehicle failed to change to Guided mode."));
} return;
QGC::SLEEP::msleep(100);
qgcApp()->processEvents(QEventLoop::ExcludeUserInputEvents);
} }
if (!didTakeoff) { if (!_armVehicleAndValidate(vehicle)) {
qgcApp()->showMessage(tr("Unable to start mission. Vehicle takeoff failed.")); qgcApp()->showMessage(tr("Unable to start mission: Vehicle failed to arm."));
return; return;
} }
} else { }
} else {
// Copter will automatically start a mission from the ground if you change to Auto and do a START+MIS
if (!_setFlightModeAndValidate(vehicle, "Auto")) {
qgcApp()->showMessage(tr("Unable to start mission: Vehicle failed to change to Guided mode."));
return; return;
} }
vehicle->sendMavCommand(vehicle->defaultComponentId(), MAV_CMD_MISSION_START, true /*show error */);
} }
if (!_setFlightModeAndValidate(vehicle, missionFlightMode())) { // Final step is to go into Auto
qgcApp()->showMessage(tr("Unable to start mission. Vehicle failed to change to auto.")); if (!_setFlightModeAndValidate(vehicle, "Auto")) {
qgcApp()->showMessage(tr("Unable to start mission: Vehicle failed to change to Auto mode."));
return; return;
} }
} }
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