mirror of
https://github.com/azaion/autopilot.git
synced 2026-04-22 09:06:33 +00:00
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:
+2
-3
@@ -1,6 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define FUNCTION_NAME(func) func()
|
const char *AZ_CONNECTION_SERIAL = "serial:///dev/ttyS0:115200";
|
||||||
|
const char *AZ_CONNECTION_UDP = "udp://:14550";
|
||||||
const char *AZ_CONNECTION = "udp://:14550";
|
|
||||||
const int AZ_RELATIVE_FLY_ALTITUDE = 50;
|
const int AZ_RELATIVE_FLY_ALTITUDE = 50;
|
||||||
|
|||||||
@@ -48,11 +48,27 @@ void AzDroneController::delayedStateCallSlot(int ms)
|
|||||||
QTimer::singleShot(ms, this, &AzDroneController::droneStateMachineSlot);
|
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)
|
bool AzDroneController::stateConnect(void)
|
||||||
{
|
{
|
||||||
// Connects to the flight controller based on AZ_CONNECTION define in AzConfig.
|
ConnectionResult result;
|
||||||
// TODO!! Add command line option to change between UDP and UART connections.
|
|
||||||
return mMavsdk.add_any_connection(AZ_CONNECTION) == ConnectionResult::Success;
|
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)
|
bool AzDroneController::stateAutopilot(void)
|
||||||
@@ -104,9 +120,7 @@ bool AzDroneController::stateReadyForArming(void)
|
|||||||
bool result = mTelemetry->health_all_ok();
|
bool result = mTelemetry->health_all_ok();
|
||||||
|
|
||||||
if (result == false) {
|
if (result == false) {
|
||||||
mTelemetry->subscribe_health([this](Telemetry::Health health) {
|
mTelemetry->subscribe_health([this](Telemetry::Health health) { emit newHealthInfo(health); });
|
||||||
emit newHealthInfo(health);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@@ -247,7 +261,6 @@ void AzDroneController::missionIndexChangedSlot(int currentIndex, int totalIndex
|
|||||||
qDebug() << "AzDroneController::missionIndexChanged()" << currentIndex << "/" << totalIndexes;
|
qDebug() << "AzDroneController::missionIndexChanged()" << currentIndex << "/" << totalIndexes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void AzDroneController::newHealthInfoSlot(Telemetry::Health health)
|
void AzDroneController::newHealthInfoSlot(Telemetry::Health health)
|
||||||
{
|
{
|
||||||
qDebug() << "AzDroneController::newHealthInfoSlot()";
|
qDebug() << "AzDroneController::newHealthInfoSlot()";
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
#include <memory.h>
|
#include <memory.h>
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
#include <mavsdk/mavsdk.h>
|
#include <mavsdk/mavsdk.h>
|
||||||
#include <mavsdk/plugins/action/action.h>
|
#include <mavsdk/plugins/action/action.h>
|
||||||
|
|||||||
@@ -2,11 +2,10 @@
|
|||||||
|
|
||||||
#include <mavsdk/plugins/telemetry/telemetry.h>
|
#include <mavsdk/plugins/telemetry/telemetry.h>
|
||||||
|
|
||||||
#include "az_mission_controller.h"
|
|
||||||
#include "az_mission.h"
|
#include "az_mission.h"
|
||||||
|
#include "az_mission_controller.h"
|
||||||
#include "az_utils.h"
|
#include "az_utils.h"
|
||||||
|
|
||||||
|
|
||||||
AzMissionController::AzMissionController(AzMission &mission, QObject *parent)
|
AzMissionController::AzMissionController(AzMission &mission, QObject *parent)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
, mMission(mission)
|
, mMission(mission)
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
#include <math.h>
|
|
||||||
#include "az_utils.h"
|
#include "az_utils.h"
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
AzUtils::AzUtils() {}
|
AzUtils::AzUtils() {}
|
||||||
|
|
||||||
|
|||||||
+3
-2
@@ -9,8 +9,9 @@ int main(int argc, char *argv[])
|
|||||||
// This is needed to have main event loop and signal-slot events in the AzDroneController.
|
// This is needed to have main event loop and signal-slot events in the AzDroneController.
|
||||||
QCoreApplication a(argc, argv);
|
QCoreApplication a(argc, argv);
|
||||||
|
|
||||||
if (argc != 2) {
|
if (argc < 2) {
|
||||||
qCritical() << "Please give mission JSON file as an argument.\n";
|
qCritical() << "\nPass the mission JSON file as the first argument.";
|
||||||
|
qCritical() << "A serial port connection can be enabled with \"serial\" as the second argument.\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user