Commit b49760af authored by DonLakeFlyer's avatar DonLakeFlyer

New sequence for PX4 Takeoff

parent 81474bf1
...@@ -139,7 +139,7 @@ void ArduCopterFirmwarePlugin::guidedModeLand(Vehicle* vehicle) ...@@ -139,7 +139,7 @@ void ArduCopterFirmwarePlugin::guidedModeLand(Vehicle* vehicle)
void ArduCopterFirmwarePlugin::guidedModeTakeoff(Vehicle* vehicle) void ArduCopterFirmwarePlugin::guidedModeTakeoff(Vehicle* vehicle)
{ {
if (!_armVehicle(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; return;
} }
......
...@@ -435,7 +435,7 @@ bool FirmwarePlugin::vehicleYawsToNextWaypointInMission(const Vehicle* vehicle) ...@@ -435,7 +435,7 @@ bool FirmwarePlugin::vehicleYawsToNextWaypointInMission(const Vehicle* vehicle)
return vehicle->multiRotor() ? false : true; return vehicle->multiRotor() ? false : true;
} }
bool FirmwarePlugin::_armVehicle(Vehicle* vehicle) bool FirmwarePlugin::_armVehicleAndValidate(Vehicle* vehicle)
{ {
if (!vehicle->armed()) { if (!vehicle->armed()) {
vehicle->setArmed(true); vehicle->setArmed(true);
......
...@@ -303,7 +303,7 @@ public: ...@@ -303,7 +303,7 @@ public:
protected: protected:
// Arms the vehicle, waiting for the arm state to change. // Arms the vehicle, waiting for the arm state to change.
// @return: true - vehicle armed, false - vehicle failed to arm // @return: true - vehicle armed, false - vehicle failed to arm
bool _armVehicle(Vehicle* vehicle); bool _armVehicleAndValidate(Vehicle* vehicle);
private: private:
QVariantList _toolBarIndicatorList; QVariantList _toolBarIndicatorList;
......
...@@ -352,6 +352,29 @@ void PX4FirmwarePlugin::guidedModeOrbit(Vehicle* vehicle, const QGeoCoordinate& ...@@ -352,6 +352,29 @@ void PX4FirmwarePlugin::guidedModeOrbit(Vehicle* vehicle, const QGeoCoordinate&
centerCoord.isValid() ? centerCoord.altitude() : NAN); centerCoord.isValid() ? centerCoord.altitude() : NAN);
} }
void PX4FirmwarePlugin::_mavCommandResult(int vehicleId, int component, int command, int result, bool noReponseFromVehicle)
{
Q_UNUSED(vehicleId);
Q_UNUSED(component);
Q_UNUSED(noReponseFromVehicle);
Vehicle* vehicle = dynamic_cast<Vehicle*>(sender());
if (!vehicle) {
qWarning() << "Dynamic cast failed!";
return;
}
if (command == MAV_CMD_NAV_TAKEOFF && result == MAV_RESULT_ACCEPTED) {
// Now that we are in takeoff mode we can arm the vehicle which will cause it to takeoff.
// We specifically don't retry arming if it fails. This way we don't fight with the user if
// They are trying to disarm.
disconnect(vehicle, &Vehicle::mavCommandResult, this, &PX4FirmwarePlugin::_mavCommandResult);
if (!vehicle->armed()) {
vehicle->setArmed(true);
}
}
}
void PX4FirmwarePlugin::guidedModeTakeoff(Vehicle* vehicle) void PX4FirmwarePlugin::guidedModeTakeoff(Vehicle* vehicle)
{ {
QString takeoffAltParam("MIS_TAKEOFF_ALT"); QString takeoffAltParam("MIS_TAKEOFF_ALT");
...@@ -367,11 +390,7 @@ void PX4FirmwarePlugin::guidedModeTakeoff(Vehicle* vehicle) ...@@ -367,11 +390,7 @@ void PX4FirmwarePlugin::guidedModeTakeoff(Vehicle* vehicle)
} }
Fact* takeoffAlt = vehicle->parameterManager()->getParameter(FactSystem::defaultComponentId, takeoffAltParam); Fact* takeoffAlt = vehicle->parameterManager()->getParameter(FactSystem::defaultComponentId, takeoffAltParam);
if (!_armVehicle(vehicle)) { connect(vehicle, &Vehicle::mavCommandResult, this, &PX4FirmwarePlugin::_mavCommandResult);
qgcApp()->showMessage(tr("Unable to takeoff: Vehicle failed to arm."));
return;
}
vehicle->sendMavCommand(vehicle->defaultComponentId(), vehicle->sendMavCommand(vehicle->defaultComponentId(),
MAV_CMD_NAV_TAKEOFF, MAV_CMD_NAV_TAKEOFF,
true, // show error is fails true, // show error is fails
...@@ -436,7 +455,7 @@ void PX4FirmwarePlugin::guidedModeChangeAltitude(Vehicle* vehicle, double altitu ...@@ -436,7 +455,7 @@ void PX4FirmwarePlugin::guidedModeChangeAltitude(Vehicle* vehicle, double altitu
void PX4FirmwarePlugin::startMission(Vehicle* vehicle) void PX4FirmwarePlugin::startMission(Vehicle* vehicle)
{ {
if (!_armVehicle(vehicle)) { if (!_armVehicleAndValidate(vehicle)) {
qgcApp()->showMessage(tr("Unable to start mission: Vehicle failed to arm.")); qgcApp()->showMessage(tr("Unable to start mission: Vehicle failed to arm."));
return; return;
} }
......
...@@ -103,6 +103,9 @@ protected: ...@@ -103,6 +103,9 @@ protected:
QString _followMeFlightMode; QString _followMeFlightMode;
QString _simpleFlightMode; QString _simpleFlightMode;
private slots:
void _mavCommandResult(int vehicleId, int component, int command, int result, bool noReponseFromVehicle);
private: private:
void _handleAutopilotVersion(Vehicle* vehicle, mavlink_message_t* message); void _handleAutopilotVersion(Vehicle* vehicle, mavlink_message_t* message);
......
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