mirror of
https://github.com/azaion/autopilot.git
synced 2026-04-22 11:16:34 +00:00
Removed blocking code from a8 and a8 remote.
This commit is contained in:
@@ -6,8 +6,8 @@ CONFIG += c++17 console
|
|||||||
|
|
||||||
TARGET = a8
|
TARGET = a8
|
||||||
|
|
||||||
QMAKE_CXXFLAGS = -O0 -g -ggdb -fsanitize=address,bounds,float-divide-by-zero,integer-divide-by-zero,null,return,signed-integer-overflow,unreachable,shift,alignment,nonnull-attribute,returns-nonnull-attribute,enum
|
QMAKE_CXXFLAGS = -O0 -g -ggdb -fsanitize=undefined,address,bounds,float-divide-by-zero,integer-divide-by-zero,null,return,signed-integer-overflow,unreachable,shift,alignment,nonnull-attribute,returns-nonnull-attribute,enum
|
||||||
QMAKE_LFLAGS = -O0 -g -ggdb -fsanitize=address,bounds,float-divide-by-zero,integer-divide-by-zero,null,return,signed-integer-overflow,unreachable,shift,alignment,nonnull-attribute,returns-nonnull-attribute,enum
|
QMAKE_LFLAGS = -O0 -g -ggdb -fsanitize=undefined,address,bounds,float-divide-by-zero,integer-divide-by-zero,null,return,signed-integer-overflow,unreachable,shift,alignment,nonnull-attribute,returns-nonnull-attribute,enum
|
||||||
|
|
||||||
QMAKE_CXX = clang++
|
QMAKE_CXX = clang++
|
||||||
QMAKE_CC = clang
|
QMAKE_CC = clang
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ void RemoteControl::openNamedPipe()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mFifoFdIn = open(FIFO_TO_GIMBAL, O_RDONLY | O_NONBLOCK);
|
mFifoFdIn = open(FIFO_TO_GIMBAL, O_RDWR | O_NONBLOCK);
|
||||||
if (mFifoFdIn == -1) {
|
if (mFifoFdIn == -1) {
|
||||||
qCritical().noquote().nospace() << "Error opening pipe for reading: " << FIFO_TO_GIMBAL;
|
qCritical().noquote().nospace() << "Error opening pipe for reading: " << FIFO_TO_GIMBAL;
|
||||||
} else {
|
} else {
|
||||||
@@ -206,14 +206,38 @@ void RemoteControl::zoomToTarget(QJsonObject &commandObject)
|
|||||||
|
|
||||||
RectangleProperties RemoteControl::calculateRectangleProperties(uint16_t top, uint16_t left, uint16_t bottom, uint16_t right)
|
RectangleProperties RemoteControl::calculateRectangleProperties(uint16_t top, uint16_t left, uint16_t bottom, uint16_t right)
|
||||||
{
|
{
|
||||||
RectangleProperties properties;
|
// Sanity check
|
||||||
|
// top cannot be greater than bottom
|
||||||
|
// left cannot be greater than right
|
||||||
|
if (top > bottom) {
|
||||||
|
uint16_t temp = top;
|
||||||
|
top = bottom;
|
||||||
|
bottom = temp;
|
||||||
|
qWarning().noquote().nospace() << "calculateRectangleProperties(): top and bottom mixed?";
|
||||||
|
}
|
||||||
|
if (left > right) {
|
||||||
|
uint16_t temp = left;
|
||||||
|
left = right;
|
||||||
|
right = temp;
|
||||||
|
qWarning().noquote().nospace() << "calculateRectangleProperties(): left and right mixed?";
|
||||||
|
}
|
||||||
|
|
||||||
|
RectangleProperties properties;
|
||||||
properties.width = right - left;
|
properties.width = right - left;
|
||||||
properties.height = bottom - top;
|
properties.height = bottom - top;
|
||||||
|
|
||||||
properties.middleX = static_cast<uint16_t>(left + properties.width / 2);
|
properties.middleX = static_cast<uint16_t>(left + properties.width / 2);
|
||||||
properties.middleY = static_cast<uint16_t>(top + properties.height / 2);
|
properties.middleY = static_cast<uint16_t>(top + properties.height / 2);
|
||||||
|
|
||||||
|
// Sanity check, none cannot be 0
|
||||||
|
// If that is the case, we will not turn or zoom
|
||||||
|
if (properties.height == 0 || properties.width == 0 || properties.middleX == 0 || properties.middleY == 0) {
|
||||||
|
properties.height = CAMERA_RESOLUTION_HEIGHT;
|
||||||
|
properties.width = CAMERA_RESOLUTION_WIDTH;
|
||||||
|
properties.middleX = CAMERA_RESOLUTION_WIDTH / 2;
|
||||||
|
properties.middleY = CAMERA_RESOLUTION_HEIGHT / 2;
|
||||||
|
qWarning().noquote().nospace() << "calculateRectangleProperties(): Something was zero -> No zoom, no turn!";
|
||||||
|
}
|
||||||
|
|
||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -265,6 +289,10 @@ void RemoteControl::run()
|
|||||||
commandObject["target_y"] = rectangle.middleY;
|
commandObject["target_y"] = rectangle.middleY;
|
||||||
commandObject["target_pixel_height"] = rectangle.height;
|
commandObject["target_pixel_height"] = rectangle.height;
|
||||||
commandObject["target_pixel_width"] = rectangle.width;
|
commandObject["target_pixel_width"] = rectangle.width;
|
||||||
|
qInfo() << "target_x: " << commandObject["target_x"];
|
||||||
|
qInfo() << "target_y: " << commandObject["target_y"];
|
||||||
|
qInfo() << "target_pixel_height: " << commandObject["target_pixel_height"];
|
||||||
|
qInfo() << "target_pixel_width: " << commandObject["target_pixel_width"];
|
||||||
|
|
||||||
mIsBusy = true;
|
mIsBusy = true;
|
||||||
|
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ CONFIG += c++17 console
|
|||||||
|
|
||||||
TARGET = a8_remote
|
TARGET = a8_remote
|
||||||
|
|
||||||
QMAKE_CXXFLAGS = -O0 -g -ggdb -fsanitize=undefined,bounds,float-divide-by-zero,integer-divide-by-zero,null,return,signed-integer-overflow,unreachable,shift,alignment,nonnull-attribute,returns-nonnull-attribute,enum
|
QMAKE_CXXFLAGS = -O0 -g -ggdb -fsanitize=undefined,address,bounds,float-divide-by-zero,integer-divide-by-zero,null,return,signed-integer-overflow,unreachable,shift,alignment,nonnull-attribute,returns-nonnull-attribute,enum
|
||||||
QMAKE_LFLAGS = -O0 -g -ggdb -fsanitize=undefined,bounds,float-divide-by-zero,integer-divide-by-zero,null,return,signed-integer-overflow,unreachable,shift,alignment,nonnull-attribute,returns-nonnull-attribute,enum
|
QMAKE_LFLAGS = -O0 -g -ggdb -fsanitize=undefined,address,bounds,float-divide-by-zero,integer-divide-by-zero,null,return,signed-integer-overflow,unreachable,shift,alignment,nonnull-attribute,returns-nonnull-attribute,enum
|
||||||
|
|
||||||
QMAKE_CXX = clang++
|
QMAKE_CXX = clang++
|
||||||
QMAKE_CC = clang
|
QMAKE_CC = clang
|
||||||
|
|||||||
@@ -85,13 +85,7 @@ void RemoteControl::createNamedPipe()
|
|||||||
|
|
||||||
void RemoteControl::sendData(uint16_t top, uint16_t left, uint16_t bottom, uint16_t right)
|
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}};
|
QJsonObject commandObject = {{"sender", FIFO_WHO_AM_I}, {"top", top}, {"left", left}, {"bottom", bottom}, {"right", right}};
|
||||||
|
|
||||||
QJsonDocument commandDocument(commandObject);
|
QJsonDocument commandDocument(commandObject);
|
||||||
std::string command = commandDocument.toJson(QJsonDocument::Compact).toStdString();
|
std::string command = commandDocument.toJson(QJsonDocument::Compact).toStdString();
|
||||||
write(mFifoFdOut, command.c_str(), command.size());
|
write(mFifoFdOut, command.c_str(), command.size());
|
||||||
@@ -101,31 +95,38 @@ void RemoteControl::sendData(uint16_t top, uint16_t left, uint16_t bottom, uint1
|
|||||||
#ifdef FIFO_TEST
|
#ifdef FIFO_TEST
|
||||||
void RemoteControl::startTest()
|
void RemoteControl::startTest()
|
||||||
{
|
{
|
||||||
qInfo().noquote().nospace() << "Enter a command (0 to exit): ";
|
QJsonObject commandObject;
|
||||||
std::string input;
|
for (uint8_t i = 0; i < 5; i++) {
|
||||||
std::cin >> input;
|
qInfo().noquote().nospace() << "Enter a command (EXIT to exit): ";
|
||||||
|
std::string input;
|
||||||
|
std::cin >> input;
|
||||||
|
|
||||||
// Send command
|
// Send command
|
||||||
QJsonObject commandObject = {
|
QJsonObject commandObject = {
|
||||||
{"sender", FIFO_WHO_AM_I},
|
{"sender", FIFO_WHO_AM_I},
|
||||||
{"latitude", 63.155653611},
|
{"latitude", 63.155653611},
|
||||||
{"longitude", 23.827191389},
|
{"longitude", 23.827191389},
|
||||||
{"altitude", randomFloatBetween(10, 11)},
|
{"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(300, 979)},
|
{"target_x", (uint16_t) randomFloatBetween(300, 979)},
|
||||||
{"target_y", (uint16_t) randomFloatBetween(200, 519)},
|
{"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},
|
||||||
{"target_real_height", 2.5},
|
{"target_real_height", 2.5},
|
||||||
{"extra", input.c_str()},
|
{"extra", input.c_str()},
|
||||||
};
|
{"top", 100},
|
||||||
|
{"left", 100},
|
||||||
|
{"bottom", 200},
|
||||||
|
{"right", 200},
|
||||||
|
};
|
||||||
|
|
||||||
QJsonDocument commandDocument(commandObject);
|
QJsonDocument commandDocument(commandObject);
|
||||||
std::string command = commandDocument.toJson(QJsonDocument::Compact).toStdString();
|
std::string command = commandDocument.toJson(QJsonDocument::Compact).toStdString();
|
||||||
write(mFifoFdOut, command.c_str(), command.size());
|
write(mFifoFdOut, command.c_str(), command.size());
|
||||||
qDebug().noquote().nospace() << "Sent: " << command;
|
qDebug().noquote().nospace() << "Sent: " << command;
|
||||||
|
}
|
||||||
|
|
||||||
if (commandObject["extra"] == "EXIT") {
|
if (commandObject["extra"] == "EXIT") {
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
|
|||||||
Reference in New Issue
Block a user