Skip to content

Commit

Permalink
Add skeletal logic for multi-UAV simulation
Browse files Browse the repository at this point in the history
  • Loading branch information
SLTozer committed Dec 20, 2015
1 parent 885f612 commit a4f002c
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 66 deletions.
48 changes: 1 addition & 47 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,47 +1 @@
# Windows image file caches
Thumbs.db
ehthumbs.db

# Folder config file
Desktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msm
*.msp

# Windows shortcuts
*.lnk

# =========================
# Operating System Files
# =========================

# OSX
# =========================

.DS_Store
.AppleDouble
.LSOverride

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
*.asv
4 changes: 4 additions & 0 deletions UavBody.m
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ function setTurnRate(uavBody, newTurnRate)
function conc = sensorReading(uavBody, cloud, t)
conc = cloudsamp(cloud, uavBody.pos(1), uavBody.pos(2), t);
end

function plot(uavBody)
plot(uavBody.pos(1),uavBody.pos(2),'o');
end
end

end
Expand Down
10 changes: 9 additions & 1 deletion UavBrain.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
uavBrain.conc = 0;
end

function decisionStep(uavBrain, cloud, t, dt)
function decisionStep(uavBrain, cloud, t, dt, messages)
switch uavBrain.currentState
case UavState.CalibrationState
nextState = calibration(uavBrain, cloud, t, dt);
Expand All @@ -43,6 +43,14 @@ function decisionStep(uavBrain, cloud, t, dt)
(uavBrain.nextTurnRate * uavBrain.nextVelocity * dt));
end

function message = getMessage(uavBrain)
message = zeros(1,4);
message(1) = uavBrain.posEstimate(1);
message(2) = uavBrain.posEstimate(2);
message(3) = uavBrain.bearingEstimate;
message(4) = uavBrain.conc;
end

function nextState = calibration(uavBrain, cloud, t, dt)
% Update bearing estimate
newPosEstimate = uavBrain.uavBody.getGpsPos();
Expand Down
49 changes: 31 additions & 18 deletions sim_start.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,44 +14,57 @@
t = 0;
dt = 1.0;

uavBody = UavBody;
uavBrain = UavBrain(uavBody);
% number of UAVs
num = 1;

uavBodies(num,1) = UavBody();
uavBrains = UavBrain.empty(num,0);
for i = 1:num
uavBrains(i) = UavBrain(uavBodies(i));
end

% i-th message is sent from the i-th uav, and is formatted as:
% [x y bearing concentration]
if dt ~= 1.0
error(['Message logic has not been set to deal with timesteps '...
'other than 1.0']);
end
uavMessages = zeros(num,4);

% open new figure window
figure
hold on % so each plot doesn't wipte the predecessor

% main simulation loop
for kk=1:1000,

%% Decision step
% Make decisions from time [t -> t + dt]
uavBrain.decisionStep(cloud, t, dt);
for i = 1:num
uavBrains(i).decisionStep(cloud, t, dt, uavMessages);
end

%% Physical timestep
% Timestep [t -> t + dt]
t = t + dt;
uavBody.move(dt);
for i = 1:num
uavBodies(i).move(dt);
uavMessages(i,:) = uavBrains(i).getMessage();
end


% Get measurements for display
p = uavBody.sensorReading(cloud, t);
x = uavBody.pos;
y = uavBrain.targetPos;
b = uavBrain.bearingEstimate;
%% Display

% clear the axes for fresh plotting
cla

% put information in the title
title(sprintf('t=%.1f secs pos=(%.1f, %.1f) Concentration=%.2f estHead=%.2f',t, x(1),x(2),p,b))

title(sprintf('t=%.1f secs',t))
% plot robot location
plot(x(1),x(2),'o')
plot(y(1),y(2),'x')

for i = 1:num
uavBodies(i).plot();
end
% plot the cloud contours
cloudplot(cloud,t)

% pause ensures that the plots update
pause(0.1)

end
end

0 comments on commit a4f002c

Please sign in to comment.