Hard coded values to target location until real values are available.

Added function for remote which AI can call.
This commit is contained in:
Nffj84
2024-07-03 15:59:11 +03:00
parent f2dc975d9f
commit 3e0841b0ca
5 changed files with 73 additions and 20 deletions
+24 -8
View File
@@ -5,12 +5,13 @@
#include <QJsonObject>
#include <QThread>
#include <QTimer>
#include "defines.hpp"
#include <fcntl.h>
#include <iostream>
#include <random>
#include <sys/stat.h>
#include <unistd.h>
#ifdef FIFO_TEST
#include <random>
#endif
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): ";
std::string input;
@@ -86,11 +103,11 @@ void RemoteControl::startCommunication()
{"sender", FIFO_WHO_AM_I},
{"latitude", 63.155653611},
{"longitude", 23.827191389},
{"altitude", randomFloatBetween(100, 500)},
{"altitude", randomFloatBetween(10, 11)},
{"yaw", randomFloatBetween(0.0f, 360.0f)},
{"pitch", 0.0},
{"target_x", (uint16_t) randomFloatBetween(0, 1279)},
{"target_y", (uint16_t) randomFloatBetween(0, 719)},
{"target_x", (uint16_t) randomFloatBetween(300, 979)},
{"target_y", (uint16_t) randomFloatBetween(200, 519)},
{"target_pixel_width", 20},
{"target_pixel_height", 10},
{"target_real_width", 5},
@@ -139,8 +156,6 @@ void RemoteControl::startCommunication()
QCoreApplication::processEvents();
QThread::msleep(100);
}
return;
}
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)
return dist(gen);
}
#endif