diff --git a/src/az_config.h b/src/az_config.h index 24d109e..ddfdd00 100644 --- a/src/az_config.h +++ b/src/az_config.h @@ -1,5 +1,6 @@ #pragma once -const char *AZ_CONNECTION_SERIAL = "serial:///dev/ttyS0:115200"; -const char *AZ_CONNECTION_UDP = "udp://:14550"; -const int AZ_RELATIVE_FLY_ALTITUDE = 50; +const char *AZ_CONNECTION_SERIAL = "serial:///dev/ttyS0:115200"; +const char *AZ_CONNECTION_UDP = "udp://:14550"; +const int AZ_RELATIVE_FLY_ALTITUDE = 50; +const float AZ_GET_AUTOPILOT_TIMEOUT = 3.0; diff --git a/src/az_drone_controller.cpp b/src/az_drone_controller.cpp index f48968a..9c15692 100644 --- a/src/az_drone_controller.cpp +++ b/src/az_drone_controller.cpp @@ -73,8 +73,16 @@ bool AzDroneController::stateConnect(void) bool AzDroneController::stateAutopilot(void) { - // Get the first autopilot from the flight controller. - return (mSystem = mMavsdk.first_autopilot(3.0).value()) != nullptr; + std::optional> autopilot = mMavsdk.first_autopilot(AZ_GET_AUTOPILOT_TIMEOUT); + + if (autopilot.has_value()) { + mSystem = autopilot.value(); + return true; + } + else { + qCritical() << "MAVSDK::first_autopilot() failed"; + return false; + } } bool AzDroneController::stateTelemetryModule(void)