Improve use of MAVSDK::add_any_connection()

Added error printing and possibility to use UART as connection
to the flight controller.

Issue: https://denyspopov.atlassian.net/browse/AZ-16
Type: New Feature
This commit is contained in:
Tuomas Järvinen
2024-05-20 21:02:32 +02:00
parent dda897a573
commit ab791eb254
6 changed files with 28 additions and 16 deletions
+20 -7
View File
@@ -48,11 +48,27 @@ void AzDroneController::delayedStateCallSlot(int ms)
QTimer::singleShot(ms, this, &AzDroneController::droneStateMachineSlot);
}
// Connects to the flight controller based on AZ_CONNECTION_XXX defines in AzConfig.
// Serial port connections is enabled if command line arguments contains "serial"
// parameter. Otherwise UDP connection is used.
bool AzDroneController::stateConnect(void)
{
// Connects to the flight controller based on AZ_CONNECTION define in AzConfig.
// TODO!! Add command line option to change between UDP and UART connections.
return mMavsdk.add_any_connection(AZ_CONNECTION) == ConnectionResult::Success;
ConnectionResult result;
if (QCoreApplication::arguments().contains("serial")) {
result = mMavsdk.add_any_connection(AZ_CONNECTION_SERIAL);
}
else {
result = mMavsdk.add_any_connection(AZ_CONNECTION_UDP);
}
if (result == ConnectionResult::Success) {
return true;
}
else {
std::cerr << "MAVSDK::add_any_connection() failed. Reason: " << result << endl;
return false;
}
}
bool AzDroneController::stateAutopilot(void)
@@ -104,9 +120,7 @@ bool AzDroneController::stateReadyForArming(void)
bool result = mTelemetry->health_all_ok();
if (result == false) {
mTelemetry->subscribe_health([this](Telemetry::Health health) {
emit newHealthInfo(health);
});
mTelemetry->subscribe_health([this](Telemetry::Health health) { emit newHealthInfo(health); });
}
return result;
@@ -247,7 +261,6 @@ void AzDroneController::missionIndexChangedSlot(int currentIndex, int totalIndex
qDebug() << "AzDroneController::missionIndexChanged()" << currentIndex << "/" << totalIndexes;
}
void AzDroneController::newHealthInfoSlot(Telemetry::Health health)
{
qDebug() << "AzDroneController::newHealthInfoSlot()";