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
+36 -5
View File
@@ -105,7 +105,7 @@ void RemoteControl::restoreOrientation(void)
Config::getSerial()->sendCommand(serialCommandAngle);
QTimer::singleShot(1000, this, [this]() mutable { sendResponse(); });
QTimer::singleShot(0, this, [this]() mutable { sendResponse(); });
}
void RemoteControl::restoreZoom(void)
@@ -123,7 +123,7 @@ void RemoteControl::restoreZoom(void)
Config::getSerial()->sendCommand(serialCommandZoom);
QTimer::singleShot(3000, this, [this]() mutable { restoreOrientation(); });
QTimer::singleShot(100, this, [this]() mutable { restoreOrientation(); });
}
void RemoteControl::calculateTargetPosition(QJsonObject &commandObject)
@@ -145,7 +145,7 @@ void RemoteControl::calculateTargetPosition(QJsonObject &commandObject)
mResponseObject["latitude"] = gpsData.latitude;
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)
@@ -171,7 +171,7 @@ void RemoteControl::turnToTarget(QJsonObject &commandObject)
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)
@@ -201,7 +201,20 @@ void RemoteControl::zoomToTarget(QJsonObject &commandObject)
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()
@@ -235,6 +248,24 @@ void RemoteControl::run()
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;
// Prepare responce object