moved reader out of miSim, went to event-based guidance
This commit is contained in:
@@ -79,7 +79,6 @@ classdef miSim
|
|||||||
[obj] = plotH(obj);
|
[obj] = plotH(obj);
|
||||||
[obj] = updatePlots(obj);
|
[obj] = updatePlots(obj);
|
||||||
[obj] = teardown(obj);
|
[obj] = teardown(obj);
|
||||||
inits = readScenarioCsv(csvPath);
|
|
||||||
writeInits(obj);
|
writeInits(obj);
|
||||||
validate(obj);
|
validate(obj);
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -229,13 +229,18 @@ class UAVRunner(BasicRunner):
|
|||||||
target = self.origin + VectorNED(north=enu_y, east=enu_x, down=-enu_z)
|
target = self.origin + VectorNED(north=enu_y, east=enu_x, down=-enu_z)
|
||||||
|
|
||||||
if in_guidance:
|
if in_guidance:
|
||||||
# Guidance mode: non-blocking — cancel previous nav and start new
|
# Guidance mode (event-triggered): navigate to target,
|
||||||
|
# then send ACK once arrived so the controller knows
|
||||||
|
# all UAVs have reached their targets before it
|
||||||
|
# requests positions and computes the next step.
|
||||||
print(f"[UAV] Guidance TARGET: E={enu_x:.1f} N={enu_y:.1f} U={enu_z:.1f}")
|
print(f"[UAV] Guidance TARGET: E={enu_x:.1f} N={enu_y:.1f} U={enu_z:.1f}")
|
||||||
if nav_task and not nav_task.done():
|
if nav_task and not nav_task.done():
|
||||||
nav_task.cancel()
|
nav_task.cancel()
|
||||||
await asyncio.gather(nav_task, return_exceptions=True)
|
await asyncio.gather(nav_task, return_exceptions=True)
|
||||||
nav_task = asyncio.create_task(drone.goto_coordinates(target))
|
await drone.goto_coordinates(target)
|
||||||
# No ACK/READY in guidance mode
|
await send_message_type(writer, MessageType.ACK)
|
||||||
|
print("[UAV] Sent ACK (arrived at guidance target)")
|
||||||
|
nav_task = None
|
||||||
else:
|
else:
|
||||||
# Sequential mode: ACK → navigate → READY
|
# Sequential mode: ACK → navigate → READY
|
||||||
waypoint_num += 1
|
waypoint_num += 1
|
||||||
|
|||||||
@@ -1095,7 +1095,7 @@
|
|||||||
</Artifacts>
|
</Artifacts>
|
||||||
<BuildFolder type="coderapp.internal.util.mfz.FileSpec"/>
|
<BuildFolder type="coderapp.internal.util.mfz.FileSpec"/>
|
||||||
<Success>true</Success>
|
<Success>true</Success>
|
||||||
<Timestamp>2026-03-03T15:05:52</Timestamp>
|
<Timestamp>2026-03-03T15:32:50</Timestamp>
|
||||||
</MainBuildResult>
|
</MainBuildResult>
|
||||||
</coderapp.internal.mlc.mfz.MatlabCoderProjectState>
|
</coderapp.internal.mlc.mfz.MatlabCoderProjectState>
|
||||||
</MF0>
|
</MF0>
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ for w = 1:numWaypoints
|
|||||||
target = targets(targetIdx, :);
|
target = targets(targetIdx, :);
|
||||||
|
|
||||||
if coder.target('MATLAB')
|
if coder.target('MATLAB')
|
||||||
disp(['Sending TARGET to client ', num2str(i), ' (waypoint ', num2str(w), '): ', ...
|
disp([datestr(now, 'HH:MM:SS'), ' Sending TARGET to client ', num2str(i), ' (waypoint ', num2str(w), '): ', ...
|
||||||
num2str(target(1)), ',', num2str(target(2)), ',', num2str(target(3))]);
|
num2str(target(1)), ',', num2str(target(2)), ',', num2str(target(3))]);
|
||||||
else
|
else
|
||||||
coder.ceval('sendTarget', int32(i), coder.ref(target));
|
coder.ceval('sendTarget', int32(i), coder.ref(target));
|
||||||
@@ -105,7 +105,6 @@ end
|
|||||||
% ---- Phase 2: miSim guidance loop ----------------------------------------
|
% ---- Phase 2: miSim guidance loop ----------------------------------------
|
||||||
% Guidance parameters (adjust here and recompile as needed)
|
% Guidance parameters (adjust here and recompile as needed)
|
||||||
MAX_GUIDANCE_STEPS = int32(100); % number of guidance iterations
|
MAX_GUIDANCE_STEPS = int32(100); % number of guidance iterations
|
||||||
GUIDANCE_RATE_MS = int32(5000); % ms between iterations (0.2 Hz default)
|
|
||||||
|
|
||||||
% Enter guidance mode on all clients
|
% Enter guidance mode on all clients
|
||||||
if ~coder.target('MATLAB')
|
if ~coder.target('MATLAB')
|
||||||
@@ -124,36 +123,37 @@ end
|
|||||||
guidance_step(positions(1:numClients, :), true, ...
|
guidance_step(positions(1:numClients, :), true, ...
|
||||||
scenarioParams, obstacleMin, obstacleMax, numObstacles);
|
scenarioParams, obstacleMin, obstacleMax, numObstacles);
|
||||||
|
|
||||||
% Main guidance loop
|
% Main guidance loop (event-triggered)
|
||||||
for step = 1:MAX_GUIDANCE_STEPS
|
for step = 1:MAX_GUIDANCE_STEPS
|
||||||
% Query current GPS positions from all clients
|
% Run one guidance step: feed current GPS positions in, get targets out
|
||||||
if ~coder.target('MATLAB')
|
|
||||||
coder.ceval('sendRequestPositions', int32(numClients));
|
|
||||||
coder.ceval('recvPositions', int32(numClients), coder.ref(positions), int32(MAX_CLIENTS));
|
|
||||||
end
|
|
||||||
|
|
||||||
% Run one guidance step: feed GPS positions in, get targets out
|
|
||||||
nextPositions = guidance_step(positions(1:numClients, :), false, ...
|
nextPositions = guidance_step(positions(1:numClients, :), false, ...
|
||||||
scenarioParams, obstacleMin, obstacleMax, numObstacles);
|
scenarioParams, obstacleMin, obstacleMax, numObstacles);
|
||||||
|
|
||||||
% Send target to each client (no ACK/READY expected in guidance mode)
|
% Send target to each client
|
||||||
for i = 1:numClients
|
for i = 1:numClients
|
||||||
target = nextPositions(i, :);
|
target = nextPositions(i, :);
|
||||||
if ~coder.target('MATLAB')
|
if ~coder.target('MATLAB')
|
||||||
coder.ceval('sendTarget', int32(i), coder.ref(target));
|
coder.ceval('sendTarget', int32(i), coder.ref(target));
|
||||||
else
|
else
|
||||||
disp(['[guidance] target UAV ', num2str(i), ': ', num2str(target)]);
|
disp([datestr(now, 'HH:MM:SS'), ' [guidance] target UAV ', num2str(i), ': ', num2str(target)]);
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
% Simulation: advance positions to guidance outputs for closed-loop feedback
|
% Wait for ACK from all clients (each UAV ACKs when it arrives at its target)
|
||||||
if coder.target('MATLAB')
|
|
||||||
positions(1:numClients, :) = nextPositions(1:numClients, :);
|
|
||||||
end
|
|
||||||
|
|
||||||
% Wait for the guidance rate interval before the next iteration
|
|
||||||
if ~coder.target('MATLAB')
|
if ~coder.target('MATLAB')
|
||||||
coder.ceval('sleepMs', int32(GUIDANCE_RATE_MS));
|
coder.ceval('waitForAllMessageType', int32(numClients), ...
|
||||||
|
int32(MESSAGE_TYPE.ACK));
|
||||||
|
else
|
||||||
|
disp(['[guidance] step ', num2str(step), ': all UAVs arrived']);
|
||||||
|
end
|
||||||
|
|
||||||
|
% Request current GPS positions from all clients
|
||||||
|
if ~coder.target('MATLAB')
|
||||||
|
coder.ceval('sendRequestPositions', int32(numClients));
|
||||||
|
coder.ceval('recvPositions', int32(numClients), coder.ref(positions), int32(MAX_CLIENTS));
|
||||||
|
else
|
||||||
|
% Simulation: advance positions to guidance outputs for closed-loop feedback
|
||||||
|
positions(1:numClients, :) = nextPositions(1:numClients, :);
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -419,7 +419,13 @@ int sendTarget(int clientId, const double* coords) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "Sent TARGET to client " << clientId << ": "
|
// Timestamp
|
||||||
|
time_t now = time(nullptr);
|
||||||
|
struct tm* lt = localtime(&now);
|
||||||
|
char ts[16];
|
||||||
|
strftime(ts, sizeof(ts), "%H:%M:%S", lt);
|
||||||
|
|
||||||
|
std::cout << ts << " Sent TARGET to client " << clientId << ": "
|
||||||
<< coords[0] << "," << coords[1] << "," << coords[2] << "\n";
|
<< coords[0] << "," << coords[1] << "," << coords[2] << "\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
function scenario = readScenarioCsv(obj, csvPath)
|
function scenario = readScenarioCsv(csvPath)
|
||||||
arguments (Input)
|
arguments (Input)
|
||||||
obj (1, 1) {mustBeA(obj, 'miSim')}; %#ok<INUSA>
|
|
||||||
csvPath (1, 1) string;
|
csvPath (1, 1) string;
|
||||||
end
|
end
|
||||||
arguments (Output)
|
arguments (Output)
|
||||||
Reference in New Issue
Block a user