Skip to content

Commit

Permalink
Fix case-sensitive flight mode comparisons
Browse files Browse the repository at this point in the history
Fixed a bug where the "Start mission" action failed on ArduPilot,
displaying an error popup with the message "Unable to start mission:
Vehicle failed to change to Auto mode." The issue was caused by
case-sensitive comparisons between flight mode strings from the vehicle
and the reference strings. Moving away from using strings entirely
should be considered.

Replaced direct string comparisons with case-insensitive comparisons
using QString::compare() with Qt::CaseInsensitive flag. This fix
resolves the immediate issue and also corrects a few other incorrect
mode comparisons unrelated to the "Start mission" problem.
  • Loading branch information
rubenp02 committed Dec 11, 2024
1 parent 0141494 commit 5c1d1a9
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/AutoPilotPlugins/APM/APMSubMotorComponentController.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void APMSubMotorComponentController::handleNewMessages(int uasid, int componenti
Q_UNUSED(uasid);
Q_UNUSED(componentid);
Q_UNUSED(severity);
if (_vehicle->flightMode() == "Motor Detection"
if (QString::compare(_vehicle->flightMode(), "Motor Detection", Qt::CaseInsensitive) == 0
&& (text.toLower().contains("thruster") || text.toLower().contains("motor"))) {
_motorDetectionMessages += text + QStringLiteral("\n");
emit motorDetectionMessagesChanged();
Expand Down
2 changes: 1 addition & 1 deletion src/FirmwarePlugin/APM/APMFirmwarePlugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ const QVariantList& APMFirmwarePlugin::toolIndicators(const Vehicle* vehicle)

bool APMFirmwarePlugin::isGuidedMode(const Vehicle* vehicle) const
{
return vehicle->flightMode() == "Guided";
return QString::compare(vehicle->flightMode(), "Guided", Qt::CaseInsensitive) == 0;
}

void APMFirmwarePlugin::_soloVideoHandshake(void)
Expand Down
4 changes: 2 additions & 2 deletions src/FirmwarePlugin/FirmwarePlugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ bool FirmwarePlugin::_armVehicleAndValidate(Vehicle* vehicle)

bool FirmwarePlugin::_setFlightModeAndValidate(Vehicle* vehicle, const QString& flightMode)
{
if (vehicle->flightMode() == flightMode) {
if (QString::compare(vehicle->flightMode(), flightMode, Qt::CaseInsensitive) == 0) {
return true;
}

Expand All @@ -377,7 +377,7 @@ bool FirmwarePlugin::_setFlightModeAndValidate(Vehicle* vehicle, const QString&

// Wait for vehicle to return flight mode
for (int i=0; i<13; i++) {
if (vehicle->flightMode() == flightMode) {
if (QString::compare(vehicle->flightMode(), flightMode, Qt::CaseInsensitive) == 0) {
flightModeChanged = true;
break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Vehicle/StandardModes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ QString StandardModes::flightMode(uint32_t custom_mode) const
bool StandardModes::setFlightMode(const QString &flightMode, uint32_t *custom_mode)
{
for (auto iter = _modes.constBegin(); iter != _modes.constEnd(); ++iter) {
if (iter->name == flightMode) {
if (QString::compare(iter->name, flightMode, Qt::CaseInsensitive) == 0) {
*custom_mode = iter.key();
return true;
}
Expand Down

0 comments on commit 5c1d1a9

Please sign in to comment.