mirror of
https://github.com/azaion/autopilot.git
synced 2026-04-22 09:56:34 +00:00
a8ba701138
- improved landing - navigate to the return point defined in JSON file - land drone safely without timeouts Issue: https://denyspopov.atlassian.net/browse/AZ-24 Type: New Feature
89 lines
2.8 KiB
C++
89 lines
2.8 KiB
C++
#pragma once
|
|
|
|
#include <memory.h>
|
|
#include <QObject>
|
|
|
|
#include <mavsdk/mavsdk.h>
|
|
#include <mavsdk/plugins/action/action.h>
|
|
#include <mavsdk/plugins/telemetry/telemetry.h>
|
|
|
|
#include "az_mission.h"
|
|
#include "az_mission_controller.h"
|
|
|
|
using namespace mavsdk;
|
|
|
|
typedef enum {
|
|
AZ_DRONE_STATE_DISCONNECTED,
|
|
AZ_DRONE_STATE_CONNECTED,
|
|
AZ_DRONE_STATE_AUTOPILOT,
|
|
AZ_DRONE_STATE_TELEMETRY_MODULE,
|
|
AZ_DRONE_STATE_ACTION_MODULE,
|
|
AZ_DRONE_STATE_READY_FOR_ARMING,
|
|
AZ_DRONE_STATE_ARMED,
|
|
AZ_DRONE_STATE_TAKE_OFF,
|
|
AZ_DRONE_STATE_FLY_MISSION,
|
|
AZ_DRONE_STATE_LAND,
|
|
AZ_DRONE_STATE_END,
|
|
} AzDroneState;
|
|
|
|
class AzDroneController : public QObject
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
explicit AzDroneController(AzMission &mission, QObject *parent = nullptr);
|
|
|
|
// Starts the autopilot.
|
|
void start();
|
|
|
|
// Specify the methods that will be called one at a time to initialise the drone and fly the mission.
|
|
bool stateConnect(void);
|
|
bool stateAutopilot(void);
|
|
bool stateTelemetryModule(void);
|
|
bool stateActionModule(void);
|
|
bool stateReadyForArming(void);
|
|
bool stateArm(void);
|
|
bool stateTakeoff(void);
|
|
bool stateFlyMission(void);
|
|
|
|
// Slots that are called by the emitted Qt signals.
|
|
private slots:
|
|
// Launches a state machine that progressively initialises the drone without blocking.
|
|
void droneStateMachineSlot(void);
|
|
|
|
// ArduPilot seems to require some delay between calls. This method uses QTimer internally
|
|
// to call each new state method with some delay without blocking the main thread.
|
|
void delayedStateCallSlot(int ms);
|
|
|
|
// Slot that is called when the newPosition() signal below is emitted.
|
|
void newPositionSlot(Telemetry::Position);
|
|
|
|
// A mission file contains several action points. This is called
|
|
// when the action point is reached. Indexing starts at 1.
|
|
void missionIndexChangedSlot(int currentIndex, int totalIndexes);
|
|
|
|
// Called at the end of the mission. Lands and disarms the drone.
|
|
void missionFinishedSlot(void);
|
|
|
|
// Gets Telemetry::Health information in prearming.
|
|
void newHealthInfoSlot(Telemetry::Health health);
|
|
|
|
signals:
|
|
// Signal is emitted when Ardupilot sends a new position from the
|
|
// MAVSDK thread. Signal goes through the main event loop and is
|
|
// captured in the main thread to avoid threading issues.
|
|
void newPosition(Telemetry::Position);
|
|
|
|
// If Telemetry::health_all_ok() fails, then autopilot subscripes for the healt updates to
|
|
// see exactly what is wrong. This signal is emitted to catch updates in the main thread.
|
|
void newHealthInfo(Telemetry::Health);
|
|
|
|
private:
|
|
Mavsdk mMavsdk;
|
|
AzDroneState mDroneState;
|
|
std::shared_ptr<System> mSystem;
|
|
Telemetry *mTelemetry;
|
|
Action *mAction;
|
|
Telemetry::Position mFirstPosition;
|
|
AzMissionController *mMissionController;
|
|
};
|