-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.m
57 lines (41 loc) · 1.22 KB
/
main.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
clear drones
droneQuantity = 6;
simulationTime = 30; % seconds
centralControl = CentralControl;
waypoints = [50,20,90,100,20,80 ; 20,40,100,10,60,60];
drones = {nan,nan,nan,nan}; % pre-allocate drones' cell array
for index = 1:droneQuantity
drones{index} = Drone;
try
drones{index}.SetWaypoint(waypoints(:,index));
catch
disp("Waypoints array not big enough")
end
end
drones{1}.flightMode = "cruise";
drones{2}.flightMode = "cruise";
drones{5}.SetPosition([80,62]')
drones{6}.SetPosition([20,60]')
dt = PhysicalObject.dt;
for index = 0 : simulationTime / dt % main simulation loop ============
realTimePassed = index*dt;
hold on
grid on
xlim([0,120]);
ylim([0,120]);
% Plot our waypoints
for h = 1:length(waypoints)
scatter(waypoints(1,h),waypoints(2,h));
end
centralControl.DronesAvoidance(drones)
for j = 1:droneQuantity
drones{j}.Update()
end
dronePositions = zeros(2,droneQuantity);
for j = 1:droneQuantity
dronePositions(:,j) = drones{j}.position;
end
scatter(dronePositions(1,:),dronePositions(2,:))
pause(dt);
cla reset;
end