added communications geometry

This commit is contained in:
2025-12-27 16:14:44 -08:00
parent 1d11ac4e90
commit 61cdb96102
8 changed files with 31 additions and 7 deletions

View File

@@ -28,6 +28,7 @@ classdef agent
% Communication
comRange = NaN;
commsGeometry = spherical;
performance = 0;
@@ -35,6 +36,7 @@ classdef agent
scatterPoints;
debug = false;
debugFig;
plotCommsGeometry = true;
end
methods (Access = public)

View File

@@ -1,4 +1,4 @@
function obj = initialize(obj, pos, vel, pan, tilt, collisionGeometry, sensorModel, guidanceModel, comRange, index, label, debug)
function obj = initialize(obj, pos, vel, pan, tilt, collisionGeometry, sensorModel, guidanceModel, comRange, index, label, debug, plotCommsGeometry)
arguments (Input)
obj (1, 1) {mustBeA(obj, 'agent')};
pos (1, 3) double;
@@ -12,6 +12,7 @@ function obj = initialize(obj, pos, vel, pan, tilt, collisionGeometry, sensorMod
index (1, 1) double = NaN;
label (1, 1) string = "";
debug (1, 1) logical = false;
plotCommsGeometry (1, 1) logical = true;
end
arguments (Output)
obj (1, 1) {mustBeA(obj, 'agent')};
@@ -24,10 +25,13 @@ function obj = initialize(obj, pos, vel, pan, tilt, collisionGeometry, sensorMod
obj.collisionGeometry = collisionGeometry;
obj.sensorModel = sensorModel;
obj.guidanceModel = guidanceModel;
obj.comRange = comRange;
obj.index = index;
obj.label = label;
obj.debug = debug;
obj.plotCommsGeometry = plotCommsGeometry;
% Add spherical geometry based on com range
obj.commsGeometry = obj.commsGeometry.initialize(obj.pos, comRange, REGION_TYPE.COMMS, sprintf("Agent %d Comms Geometry", obj.index));
if obj.debug
obj.debugFig = figure;

View File

@@ -30,6 +30,11 @@ function [obj, f] = plot(obj, ind, f)
% Plot collision geometry
[obj.collisionGeometry, f] = obj.collisionGeometry.plotWireframe(ind, f);
% Plot communications geometry
if obj.plotCommsGeometry
[obj.commsGeometry, f] = obj.commsGeometry.plotWireframe(ind, f);
end
% Plot FOV geometry
[obj.fovGeometry, f] = obj.fovGeometry.plot(ind, f);
end

View File

@@ -25,6 +25,17 @@ function updatePlots(obj)
end
end
% Communications geometry edges
if obj.plotCommsGeometry
for jj = 1:size(obj.commsGeometry.lines, 2)
for ii = 1:size(obj.collisionGeometry.lines(:, jj), 1)
obj.collisionGeometry.lines(ii, jj).XData = obj.collisionGeometry.lines(ii, jj).XData + deltaPos(1);
obj.collisionGeometry.lines(ii, jj).YData = obj.collisionGeometry.lines(ii, jj).YData + deltaPos(2);
obj.collisionGeometry.lines(ii, jj).ZData = obj.collisionGeometry.lines(ii, jj).ZData + deltaPos(3);
end
end
end
% Update FOV geometry surfaces
for jj = 1:size(obj.fovGeometry.surface, 2)
% Update each plot

View File

@@ -22,7 +22,7 @@ function obj = plot(obj)
% Plot objective gradient
obj.f = obj.domain.objective.plot(obj.objectivePlotIndices, obj.f);
% Plot agents and their collision geometries
% Plot agents and their collision/communications geometries
for ii = 1:size(obj.agents, 1)
[obj.agents{ii}, obj.f] = obj.agents{ii}.plot(obj.spatialPlotIndices, obj.f);
end

View File

@@ -12,7 +12,7 @@ function [obj] = updatePlots(obj, updatePartitions)
return;
end
% Update agent positions, collision geometries
% Update agent positions, collision/communication geometries
for ii = 1:size(obj.agents, 1)
obj.agents{ii}.updatePlots();
end

View File

@@ -9,6 +9,7 @@ classdef REGION_TYPE
OBSTACLE (2, [255, 127, 127]); % obstacle region
COLLISION (3, [255, 255, 128]); % collision avoidance region
FOV (4, [255, 165, 0]); % field of view region
COMMS (5, [0, 255, 0]); % comunications region
end
methods
function obj = REGION_TYPE(id, color)

View File

@@ -6,6 +6,7 @@ classdef test_miSim < matlab.unittest.TestCase
% Debug
makeVideo = true; % disable video writing for big performance increase
makePlots = true; % disable plotting for big performance increase (also disables video)
plotCommsGeometry = false; % disable plotting communications geometries
% Sim
maxIter = 250;
@@ -484,7 +485,7 @@ classdef test_miSim < matlab.unittest.TestCase
tc.agents{2} = tc.agents{2}.initialize(tc.domain.center - d, zeros(1,3), 0, 0, geometry2, sensor, @gradientAscent, 3, 2, sprintf("Agent %d", 2), false);
% Initialize the simulation
tc.testClass = tc.testClass.initialize(tc.domain, tc.domain.objective, tc.agents, tc.minAlt, tc.timestep, tc.partitoningFreq, cell(0, 1), tc.maxIter, tc.makeVideo);
tc.testClass = tc.testClass.initialize(tc.domain, tc.domain.objective, tc.agents, tc.minAlt, tc.timestep, tc.partitoningFreq, tc.maxIter, cell(0, 1), tc.makeVideo, tc.makePlots);
% Run the simulation
tc.testClass.run();
@@ -515,8 +516,8 @@ classdef test_miSim < matlab.unittest.TestCase
% Initialize agents
tc.agents = {agent; agent;};
tc.agents{1} = tc.agents{1}.initialize(tc.domain.center - d + [0, radius * 1.5, 0], zeros(1,3), 0, 0, geometry1, sensor, @gradientAscent, 5*radius, 1, sprintf("Agent %d", 1), false);
tc.agents{2} = tc.agents{2}.initialize(tc.domain.center - d - [0, radius * 1.5, 0] - [0, 1, 0], zeros(1,3), 0, 0, geometry2, sensor, @gradientAscent, 5*radius, 2, sprintf("Agent %d", 2), false);
tc.agents{1} = tc.agents{1}.initialize(tc.domain.center - d + [0, radius * 1.5, 0], zeros(1,3), 0, 0, geometry1, sensor, @gradientAscent, 4, 1, sprintf("Agent %d", 1), false, false);
tc.agents{2} = tc.agents{2}.initialize(tc.domain.center - d - [0, radius * 1.5, 0] - [0, 1, 0], zeros(1,3), 0, 0, geometry2, sensor, @gradientAscent, 4, 2, sprintf("Agent %d", 2), false, false);
% Initialize obstacles
obstacleLength = 1;