mirror of
https://github.com/azaion/autopilot.git
synced 2026-04-22 22:06:34 +00:00
Removed build folder.
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
#include <QDebug>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QThread>
|
||||
#include <QObject>
|
||||
#include <QTimer>
|
||||
#include "config.hpp"
|
||||
#include "defines.hpp"
|
||||
@@ -79,9 +79,14 @@ void RemoteControl::openNamedPipe()
|
||||
}
|
||||
}
|
||||
|
||||
void RemoteControl::whenDone(void)
|
||||
void RemoteControl::sendResponse(void)
|
||||
{
|
||||
// All is done, no it's time to rest
|
||||
QJsonDocument responseDocument(mResponseObject);
|
||||
std::string response = responseDocument.toJson(QJsonDocument::Compact).toStdString();
|
||||
write(mFifoFdOut, response.c_str(), response.size());
|
||||
qDebug().noquote().nospace() << "Sent: " << response;
|
||||
|
||||
mIsBusy = false;
|
||||
}
|
||||
|
||||
void RemoteControl::restoreOrientation(void)
|
||||
@@ -97,6 +102,8 @@ void RemoteControl::restoreOrientation(void)
|
||||
|
||||
qDebug().noquote().nospace() << serialCommandAngle;
|
||||
Config::getSerial()->sendCommand(serialCommandAngle);
|
||||
|
||||
QTimer::singleShot(1000, this, [this]() mutable { sendResponse(); });
|
||||
}
|
||||
|
||||
void RemoteControl::restoreZoom(void)
|
||||
@@ -112,9 +119,11 @@ void RemoteControl::restoreZoom(void)
|
||||
|
||||
qDebug().noquote().nospace() << serialCommandZoom.toStdString();
|
||||
Config::getSerial()->sendCommand(serialCommandZoom);
|
||||
|
||||
QTimer::singleShot(3000, this, [this]() mutable { restoreOrientation(); });
|
||||
}
|
||||
|
||||
QJsonObject RemoteControl::calculateTargetPosition(QJsonObject &commandObject, QJsonObject &responseObject)
|
||||
void RemoteControl::calculateTargetPosition(QJsonObject &commandObject)
|
||||
{
|
||||
qDebug().noquote().nospace() << "Calculating?";
|
||||
|
||||
@@ -129,11 +138,11 @@ QJsonObject RemoteControl::calculateTargetPosition(QJsonObject &commandObject, Q
|
||||
//float targetRealHeight = commandObject["target_real_height"].toDouble();
|
||||
|
||||
GPSData gpsData = UtilsTargetLocation::getLocation(altitude, latitude, longitude, yaw, pitch, 0.0f, targetRealWidth, targetPixelWidth);
|
||||
responseObject["altitude"] = gpsData.altitude;
|
||||
responseObject["latitude"] = gpsData.latitude;
|
||||
responseObject["longitude"] = gpsData.longitude;
|
||||
mResponseObject["altitude"] = gpsData.altitude;
|
||||
mResponseObject["latitude"] = gpsData.latitude;
|
||||
mResponseObject["longitude"] = gpsData.longitude;
|
||||
|
||||
return responseObject;
|
||||
QTimer::singleShot(3000, this, [this, commandObject]() mutable { zoomToTarget(commandObject); });
|
||||
}
|
||||
|
||||
void RemoteControl::turnToTarget(QJsonObject &commandObject)
|
||||
@@ -158,6 +167,8 @@ void RemoteControl::turnToTarget(QJsonObject &commandObject)
|
||||
serialCommandTurn[11] = degreesVal >> 8;
|
||||
|
||||
Config::getSerial()->sendCommand(serialCommandTurn);
|
||||
|
||||
QTimer::singleShot(3000, this, [this, commandObject]() mutable { calculateTargetPosition(commandObject); });
|
||||
}
|
||||
|
||||
void RemoteControl::zoomToTarget(QJsonObject &commandObject)
|
||||
@@ -186,79 +197,56 @@ void RemoteControl::zoomToTarget(QJsonObject &commandObject)
|
||||
serialCommandNewZoom[9] = scaledFractional;
|
||||
|
||||
Config::getSerial()->sendCommand(serialCommandNewZoom);
|
||||
|
||||
QTimer::singleShot(10000, this, [this, commandObject]() mutable { restoreZoom(); });
|
||||
}
|
||||
|
||||
void RemoteControl::run()
|
||||
{
|
||||
mIsBusy = false;
|
||||
|
||||
while (true) {
|
||||
char buffer[1024];
|
||||
ssize_t bytesRead = read(mFifoFdIn, buffer, sizeof(buffer) - 1);
|
||||
if (mIsBusy == false) {
|
||||
char buffer[1024];
|
||||
ssize_t bytesRead = read(mFifoFdIn, buffer, sizeof(buffer) - 1);
|
||||
|
||||
if (bytesRead > 0) {
|
||||
buffer[bytesRead] = '\0';
|
||||
if (bytesRead > 0) {
|
||||
buffer[bytesRead] = '\0';
|
||||
|
||||
QJsonDocument commandDoc = QJsonDocument::fromJson(buffer);
|
||||
QJsonDocument commandDoc = QJsonDocument::fromJson(buffer);
|
||||
|
||||
// Ignore non json messages
|
||||
if (commandDoc.isNull() == false) {
|
||||
QJsonObject commandObject = commandDoc.object();
|
||||
// Ignore non json messages
|
||||
if (commandDoc.isNull() == false) {
|
||||
QJsonObject commandObject = commandDoc.object();
|
||||
|
||||
// Ignore own messages and messages that don't have sender
|
||||
if (commandObject.contains("sender") == false || commandObject["sender"] == FIFO_WHO_AM_I) {
|
||||
continue;
|
||||
// Ignore own messages and messages that don't have sender
|
||||
if (commandObject.contains("sender") == false || commandObject["sender"] == FIFO_WHO_AM_I) {
|
||||
continue;
|
||||
}
|
||||
|
||||
QString message = QString::fromUtf8(buffer);
|
||||
qDebug().noquote().nospace() << "Received: " << message;
|
||||
|
||||
// Exit with exit message
|
||||
if (commandObject.contains("extra") == true && commandObject["extra"] == "EXIT") {
|
||||
return;
|
||||
}
|
||||
|
||||
mIsBusy = true;
|
||||
|
||||
// Prepare responce object
|
||||
mResponseObject = QJsonObject();
|
||||
mResponseObject["sender"] = FIFO_WHO_AM_I;
|
||||
mResponseObject["status"] = "OK";
|
||||
|
||||
// Get current orientation and zoom
|
||||
Config::updateState();
|
||||
|
||||
QTimer::singleShot(0, this, [this, commandObject]() mutable { turnToTarget(commandObject); });
|
||||
}
|
||||
|
||||
QString message = QString::fromUtf8(buffer);
|
||||
qDebug().noquote().nospace() << "Received: " << message;
|
||||
|
||||
// Exit with exit message
|
||||
if (commandObject.contains("EXIT") == true) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Prepare responce object
|
||||
QJsonObject responseObject;
|
||||
responseObject["sender"] = FIFO_WHO_AM_I;
|
||||
responseObject["status"] = "OK";
|
||||
|
||||
// Get current orientation and zoom
|
||||
Config::updateState();
|
||||
|
||||
// Turn to target
|
||||
if (commandObject.contains("target_x") == true && commandObject.contains("target_y") == true) {
|
||||
QTimer::singleShot(100, this, [this, commandObject]() mutable { turnToTarget(commandObject); });
|
||||
QTimer::singleShot(1000, this, &RemoteControl::whenDone);
|
||||
}
|
||||
|
||||
// Calculate target location
|
||||
if (commandObject.contains("latitude") == true && commandObject.contains("longitude") == true && commandObject.contains("altitude") == true && commandObject.contains("yaw") == true && commandObject.contains("pitch") == true && commandObject.contains("target_pixel_width") == true && commandObject.contains("target_pixel_height") == true && commandObject.contains("target_real_width") == true && commandObject.contains("target_real_height") == true) {
|
||||
responseObject = calculateTargetPosition(commandObject, responseObject);
|
||||
QTimer::singleShot(1000, this, &RemoteControl::whenDone);
|
||||
}
|
||||
|
||||
// Zoom to target
|
||||
if (commandObject.contains("target_pixel_width") == true && commandObject.contains("target_pixel_height") == true) {
|
||||
QTimer::singleShot(100, this, [this, commandObject]() mutable { zoomToTarget(commandObject); });
|
||||
QTimer::singleShot(1000, this, &RemoteControl::whenDone);
|
||||
}
|
||||
|
||||
// Restore previous zoom and orientation
|
||||
QTimer::singleShot(100, this, &RemoteControl::restoreZoom);
|
||||
QTimer::singleShot(1000, this, &RemoteControl::whenDone);
|
||||
|
||||
QTimer::singleShot(100, this, &RemoteControl::restoreOrientation);
|
||||
QTimer::singleShot(1000, this, &RemoteControl::whenDone);
|
||||
|
||||
// Respond after doing camera things
|
||||
QJsonDocument responseDocument(responseObject);
|
||||
std::string response = responseDocument.toJson(QJsonDocument::Compact).toStdString();
|
||||
write(mFifoFdOut, response.c_str(), response.size());
|
||||
qDebug().noquote().nospace() << "Sent: " << response;
|
||||
QCoreApplication::processEvents();
|
||||
}
|
||||
}
|
||||
|
||||
// Sleep for a while
|
||||
QCoreApplication::processEvents();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <QJsonObject>
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <QThread>
|
||||
|
||||
class RemoteControl : public QObject
|
||||
{
|
||||
@@ -11,18 +12,20 @@ class RemoteControl : public QObject
|
||||
public:
|
||||
RemoteControl();
|
||||
~RemoteControl();
|
||||
void openNamedPipe(void);
|
||||
void run();
|
||||
|
||||
private slots:
|
||||
QJsonObject calculateTargetPosition(QJsonObject &commandObject, QJsonObject &responseObject);
|
||||
void sendResponse(void);
|
||||
void calculateTargetPosition(QJsonObject &commandObject);
|
||||
void turnToTarget(QJsonObject &commandObject);
|
||||
void zoomToTarget(QJsonObject &commandObject);
|
||||
void restoreOrientation(void);
|
||||
void restoreZoom(void);
|
||||
void whenDone(void);
|
||||
|
||||
private:
|
||||
void openNamedPipe(void);
|
||||
bool mIsBusy;
|
||||
int mFifoFdIn;
|
||||
int mFifoFdOut;
|
||||
QJsonObject mResponseObject;
|
||||
};
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "serialPort.hpp"
|
||||
#include <QCoreApplication>
|
||||
#include <QDebug>
|
||||
#include <QTimer>
|
||||
#include "defines.hpp"
|
||||
#include "utilsCRC16.hpp"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user