5#include <QtCore/QString>
31 const QString manualFlightModeName = tr(
"Manual");
32 const QString acroFlightModeName = tr(
"Acro");
33 const QString stabilizedFlightModeName = tr(
"Stabilized");
34 const QString rattitudeFlightModeName = tr(
"Rattitude");
35 const QString altCtlFlightModeName = tr(
"Altitude");
36 const QString posCtlFlightModeName = tr(
"Position");
37 const QString offboardFlightModeName = tr(
"Offboard");
38 const QString readyFlightModeName = tr(
"Ready");
39 const QString takeoffFlightModeName = tr(
"Takeoff");
40 const QString holdFlightModeName = tr(
"Hold");
41 const QString missionFlightModeName = tr(
"Mission");
42 const QString rtlFlightModeName = tr(
"Return");
43 const QString landingFlightModeName = tr(
"Land");
44 const QString preclandFlightModeName = tr(
"Precision Land");
45 const QString followMeFlightModeName = tr(
"Follow Me");
46 const QString simpleFlightModeName = tr(
"Simple");
47 const QString orbitFlightModeName = tr(
"Orbit");
48 const QString slowFlightModeName = tr(
"Position Slow");
49 const QString altitudeCruiseFlightModeName = tr(
"Altitude Cruise");
50 const QString terminationFlightModeName = tr(
"Termination");
51 const QString vtolTakeoffFlightModeName = tr(
"VTOL Takeoff");
52 const QString guidedCourseFlightModeName = tr(
"Guided Course");
119 QStringList flightModesList;
123 bool fw = (vehicle->
fixedWing() && mode.fixedWing);
124 bool mc = (vehicle->
multiRotor() && mode.multiRotor);
128 if (fw || mc || other) {
129 flightModesList += mode.mode_name;
134 return flightModesList;
141 if (base_mode & MAV_MODE_FLAG_CUSTOM_MODE_ENABLED) {
142 return _modeEnumToString.value(custom_mode, tr(
"Unknown %1:%2").arg(base_mode).arg(custom_mode));
156 if(
flightMode.compare(mode.mode_name, Qt::CaseInsensitive) == 0){
157 *base_mode = MAV_MODE_FLAG_CUSTOM_MODE_ENABLED;
158 *custom_mode = mode.custom_mode;
165 qCWarning(PX4FirmwarePluginLog) <<
"Unknown flight Mode" <<
flightMode;
181 if (vehicle->
vtol()) {
187 return (capabilities & available) == capabilities;
204 QList<MAV_CMD> supportedCommands = {
205 MAV_CMD_NAV_WAYPOINT,
206 MAV_CMD_NAV_LOITER_UNLIM, MAV_CMD_NAV_LOITER_TIME,
207 MAV_CMD_NAV_RETURN_TO_LAUNCH,
209 MAV_CMD_DO_DIGICAM_CONTROL,
210 MAV_CMD_DO_SET_CAM_TRIGG_DIST,
211 MAV_CMD_DO_SET_SERVO,
212 MAV_CMD_DO_SET_ACTUATOR,
213 MAV_CMD_DO_CHANGE_SPEED,
215 MAV_CMD_DO_LAND_START,
216 MAV_CMD_DO_SET_ROI_LOCATION, MAV_CMD_DO_SET_ROI_WPNEXT_OFFSET, MAV_CMD_DO_SET_ROI_NONE,
217 MAV_CMD_DO_MOUNT_CONFIGURE,
218 MAV_CMD_DO_MOUNT_CONTROL,
219 MAV_CMD_SET_CAMERA_MODE,
220 MAV_CMD_IMAGE_START_CAPTURE, MAV_CMD_IMAGE_STOP_CAPTURE, MAV_CMD_VIDEO_START_CAPTURE, MAV_CMD_VIDEO_STOP_CAPTURE,
222 MAV_CMD_CONDITION_YAW,
223 MAV_CMD_NAV_LOITER_TO_ALT,
227 QList<MAV_CMD> vtolCommands = {
228 MAV_CMD_DO_VTOL_TRANSITION, MAV_CMD_NAV_VTOL_TAKEOFF, MAV_CMD_NAV_VTOL_LAND,
231 QList<MAV_CMD> flightCommands = {
232 MAV_CMD_NAV_LAND, MAV_CMD_NAV_TAKEOFF,
236 supportedCommands += vtolCommands;
237 supportedCommands += flightCommands;
240 supportedCommands += vtolCommands;
241 supportedCommands += flightCommands;
243 supportedCommands += flightCommands;
247 supportedCommands.append(MAV_CMD_CONDITION_GATE);
250 return supportedCommands;
255 switch (vehicleClass) {
257 return QStringLiteral(
":/json/PX4-MavCmdInfoCommon.json");
259 return QStringLiteral(
":/json/PX4-MavCmdInfoFixedWing.json");
261 return QStringLiteral(
":/json/PX4-MavCmdInfoMultiRotor.json");
263 return QStringLiteral(
":/json/PX4-MavCmdInfoVTOL.json");
265 return QStringLiteral(
":/json/PX4-MavCmdInfoSub.json");
267 return QStringLiteral(
":/json/PX4-MavCmdInfoRover.json");
269 qCWarning(PX4FirmwarePluginLog) <<
"PX4FirmwarePlugin::missionCommandOverrides called with bad VehicleClass_t:" << vehicleClass;
284void sendRepositionKeepLatLon(
Vehicle* vehicle,
float yaw,
float amslAltitude,
288 const float groundSpeed = -1.0f;
289 const float flags = MAV_DO_REPOSITION_FLAGS_CHANGE_MODE;
292 const bool commandInt =
296 if (ackHandlerInfo) {
298 groundSpeed, flags, 0.0f, yaw, NAN, NAN, amslAltitude);
300 vehicle->
sendMavCommandInt(compId, MAV_CMD_DO_REPOSITION, MAV_FRAME_GLOBAL,
true ,
301 groundSpeed, flags, 0.0f, yaw, NAN, NAN, amslAltitude);
303 }
else if (ackHandlerInfo) {
305 NAN, NAN, amslAltitude);
307 vehicle->
sendMavCommand(compId, MAV_CMD_DO_REPOSITION,
true , groundSpeed, flags, 0.0f, yaw, NAN,
316 sendRepositionKeepLatLon(vehicle, NAN, NAN);
335 auto* vehicle =
static_cast<Vehicle*
>(resultHandlerData);
337 switch (failureCode) {
339 if (ack.result == MAV_RESULT_ACCEPTED) {
343 if (!vehicle->
armed()) {
355 "Takeoff not sent: a previous takeoff command is still waiting for a vehicle response."));
365 if (qIsNaN(vehicleAltitudeAMSL)) {
370 double takeoffAltAMSL = takeoffAltRel + vehicleAltitudeAMSL;
381 static_cast<float>(takeoffAltAMSL));
386 QString speedParam(
"MPC_XY_VEL_MAX");
389 const Fact* speedFact =
392 return speedFact->
rawValue().toDouble();
401 QString airspeedMax(
"FW_AIRSPD_MAX");
404 const Fact* airspeedFact =
407 return airspeedFact->
rawValue().toDouble();
416 QString airspeedMin(
"FW_AIRSPD_MIN");
419 const Fact* airspeedFact =
422 return airspeedFact->
rawValue().toDouble();
444 Q_UNUSED(forwardFlightLoiterRadius)
451 if (vehicle->
capabilityBits() & MAV_PROTOCOL_CAPABILITY_COMMAND_INT) {
453 MAV_CMD_DO_REPOSITION,
457 MAV_DO_REPOSITION_FLAGS_CHANGE_MODE,
460 gotoCoord.latitude(),
461 gotoCoord.longitude(),
465 MAV_CMD_DO_REPOSITION,
468 MAV_DO_REPOSITION_FLAGS_CHANGE_MODE,
471 static_cast<float>(gotoCoord.latitude()),
472 static_cast<float>(gotoCoord.longitude()),
487 if (ack.result != MAV_RESULT_ACCEPTED) {
488 switch (failureCode) {
490 qCDebug(PX4FirmwarePluginLog) << QStringLiteral(
"MAV_CMD_DO_REPOSITION error(%1)").arg(ack.result);
493 qCDebug(PX4FirmwarePluginLog) <<
"MAV_CMD_DO_REPOSITION no response from vehicle";
496 qCDebug(PX4FirmwarePluginLog) <<
"Internal Error: MAV_CMD_DO_REPOSITION could not be sent due to duplicate command";
509 if (pauseSucceeded) {
510 sendRepositionKeepLatLon(pData->
vehicle, NAN,
static_cast<float>(pData->
newAMSLAlt));
530 double newAltRel = currentAltRel + altitudeChange;
533 resultData->
plugin =
this;
542 sendRepositionKeepLatLon(vehicle, NAN, NAN, &handlerInfo);
553 MAV_CMD_DO_CHANGE_SPEED,
556 static_cast<float>(groundspeed),
567 MAV_CMD_DO_CHANGE_SPEED,
570 static_cast<float>(airspeed_equiv),
583 const float radians = qDegreesToRadians(vehicle->
coordinate().azimuthTo(headingCoord));
585 sendRepositionKeepLatLon(vehicle, radians, NAN);
592 const QGeoCoordinate homePosition = vehicle->
homePosition();
593 if (!homePosition.isValid() || qIsNaN(homePosition.altitude())) {
598 _sendROICommand(vehicle, roiCenterCoord, MAV_FRAME_GLOBAL,
static_cast<float>(homePosition.altitude() + relativeAltitudeMeters));
694 if (message->compid == MAV_COMP_ID_UDP_BRIDGE) {
698 switch (message->msgid) {
699 case MAVLINK_MSG_ID_AUTOPILOT_VERSION:
700 _handleAutopilotVersion(vehicle, message);
712 if (!instanceData->versionNotified) {
713 bool notifyUser =
false;
714 int supportedMajorVersion = 1;
715 int supportedMinorVersion = 4;
716 int supportedPatchVersion = 1;
718 mavlink_autopilot_version_t version;
719 mavlink_msg_autopilot_version_decode(message, &version);
721 if (version.flight_sw_version != 0) {
722 int majorVersion, minorVersion, patchVersion;
724 majorVersion = (version.flight_sw_version >> (8*3)) & 0xFF;
725 minorVersion = (version.flight_sw_version >> (8*2)) & 0xFF;
726 patchVersion = (version.flight_sw_version >> (8*1)) & 0xFF;
728 if (majorVersion < supportedMajorVersion) {
730 }
else if (majorVersion == supportedMajorVersion) {
731 if (minorVersion < supportedMinorVersion) {
733 }
else if (minorVersion == supportedMinorVersion) {
734 notifyUser = patchVersion < supportedPatchVersion;
742 instanceData->versionNotified =
true;
743 QGC::showAppMessage(tr(
"QGroundControl supports PX4 Pro firmware Version %1.%2.%3 and above. You are using a version prior to that which will lead to unpredictable results. Please upgrade your firmware.").arg(supportedMajorVersion).arg(supportedMinorVersion).arg(supportedPatchVersion));
757QString PX4FirmwarePlugin::_getLatestVersionFileUrl(
Vehicle* vehicle)
const
760 return QStringLiteral(
"https://api.github.com/repos/PX4/Firmware/releases");
765 return QStringLiteral(
"v([0-9,\\.]*) Stable");
770 return ((vehicle->
vehicleType() == MAV_TYPE_GROUND_ROVER) || (vehicle->
vehicleType() == MAV_TYPE_SUBMARINE));
775 static const char* HOOBS_HI =
"LND_FLIGHT_T_HI";
776 static const char* HOOBS_LO =
"LND_FLIGHT_T_LO";
777 uint64_t hobbsTimeSeconds = 0;
783 hobbsTimeSeconds = ((uint64_t)factHi->
rawValue().toUInt() << 32 | (uint64_t)factLo->
rawValue().toUInt()) / 1000000;
784 qCDebug(PX4FirmwarePluginLog) <<
"Hobbs Meter raw PX4:" <<
"(" << factHi->
rawValue().toUInt() << factLo->
rawValue().toUInt() <<
")";
787 int hours = hobbsTimeSeconds / 3600;
788 int minutes = (hobbsTimeSeconds % 3600) / 60;
789 int seconds = hobbsTimeSeconds % 60;
790 QString timeStr = QString::asprintf(
"%04d:%02d:%02d", hours, minutes, seconds);
791 qCDebug(PX4FirmwarePluginLog) <<
"Hobbs Meter string:" << timeStr;
800 const QString gripperEnableParam = QStringLiteral(
"PD_GRIPPER_EN");
803 return gripperFact && gripperFact->
rawValue().toInt() != 0;
807 const QString gripperTypeParam = QStringLiteral(
"PD_GRIPPER_TYPE");
810 return gripperFact && gripperFact->
rawValue().toInt() >= 0;
818 for(
auto &mode: modeList){
841 mode.multiRotor =
true;
847 mode.multiRotor =
false;
858 mode.fixedWing =
false;
877 mode.fixedWing =
true;
887 "kExternalFlightModeCount must match the PX4 external sub modes");
895 const auto mode = std::find_if(modeList.cbegin(), modeList.cend(), [&customMode](
const FirmwareFlightMode& entry) {
896 return entry.custom_mode == customMode.data;
898 if (mode == modeList.cend()) {
901 const QString& name = mode->mode_name;
905 if (name.startsWith(QStringLiteral(
"(Mode not available)"))) {
923 if (indicatorName ==
"Battery") {
924 return QVariant::fromValue(QUrl::fromUserInput(
"qrc:/qml/QGroundControl/FirmwarePlugin/PX4/PX4BatteryIndicator.qml"));
925 }
else if (indicatorName ==
"FlightMode") {
926 return QVariant::fromValue(QUrl::fromUserInput(
"qrc:/qml/QGroundControl/FirmwarePlugin/PX4/PX4FlightModeIndicator.qml"));
QList< FirmwareFlightMode > FlightModeList
static void _pauseVehicleThenChangeAltResultHandler(void *resultHandlerData, int, const mavlink_command_ack_t &ack, Vehicle::MavCmdResultFailureCode_t failureCode)
struct __mavlink_message mavlink_message_t
#define QGC_LOGGING_CATEGORY(name, categoryStr)
struct __mavlink_command_ack_t mavlink_command_ack_t
The AutoPilotPlugin class is an abstract base class which represents the methods and objects which ar...
A Fact is used to hold a single value within the system.
QVariant rawValue() const
void _setModeEnumToModeStringMapping(FlightModeCustomModeMap enumToString)
FlightModeList _flightModeList
virtual double minimumEquivalentAirspeed(Vehicle *) const
FirmwareCapabilities
Set of optional capabilites which firmware may support.
@ ChangeHeadingCapability
Vehicle supports changing heading at current location.
@ GuidedTakeoffCapability
Vehicle supports guided takeoff.
@ TakeoffVehicleCapability
Vehicle supports taking off.
@ GuidedModeCapability
Vehicle supports guided mode commands.
@ OrbitModeCapability
Vehicle supports orbit mode.
@ SetFlightModeCapability
FirmwarePlugin::setFlightMode method is supported.
@ VTOLMulticopterTakeoffCapability
VTOL supports MAV_CMD_NAV_TAKEOFF while remaining in multicopter mode.
@ ROIModeCapability
Vehicle supports ROI (both in Fly guided mode and from Plan creation).
@ PauseVehicleCapability
Vehicle supports pausing at current location.
void _sendROICommand(Vehicle *vehicle, const QGeoCoordinate &coord, MAV_FRAME frame, float altitude) const
Build + send MAV_CMD_DO_SET_ROI_LOCATION (COMMAND_INT when the vehicle supports it).
virtual double maximumEquivalentAirspeed(Vehicle *) const
bool _setFlightModeAndValidate(Vehicle *vehicle, const QString &flightMode) const
void _updateFlightModeList(FlightModeList &flightModeList)
virtual QString _versionRegex() const
Returns regex QString to extract version information from text.
bool _armVehicleAndValidate(Vehicle *vehicle) const
FlightModeCustomModeMap _modeEnumToString
virtual double maximumHorizontalSpeedMultirotorMetersSecond(Vehicle *) const
bool versionNotified
true: user notified over version issue
PX4FirmwarePluginInstanceData(QObject *parent=nullptr)
void initializeVehicle(Vehicle *vehicle) override
Called when Vehicle is first created to perform any firmware specific setup.
bool isCapable(const Vehicle *vehicle, FirmwareCapabilities capabilities) const override
bool adjustIncomingMavlinkMessage(Vehicle *vehicle, mavlink_message_t *message) override
VehicleReadiness * createVehicleReadiness(Vehicle *vehicle) const override
void setGuidedMode(Vehicle *vehicle, bool guidedMode) const override
Set guided flight mode.
QString gotoFlightMode(void) const override
Returns the flight mode which the vehicle will be in if it is performing a goto location.
QList< MAV_CMD > supportedMissionCommands(QGCMAVLink::VehicleClass_t vehicleClass) const override
List of supported mission commands. Empty list for all commands supported.
bool guidedModeGotoLocation(Vehicle *vehicle, const QGeoCoordinate &gotoCoord, double forwardFlightLoiterRadius) const override
QString flightMode(uint8_t base_mode, uint32_t custom_mode) const override
QString takeOffFlightMode(void) const override
Returns the flight mode for TakeOff.
QString pauseFlightMode(void) const override
Returns The flight mode which indicates the vehicle is paused.
virtual ~PX4FirmwarePlugin()
bool sendHomePositionToVehicle(void) const override
bool setFlightMode(const QString &flightMode, uint8_t *base_mode, uint32_t *custom_mode) const override
void startMission(Vehicle *vehicle) const override
Command the vehicle to start the mission.
void updateAvailableFlightModes(FlightModeList &modeList) override
Update Available flight modes received from vehicle.
ParameterMetaData * _createParameterMetaData() final
static QString externalFlightModeName(const FlightModeList &modeList, int externalIndex)
Name a vehicle's AVAILABLE_MODES list gives an External Mode (1-based), empty if no mode is registere...
QString takeControlFlightMode(void) const override
Returns the flight mode to use when the operator wants to take back control from autonomouse flight.
bool fixedWingAirSpeedLimitsAvailable(Vehicle *vehicle) const override
QString missionFlightMode(void) const override
Returns the flight mode for running missions.
void pauseVehicle(Vehicle *vehicle) const override
QString landFlightMode(void) const override
Returns the flight mode for Land.
QString rtlFlightMode(void) const override
Returns the flight mode for RTL.
static constexpr int kExternalFlightModeCount
Number of PX4 External Mode slots. PX4FirmwarePlugin.cc checks it against px4_custom_mode....
void guidedModeRTL(Vehicle *vehicle, bool smartRTL) const override
Command vehicle to return to launch.
void guidedModeChangeHeading(Vehicle *vehicle, const QGeoCoordinate &headingCoord) const override
Command vehicle to rotate towards specified location.
bool guidedModeROI(Vehicle *vehicle, const QGeoCoordinate &roiCenterCoord, double relativeAltitudeMeters) const override
uint32_t highLatencyCustomModeTo32Bits(uint16_t hlCustomMode) const override
Convert from HIGH_LATENCY2.custom_mode value to correct 32 bit value.
void startTakeoff(Vehicle *vehicle) const override
Command the vehicle to start a takeoff.
double maximumHorizontalSpeedMultirotorMetersSecond(Vehicle *vehicle) const override
QStringList flightModes(Vehicle *vehicle) const override
QString getHobbsMeter(Vehicle *vehicle) const override
gets hobbs meter from autopilot. This should be reimplmeented for each firmware
bool isGuidedMode(const Vehicle *vehicle) const override
Returns whether the vehicle is in guided mode or not.
void guidedModeTakeoff(Vehicle *vehicle, double takeoffAltRel) const override
Command vehicle to takeoff from current location to the specified height.
QVariant expandedToolbarIndicatorSource(const Vehicle *vehicle, const QString &indicatorName) const override
double minimumEquivalentAirspeed(Vehicle *vehicle) const override
QString followFlightMode(void) const override
Returns the flight mode which the vehicle will be for follow me.
void guidedModeChangeEquivalentAirspeedMetersSecond(Vehicle *vehicle, double airspeed_equiv) const override
bool supportsNegativeThrust(Vehicle *vehicle) const override
bool mulirotorSpeedLimitsAvailable(Vehicle *vehicle) const override
QString missionCommandOverrides(QGCMAVLink::VehicleClass_t vehicleClass) const override
double maximumEquivalentAirspeed(Vehicle *vehicle) const override
void guidedModeChangeAltitude(Vehicle *vehicle, double altitudeRel, bool pauseVehicle) override
QString stabilizedFlightMode(void) const override
Returns the flight mode for Stabilized.
void _changeAltAfterPause(void *resultHandlerData, bool pauseSucceeded)
AutoPilotPlugin * autopilotPlugin(Vehicle *vehicle) const override
bool hasGripper(const Vehicle *vehicle) const override
static QStringList externalFlightModeNames(const FlightModeList &modeList)
externalFlightModeName of each of External Mode 1-8, in order
void guidedModeChangeGroundSpeedMetersSecond(Vehicle *vehicle, double groundspeed) const override
void guidedModeLand(Vehicle *vehicle) const override
Command vehicle to land at current location.
PX4 guided action readiness.
bool parameterExists(int componentId, const QString ¶mName) const
Fact * getParameter(int componentId, const QString ¶mName)
static constexpr int defaultComponentId
static constexpr const VehicleClass_t VehicleClassSub
static constexpr const VehicleClass_t VehicleClassFixedWing
static constexpr const VehicleClass_t VehicleClassMultiRotor
static constexpr const VehicleClass_t VehicleClassRoverBoat
static constexpr const VehicleClass_t VehicleClassVTOL
static SettingsManager * instance()
Fact * altitudeRelative()
Whether the vehicle would accept the Arm, Takeoff and Start Mission guided actions.
void sendMavCommand(int compId, MAV_CMD command, bool showError, float param1=0.0f, float param2=0.0f, float param3=0.0f, float param4=0.0f, float param5=0.0f, float param6=0.0f, float param7=0.0f)
QString flightMode() const
QGeoCoordinate homePosition()
void setFirmwarePluginInstanceData(FirmwarePluginInstanceData *firmwarePluginInstanceData)
uint64_t capabilityBits() const
static void showCommandAckError(const mavlink_command_ack_t &ack)
MAV_TYPE vehicleType() const
void sendMavCommandInt(int compId, MAV_CMD command, MAV_FRAME frame, bool showError, float param1, float param2, float param3, float param4, double param5, double param6, float param7)
int defaultComponentId() const
ParameterManager * parameterManager()
QGeoCoordinate coordinate()
void sendMavCommandIntWithHandler(const MavCmdAckHandlerInfo_t *ackHandlerInfo, int compId, MAV_CMD command, MAV_FRAME frame, float param1=0.0f, float param2=0.0f, float param3=0.0f, float param4=0.0f, double param5=0.0f, double param6=0.0f, float param7=0.0f)
class FirmwarePluginInstanceData * firmwarePluginInstanceData()
Q_INVOKABLE int versionCompare(const QString &compare) const
Used to check if running current version is equal or higher than the one being compared.
void sendMavCommandWithHandler(const MavCmdAckHandlerInfo_t *ackHandlerInfo, int compId, MAV_CMD command, float param1=0.0f, float param2=0.0f, float param3=0.0f, float param4=0.0f, float param5=0.0f, float param6=0.0f, float param7=0.0f)
Sends the command and calls the callback with the result.
void setArmedShowError(bool armed)
void showAppMessage(const QString &message, const QString &title)
Modal application message. Queued if the UI isn't ready yet.
@ PX4_CUSTOM_MAIN_MODE_AUTO
@ PX4_CUSTOM_SUB_MODE_EXTERNAL1
@ PX4_CUSTOM_SUB_MODE_EXTERNAL8
PX4FirmwarePlugin * plugin
static constexpr VehicleClass_t VehicleClassGeneric
MavCmdResultHandler resultHandler
nullptr for no handler
struct VehicleTypes::MavCmdAckHandlerInfo_s MavCmdAckHandlerInfo_t
Callback info bundle for sendMavCommandWithHandler.
MavCmdResultFailureCode_t
@ MavCmdResultFailureDuplicateCommand
Unable to send command since duplicate is already being waited on for response.
@ MavCmdResultCommandResultOnly
commandResult specifies full success/fail info
@ MavCmdResultFailureNoResponseToCommand
No response from vehicle to command.