Set camera ready for lift and drop

Added functionality to set camera ready for bringing it down or up.
Camera will be made available for AI after bringCameraDown command is given via UDPSocket.
Camera will be made unavailable for AI after bringCameraUp command is given via UDPSocket.
This commit is contained in:
Nffj84
2025-03-24 18:01:47 +02:00
parent f1023788e5
commit deb607237e
4 changed files with 161 additions and 74 deletions
+61 -4
View File
@@ -11,10 +11,12 @@ AiEngineGimbalServer::AiEngineGimbalServer(QObject *parent)
mIsAvailable = false;
qDebug() << "Initial is available: " << mIsAvailable;
QTimer::singleShot(5000, this, [this]() {
mIsAvailable = true;
qDebug() << "Initial is available: " << mIsAvailable;
});
// Commented out, might be required later
// Making camera available is currently do in processUdpCommands() with command bringCameraDown
//QTimer::singleShot(5000, this, [this]() {
// mIsAvailable = true;
// qDebug() << "Initial is available: " << mIsAvailable;
//});
mActions.setup(&mUdpSocket, &mUdpCommand, &mUdpResponse, &mGimbalStatus);
@@ -26,6 +28,13 @@ AiEngineGimbalServer::AiEngineGimbalServer(QObject *parent)
mDronePosition.yaw = 90.0;
connect(&mActions, &AiEngineGimbalServerActions::aiTargetZoomed, this, &AiEngineGimbalServer::aiTargetZoomed);
// Create and bind the new UDP socket for receiving commands
mReceiveUdpSocket = new QUdpSocket(this);
mReceiveUdpSocket->bind(QHostAddress::LocalHost, 45454);
// Connect the socket to handle incoming messages
connect(mReceiveUdpSocket, &QUdpSocket::readyRead, this, &AiEngineGimbalServer::processUdpCommands);
}
@@ -101,3 +110,51 @@ void AiEngineGimbalServer::cameraPositionSlot(AiEngineCameraPosition position)
{
qDebug() << "AiEngineGimbalServer::cameraPositionSlot() Move camera to:" << position.pitch << position.yaw << "zoom:" << position.zoom;
}
void AiEngineGimbalServer::processUdpCommands(void) {
while (mReceiveUdpSocket->hasPendingDatagrams()) {
QByteArray datagram;
datagram.resize(mReceiveUdpSocket->pendingDatagramSize());
mReceiveUdpSocket->readDatagram(datagram.data(), datagram.size());
QString command = QString::fromUtf8(datagram);
qDebug() << "Received command:" << command;
if (command == "bringCameraDown") {
mActions.setAllowCameraCommands(true); // This will allow other camera commands
mActions.goToInitialOrientation();
// 10 second delay to let camera get ready for AI
QTimer::singleShot(10000, this, [this]() {
mIsAvailable = true;
qDebug() << "Camera set available and to initial position";
});
}
else if (command == "bringCameraUp") {
// No delay, set camera unavailable
mActions.setAllowCameraCommands(false); // This will prevent any ongoing commands
mIsAvailable = false;
mActions.goToInitialOrientation();
qDebug() << "Camera set unavailable and to initial position";
}
}
/*
// How to call this:
#include <QUdpSocket>
void sendCommand(const QString &command) {
QUdpSocket udpSocket;
QByteArray datagram = command.toUtf8();
udpSocket.writeDatagram(datagram, QHostAddress::LocalHost, 45454);
}
int main() {
sendCommand("bringCameraDown");
sendCommand("bringCameraUp");
return 0;
}
*/
}