diff --git a/aerpaw/controller.coderprj b/aerpaw/controller.coderprj
index b057661..7b72992 100644
--- a/aerpaw/controller.coderprj
+++ b/aerpaw/controller.coderprj
@@ -163,6 +163,11 @@
+
+ int32
+
+
+
@@ -1178,7 +1183,7 @@
true
- 2026-04-05T14:48:49
+ 2026-04-06T20:46:55
diff --git a/aerpaw/controller.m b/aerpaw/controller.m
index 6ed3a19..1b00cf9 100644
--- a/aerpaw/controller.m
+++ b/aerpaw/controller.m
@@ -42,9 +42,10 @@ end
% TRANSIT_ALT_STEP must exceed 2 * max(collisionRadius).
% Waypoint 1: each UAV flies to (finalX, finalY) at its unique transit altitude.
% Waypoint 2: each UAV adjusts to its actual target altitude.
+% These constants are also used for the altitude-staggered return before RTL.
+TRANSIT_ALT_BASE = 25.0; % must match drone.takeoff() altitude in uav_runner.py
+TRANSIT_ALT_STEP = 25; % vertical separation per UAV (m); must exceed 2*collisionRadius
if ~coder.target('MATLAB')
- TRANSIT_ALT_BASE = 25.0; % must match drone.takeoff() altitude in uav_runner.py
- TRANSIT_ALT_STEP = 25; % vertical separation per UAV (m); must exceed 2*collisionRadius
for ii = double(totalLoaded):-1:1
transitRow = (ii - 1) * 2 + 1;
finalRow = (ii - 1) * 2 + 2;
@@ -190,6 +191,21 @@ if ~coder.target('MATLAB')
end
% --------------------------------------------------------------------------
+% Altitude-staggered return: separate UAVs vertically before issuing RTL,
+% mirroring the initial positioning stagger so UAVs transit laterally at
+% unique altitudes and cannot collide during the return flight.
+if ~coder.target('MATLAB')
+ for i = 1:numClients
+ transitAlt = TRANSIT_ALT_BASE + (double(i) - 1) * TRANSIT_ALT_STEP;
+ target = [positions(i, 1), positions(i, 2), transitAlt];
+ coder.ceval('sendTarget', int32(i), coder.ref(target));
+ end
+ coder.ceval('waitForAllMessageType', int32(numClients), int32(MESSAGE_TYPE.ACK));
+ coder.ceval('waitForAllMessageType', int32(numClients), int32(MESSAGE_TYPE.READY));
+else
+ disp('Altitude-staggered return (simulation): UAVs commanded to transit altitudes.');
+end
+
% Send RTL command to all clients
for i = 1:numClients
if coder.target('MATLAB')
diff --git a/aerpaw/results/plotGpsLogs.m b/aerpaw/results/plotGpsLogs.m
index 637bfd9..a5d1206 100644
--- a/aerpaw/results/plotGpsLogs.m
+++ b/aerpaw/results/plotGpsLogs.m
@@ -79,7 +79,7 @@ function [f, G] = plotGpsLogs(logDirs, seaToGroundLevel, plotWholeFlight)
fprintf("Minimum distance between agents %d and %d is %2.3f\n", ii, jj, min(d));
if min(d) < 6
- warning("Minimum distance between agents %d and %d of %2.3f is questionable for AERPAW", ii, jj, min(d);
+ warning("Minimum distance between agents %d and %d of %2.3f is questionable for AERPAW", ii, jj, min(d));
end
end
diff --git a/aerpaw/results/resultsAnalysis.m b/aerpaw/results/resultsAnalysis.m
index d480a72..2d13f69 100644
--- a/aerpaw/results/resultsAnalysis.m
+++ b/aerpaw/results/resultsAnalysis.m
@@ -1,5 +1,5 @@
%% Plot AERPAW logs (trajectory, radio)
-resultsPath = fullfile(matlab.project.rootProject().RootFolder, "sandbox", "two_around_wall"); % Define path to results copied from AERPAW platform
+resultsPath = fullfile(matlab.project.rootProject().RootFolder, "sandbox", "test2"); % Define path to results copied from AERPAW platform
% Measure intervals between issuing commands from the controller
% (make sure this is ~4-5 seconds at minimum to avoid overwhelming the UAV autopilot)
@@ -16,8 +16,8 @@ fprintf("Minimum command spacing: %2.3f seconds\n", seconds(min(dt)));
fprintf("Maximum command spacing: %2.3f seconds\n", seconds(max(dt)));
fprintf("Mean command spacing: %2.3f seconds\n", seconds(mean(dt)));
fprintf("Median command spacing: %2.3f seconds\n", seconds(median(dt)));
-if seconds(min(dt)) > 4
- warning("Minimum command spacing %2.3f questionably short for AERPAW", min(dt));
+if seconds(min(dt)) < 4
+ warning("Minimum command spacing %2.3f questionably short for AERPAW", seconds(min(dt)));
end
% Plot GPS logged data and scenario information (domain, objective, obstacles)