stagger takeoff/landing for increased spacing

This commit is contained in:
kdee committed 2026-06-02 20:43:56 -07:00
1 parent 0adaf0b350
commit 1479892014
6 files changed
+331 -422

No files matched your search

+28
View File
@@ -512,6 +512,7 @@ static const char* messageTypeName(uint8_t msgType) {
case 6: return "GUIDANCE_TOGGLE";
case 7: return "REQUEST_POSITION";
case 8: return "POSITION";
case 9: return "TAKEOFF";
default: return "UNKNOWN";
}
}
@@ -614,6 +615,33 @@ int waitForAllMessageType(int numClients, int expectedType) {
return 1;
}
// Wait for a specific message type from a SINGLE client (blocking).
// Used by the staggered flyout/flyback, where the controller waits on one UAV
// while the other is still flying its own (offset) event. Skips past any
// unexpected byte and returns 0 on disconnect/error, 1 on success.
int waitForClientMessageType(int clientId, int expectedType) {
if (clientId <= 0 || clientId > (int)clientSockets.size()) return 0;
int sock = clientSockets[clientId - 1];
uint8_t expected = (uint8_t)expectedType;
while (true) {
uint8_t msg;
int len = recv(sock, &msg, 1, MSG_WAITALL);
if (len <= 0) {
std::cerr << logPrefix() << "waitForClientMessageType: client " << clientId
<< " disconnected while waiting for " << messageTypeName(expected) << "\n";
return 0;
}
if (msg == expected) {
std::cout << logPrefix() << "Received " << messageTypeName(expected)
<< " from client " << clientId << "\n";
return 1;
}
std::cerr << logPrefix() << "Unexpected " << messageTypeName(msg) << " from client "
<< clientId << " (expected " << messageTypeName(expected) << ")\n";
}
}
// Broadcast GUIDANCE_TOGGLE to all clients
void sendGuidanceToggle(int numClients) {
for (int i = 1; i <= numClients; i++) {
+3
View File
@@ -61,6 +61,9 @@ int loadObstacles(const char* filename,
int sendMessageType(int clientId, int msgType);
int sendTarget(int clientId, const double* coords);
int waitForAllMessageType(int numClients, int expectedType);
// Block until a SINGLE client sends expectedType (used by the staggered
// flyout/flyback to wait on one UAV while the other is mid-flight).
int waitForClientMessageType(int clientId, int expectedType);
// Guidance loop operations
void setGuidanceStep(int step, int totalSteps); // call at the top of each guidance iteration