-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathss_animation.m
150 lines (135 loc) · 4.31 KB
/
ss_animation.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
clc;
clear;
close all;
model = CreateModel2();
file = load('drone.mat');
uavs = file.uavs;
figure();
set(gcf, 'Position', get(0, 'Screensize'));
iter = 0;
% Plot model
mesh(model.X,model.Y,model.H); % Plot the data
colormap pink; % Default color map.
set(gca, 'Position', [0 0 1 1]); % Fill the figure window.
axis equal vis3d on; % Set aspect ratio and turn off axis.
shading interp; % Interpolate color across faces.
material dull; % Mountains aren't shiny.
camlight left; % Add a light over to the left somewhere.
lighting gouraud; % Use decent lighting.
xlabel('x [m]');
ylabel('y [m]');
zlabel('z [m]');
hold on
% Plot threats
threats = model.threats;
threat_num = size(threats,1);
h=250; % Height
for i = 1:threat_num
threat = threats(i,:);
threat_x = threat(1);
threat_y = threat(2);
threat_z = threat(3);
threat_radius = threat(4);
[xc,yc,zc]=cylinder(threat_radius); % create a unit cylinder
% set the center and height
xc=xc+threat_x;
yc=yc+threat_y;
zc=zc*h+threat_z;
c = mesh(xc,yc,zc); % plot the cylinder
set(c,'Edgecolor','none','Facecolor','black','FaceAlpha',.5); % set color and transparency
end
% Start location
xs=model.start(1);
ys=model.start(2);
zs=model.start(3);
plot3(xs,ys,zs,'bs','MarkerSize',10,'MarkerFaceColor','b');
% End location
xf=model.goal(1);
yf=model.goal(2);
zf=model.goal(3);
plot3(xf,yf,zf,'rp','MarkerSize',10,'MarkerFaceColor','r');
step = 4;
% Plot UAVS path
for it = 1:size(uavs)
k = 0;
for j = 1:step:size(uavs(it).path,1)
iter = iter + 1;
% hold on
%% Plot previous UAVS
for i = 1:it-1
% % Path
% plot3(uavs(i).path(:,1), uavs(i).path(:,2), uavs(i).path(:,3),...
% '-', 'LineWidth', 3);
%
% % Target
% scatter3(uavs(i).target(1:end-1,1),...
% uavs(i).target(1:end-1,2),...
% uavs(i).target(1:end-1,3),...
% 70,'k','fill', 'Marker', 'h');
scatter3(uavs(i).target(end,1),...
uavs(i).target(end,2),...
uavs(i).target(end,3),...
70,'b','fill', 'Marker', 'o');
end
%% Curent UAV
% Path
plot3(uavs(it).path(1:j,1), uavs(it).path(1:j,2), uavs(it).path(1:j,3),...
'-', 'LineWidth', 3);
% Target
if it == 1
if norm(uavs(it).path(j,:) - uavs(it).path(1,:)) < 2.0
k = 1;
end
else
if norm(uavs(it).path(j,:) - uavs(it-1).path(end,:)) < 15.0
k = 1;
end
end
if k > 0
if norm(uavs(it).path(j,:) - uavs(it).target(k,:)) < 6.0
if k < size(uavs(it).target,1)
k = k+1;
end
end
scatter3(uavs(it).target(k,1),...
uavs(it).target(k,2),...
uavs(it).target(k,3),...
70,'k','fill', 'Marker', 'h');
end
pltx = scatter3(uavs(it).path(j,1),...
uavs(it).path(j,2),...
uavs(it).path(j,3),...
70,'r','fill', 'Marker', 'o');
% hold off;
view([5 70]);
drawnow
F(iter) = getframe(gcf);
delete(pltx);
end
end
%% End frame
iter = iter + 1;
% Plot previous UAVS
for i = 1:size(uavs)
% % Path
% plot3(uavs(i).path(:,1), uavs(i).path(:,2), uavs(i).path(:,3),...
% '-', 'LineWidth', 3);
%
% % Target
% scatter3(uavs(i).target(1:end-1,1),...
% uavs(i).target(1:end-1,2),...
% uavs(i).target(1:end-1,3),...
% 70,'k','fill', 'Marker', 'h');
scatter3(uavs(i).target(end,1),...
uavs(i).target(end,2),...
uavs(i).target(end,3),...
70,'b','fill', 'Marker', 'o');
end
view([5 70]);
drawnow
F(iter) = getframe(gcf);
video = VideoWriter('result.avi','Motion JPEG AVI');
video.FrameRate = 20; % (frames per second) this number depends on the sampling time and the number of frames you have
open(video);
writeVideo(video,F);
close(video);