mirror of
https://github.com/azaion/autopilot.git
synced 2026-04-22 11:36:34 +00:00
Hard coded values to target location until real values are available.
Added function for remote which AI can call.
This commit is contained in:
@@ -105,7 +105,7 @@ void RemoteControl::restoreOrientation(void)
|
|||||||
|
|
||||||
Config::getSerial()->sendCommand(serialCommandAngle);
|
Config::getSerial()->sendCommand(serialCommandAngle);
|
||||||
|
|
||||||
QTimer::singleShot(1000, this, [this]() mutable { sendResponse(); });
|
QTimer::singleShot(0, this, [this]() mutable { sendResponse(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoteControl::restoreZoom(void)
|
void RemoteControl::restoreZoom(void)
|
||||||
@@ -123,7 +123,7 @@ void RemoteControl::restoreZoom(void)
|
|||||||
|
|
||||||
Config::getSerial()->sendCommand(serialCommandZoom);
|
Config::getSerial()->sendCommand(serialCommandZoom);
|
||||||
|
|
||||||
QTimer::singleShot(3000, this, [this]() mutable { restoreOrientation(); });
|
QTimer::singleShot(100, this, [this]() mutable { restoreOrientation(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoteControl::calculateTargetPosition(QJsonObject &commandObject)
|
void RemoteControl::calculateTargetPosition(QJsonObject &commandObject)
|
||||||
@@ -145,7 +145,7 @@ void RemoteControl::calculateTargetPosition(QJsonObject &commandObject)
|
|||||||
mResponseObject["latitude"] = gpsData.latitude;
|
mResponseObject["latitude"] = gpsData.latitude;
|
||||||
mResponseObject["longitude"] = gpsData.longitude;
|
mResponseObject["longitude"] = gpsData.longitude;
|
||||||
|
|
||||||
QTimer::singleShot(3000, this, [this, commandObject]() mutable { zoomToTarget(commandObject); });
|
QTimer::singleShot(100, this, [this, commandObject]() mutable { zoomToTarget(commandObject); });
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoteControl::turnToTarget(QJsonObject &commandObject)
|
void RemoteControl::turnToTarget(QJsonObject &commandObject)
|
||||||
@@ -171,7 +171,7 @@ void RemoteControl::turnToTarget(QJsonObject &commandObject)
|
|||||||
|
|
||||||
Config::getSerial()->sendCommand(serialCommandTurn);
|
Config::getSerial()->sendCommand(serialCommandTurn);
|
||||||
|
|
||||||
QTimer::singleShot(3000, this, [this, commandObject]() mutable { calculateTargetPosition(commandObject); });
|
QTimer::singleShot(1000, this, [this, commandObject]() mutable { calculateTargetPosition(commandObject); });
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoteControl::zoomToTarget(QJsonObject &commandObject)
|
void RemoteControl::zoomToTarget(QJsonObject &commandObject)
|
||||||
@@ -201,7 +201,20 @@ void RemoteControl::zoomToTarget(QJsonObject &commandObject)
|
|||||||
|
|
||||||
Config::getSerial()->sendCommand(serialCommandNewZoom);
|
Config::getSerial()->sendCommand(serialCommandNewZoom);
|
||||||
|
|
||||||
QTimer::singleShot(10000, this, [this, commandObject]() mutable { restoreZoom(); });
|
QTimer::singleShot(5000, this, [this, commandObject]() mutable { restoreZoom(); });
|
||||||
|
}
|
||||||
|
|
||||||
|
RectangleProperties RemoteControl::calculateRectangleProperties(uint16_t top, uint16_t left, uint16_t bottom, uint16_t right)
|
||||||
|
{
|
||||||
|
RectangleProperties properties;
|
||||||
|
|
||||||
|
properties.width = right - left;
|
||||||
|
properties.height = bottom - top;
|
||||||
|
|
||||||
|
properties.middleX = static_cast<uint16_t>(left + properties.width / 2);
|
||||||
|
properties.middleY = static_cast<uint16_t>(top + properties.height / 2);
|
||||||
|
|
||||||
|
return properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoteControl::run()
|
void RemoteControl::run()
|
||||||
@@ -235,6 +248,24 @@ void RemoteControl::run()
|
|||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO:
|
||||||
|
// Wait that these are actually available
|
||||||
|
// Without these it is impossible to calculate target location
|
||||||
|
commandObject["altitude"] = 10.5f;
|
||||||
|
commandObject["latitude"] = 55.75000000f;
|
||||||
|
commandObject["longitude"] = 37.61666670f;
|
||||||
|
commandObject["pitch"] = 0.0f;
|
||||||
|
commandObject["yaw"] = 152.5f;
|
||||||
|
commandObject["target_real_height"] = 2.5f;
|
||||||
|
commandObject["target_real_width"] = 5.0f;
|
||||||
|
|
||||||
|
// Rectangle calculation for having proper zoom on group / target
|
||||||
|
RectangleProperties rectangle = calculateRectangleProperties(commandObject["top"].toInt(), commandObject["left"].toInt(), commandObject["bottom"].toInt(), commandObject["right"].toInt());
|
||||||
|
commandObject["target_x"] = rectangle.middleX;
|
||||||
|
commandObject["target_y"] = rectangle.middleY;
|
||||||
|
commandObject["target_pixel_height"] = rectangle.height;
|
||||||
|
commandObject["target_pixel_width"] = rectangle.width;
|
||||||
|
|
||||||
mIsBusy = true;
|
mIsBusy = true;
|
||||||
|
|
||||||
// Prepare responce object
|
// Prepare responce object
|
||||||
|
|||||||
@@ -22,6 +22,5 @@ SOURCES += \
|
|||||||
remoteControl.cpp
|
remoteControl.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
defines.hpp \
|
|
||||||
remoteControl.hpp
|
remoteControl.hpp
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#define FIFO_WHO_AM_I "AI"
|
|
||||||
#define FIFO_TO_GIMBAL "/tmp/fifo_to_a8_gimbal"
|
|
||||||
#define FIFO_FROM_GIMBAL "/tmp/fifo_from_a8_gimbal"
|
|
||||||
@@ -5,12 +5,13 @@
|
|||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include "defines.hpp"
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <random>
|
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#ifdef FIFO_TEST
|
||||||
|
#include <random>
|
||||||
|
#endif
|
||||||
|
|
||||||
RemoteControl::RemoteControl() {}
|
RemoteControl::RemoteControl() {}
|
||||||
|
|
||||||
@@ -75,7 +76,23 @@ void RemoteControl::createNamedPipe()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoteControl::startCommunication()
|
void RemoteControl::sendData(uint16_t top, uint16_t left, uint16_t bottom, uint16_t right)
|
||||||
|
{
|
||||||
|
qInfo().noquote().nospace() << "Enter a command (0 to exit): ";
|
||||||
|
std::string input;
|
||||||
|
std::cin >> input;
|
||||||
|
|
||||||
|
// Send command
|
||||||
|
QJsonObject commandObject = {{"sender", FIFO_WHO_AM_I}, {"top", top}, {"left", left}, {"bottom", bottom}, {"right", right}};
|
||||||
|
|
||||||
|
QJsonDocument commandDocument(commandObject);
|
||||||
|
std::string command = commandDocument.toJson(QJsonDocument::Compact).toStdString();
|
||||||
|
write(mFifoFdOut, command.c_str(), command.size());
|
||||||
|
qDebug().noquote().nospace() << "Sent: " << command;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef FIFO_TEST
|
||||||
|
void RemoteControl::startTest()
|
||||||
{
|
{
|
||||||
qInfo().noquote().nospace() << "Enter a command (0 to exit): ";
|
qInfo().noquote().nospace() << "Enter a command (0 to exit): ";
|
||||||
std::string input;
|
std::string input;
|
||||||
@@ -86,11 +103,11 @@ void RemoteControl::startCommunication()
|
|||||||
{"sender", FIFO_WHO_AM_I},
|
{"sender", FIFO_WHO_AM_I},
|
||||||
{"latitude", 63.155653611},
|
{"latitude", 63.155653611},
|
||||||
{"longitude", 23.827191389},
|
{"longitude", 23.827191389},
|
||||||
{"altitude", randomFloatBetween(100, 500)},
|
{"altitude", randomFloatBetween(10, 11)},
|
||||||
{"yaw", randomFloatBetween(0.0f, 360.0f)},
|
{"yaw", randomFloatBetween(0.0f, 360.0f)},
|
||||||
{"pitch", 0.0},
|
{"pitch", 0.0},
|
||||||
{"target_x", (uint16_t) randomFloatBetween(0, 1279)},
|
{"target_x", (uint16_t) randomFloatBetween(300, 979)},
|
||||||
{"target_y", (uint16_t) randomFloatBetween(0, 719)},
|
{"target_y", (uint16_t) randomFloatBetween(200, 519)},
|
||||||
{"target_pixel_width", 20},
|
{"target_pixel_width", 20},
|
||||||
{"target_pixel_height", 10},
|
{"target_pixel_height", 10},
|
||||||
{"target_real_width", 5},
|
{"target_real_width", 5},
|
||||||
@@ -139,8 +156,6 @@ void RemoteControl::startCommunication()
|
|||||||
QCoreApplication::processEvents();
|
QCoreApplication::processEvents();
|
||||||
QThread::msleep(100);
|
QThread::msleep(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
float RemoteControl::randomFloatBetween(float min, float max)
|
float RemoteControl::randomFloatBetween(float min, float max)
|
||||||
@@ -153,3 +168,4 @@ float RemoteControl::randomFloatBetween(float min, float max)
|
|||||||
// Generate a random float between min and max (inclusive)
|
// Generate a random float between min and max (inclusive)
|
||||||
return dist(gen);
|
return dist(gen);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -1,15 +1,27 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
#define FIFO_WHO_AM_I "AI"
|
||||||
|
#define FIFO_TO_GIMBAL "/tmp/fifo_to_a8_gimbal"
|
||||||
|
#define FIFO_FROM_GIMBAL "/tmp/fifo_from_a8_gimbal"
|
||||||
|
//#define FIFO_TEST
|
||||||
|
|
||||||
class RemoteControl
|
class RemoteControl
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RemoteControl();
|
RemoteControl();
|
||||||
~RemoteControl();
|
~RemoteControl();
|
||||||
void createNamedPipe(void);
|
void createNamedPipe(void);
|
||||||
void startCommunication(void);
|
void sendData(uint16_t top, uint16_t left, uint16_t bottom, uint16_t right);
|
||||||
|
#ifdef FIFO_TEST
|
||||||
|
void startTest(void);
|
||||||
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
#ifdef FIFO_TEST
|
||||||
float randomFloatBetween(float min, float max);
|
float randomFloatBetween(float min, float max);
|
||||||
|
#endif
|
||||||
int mFifoFdIn;
|
int mFifoFdIn;
|
||||||
int mFifoFdOut;
|
int mFifoFdOut;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user