mirror of
https://github.com/azaion/autopilot.git
synced 2026-04-22 22:56:33 +00:00
37e8cfd3fe
- uses MAVSDK::MissionRaw objects for missions - added new state AZ_DRONE_STATE_MISSION_UPLOADED - new state is used in AzDroneControllerPlane before waiting for AUTO switch TODO!! - move to AzMissionController - use JSON file instead of hard coded mission items
58 lines
2.1 KiB
C++
58 lines
2.1 KiB
C++
#include <ctime>
|
|
|
|
#include <QCoreApplication>
|
|
#include <QDebug>
|
|
#include <QFile>
|
|
|
|
#include "az_drone_controller.h"
|
|
#include "az_drone_controller_plane.h"
|
|
#include "az_mission.h"
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
// Add current data and time for easier log handling.
|
|
std::cout << "\n#################################################\n";
|
|
std::time_t currentTime = std::time(nullptr);
|
|
std::tm* localTime = std::localtime(¤tTime);
|
|
std::cout << "Starting autopilot program at " << std::put_time(localTime, "%Y-%m-%d %H:%M:%S") << std::endl;
|
|
std::cout << "#################################################\n";
|
|
|
|
// This is needed to have main event loop and signal-slot events in the AzDroneController.
|
|
QCoreApplication a(argc, argv);
|
|
|
|
if (a.arguments().size() != 4) {
|
|
qCritical() << "\nProgram needs three command line parameters.";
|
|
qCritical() << "\tFirst argument: mission JSON file.";
|
|
qCritical() << "\tSecond argument: \"quadcopter\" or \"plane\".";
|
|
qCritical() << "\tThird argument: \"udp\" or \"serial\" for connection type.";
|
|
qCritical() << "\tFor example ./drone_controller mission.json plane udp";
|
|
return 1;
|
|
}
|
|
|
|
if (QFile::exists(a.arguments().at(1)) == false) {
|
|
qCritical() << "\nMission file doesn't exist";
|
|
return 1;
|
|
}
|
|
|
|
if (a.arguments().at(2) != "plane" && a.arguments().at(2) != "quadcopter") {
|
|
qCritical() << "\nPass \"quadcopter\" or \"plane\" for drone type as second argument";
|
|
return 1;
|
|
}
|
|
|
|
if (a.arguments().at(3) != "udp" && a.arguments().at(3) != "serial") {
|
|
qCritical() << "Pass \"udp\" or \"serial\" for connection type as third argument";
|
|
return 1;
|
|
}
|
|
|
|
// Reads mission from the JSON file which is given as command line option.
|
|
AzMission mission(argv[1]);
|
|
cout << mission;
|
|
|
|
// Launch a drone controller using the MAVSDK for ArduPilot-based flight controllers.
|
|
bool isPlane = a.arguments().at(2) == "plane";
|
|
AzDroneController *controller = isPlane ? new AzDroneControllerPlane(mission) : new AzDroneController(mission);
|
|
controller->start();
|
|
|
|
return a.exec();
|
|
}
|