-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplotdynamic_tes.m
More file actions
263 lines (222 loc) · 7.57 KB
/
plotdynamic_tes.m
File metadata and controls
263 lines (222 loc) · 7.57 KB
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
function plotdynamic_tes(D,PathStore,Path_num,RobotNum,Start,Goal,~,~)
%AllRobotState = zeros(size(D,1),size(D,2));
MM = size(D,2);
NN = size(D,1);
m=size(D,2);
axis equal;
video = VideoWriter('simulation_fortest','MPEG-4');
video.FrameRate=8;
open(video);
ax = gca();
globaltime = 0;
MAX=0;
temp=0.3;
%%
[PathStore]=biais_goal(PathStore,RobotNum,Start,Goal,m);
[PathStore]=insert_value_dyn(PathStore,RobotNum);
for i = 1:RobotNum
Path_num{i,1}=(PathStore{i,1}(:,2)+(PathStore{i,1}(:,1)-1)*m)';
end
for i = 1:RobotNum
Goal(i)=Path_num{i,1}(length(Path_num{i,1}));
Start(i)=Path_num{i,1}(1);
end
[X_F,Y_F]=spread(Goal,m);
[X,Y]=spread(Start,m);
for i = 1:RobotNum
% [PATH,path_num]=IP_solver(D,Start(i),Goal(i),i);
% PathStore{i} = PATH;
% Path_num{i} = path_num;
MAX=max([size(PathStore{i,1},1),MAX]);
% MAX=MAX+1;
H(i)=size(PathStore{i,1},1);
end
MAX = MAX+1;
for i=1:RobotNum
if size(PathStore{i},1)<MAX
SI=size(PathStore{i});
for j = (SI+1):MAX
PathStore{i}(j,1) = PathStore{i}(H(i),1);
PathStore{i}(j,2) = PathStore{i}(H(i),2);
% Path_num{i}(j)=Path_num{i}(H(i));
end
end
end
m_len=size(PathStore{1},1);
%% 辨别方向
for i = 1:RobotNum
for j =1:MAX-1
x_in=PathStore{i,1}(j+1,1)-PathStore{i,1}(j,1);
y_in=PathStore{i,1}(j+1,2)-PathStore{i,1}(j,2);
if x_in>=0 && y_in==0
Path_dir(i,j)=2;
end
if y_in>=0 && x_in==0
Path_dir(i,j)=1;
end
if y_in==0 && x_in<=0
Path_dir(i,j)=4;
end
if x_in==0 && y_in<=0
Path_dir(i,j)=3;
end
if x_in==0 && y_in==0
if j <=m_len-11
x_in_end=PathStore{i,1}(j+11,1)-PathStore{i,1}(j,1);
y_in_end=PathStore{i,1}(j+11,2)-PathStore{i,1}(j,2);
if x_in_end>0 && y_in_end==0
Path_dir(i,j)=2;
end
if y_in_end>0 && x_in_end==0
Path_dir(i,j)=1;
end
if y_in_end==0 && x_in_end<0
Path_dir(i,j)=4;
end
if x_in_end==0 && y_in_end<0
Path_dir(i,j)=3;
end
end
end
if j == MAX-1
Path_dir(i,j+1)=Path_dir(i,j);
end
end
end
for i=1:RobotNum
test=Path_num{i}-Goal(i);
final=find(test==0);
% final = length(Path_num{i});
finalindice(i) = final(1);
end
indice=max(finalindice);
%disp(indice)
for loop=1:10000
if loop > indice+1
break;
end
% frame = getframe(ax);
pause(0.01);
cla;
axis equal;
xlim([0 MM])
ylim([0 NN])
mapdesigner(fliplr(D),1);
% arrowdesign(dir_way,D)
hold on;
% axis([0 13 0 13]);
for i=1:RobotNum
if ~isempty(PathStore{i,1})
%AllRobotState(PathStore{i,1}(loop,1),PathStore{i,1}(loop,2)) = 1;
if PathStore{i,1}(loop,1)==X_F(i) && PathStore{i,1}(loop,2)==Y_F(i)
axis([0,MM,0,NN])
axis equal
plot(PathStore{i,1}(loop,2)-1/2,PathStore{i,1}(loop,1)-1/2,'o','MarkerEdgeColor','g','MarkerFaceColor','g','MarkerSize',10) %一般情况下机器人不会中途经过终点
text(PathStore{i,1}(loop,2)-1/3,PathStore{i,1}(loop,1)-1/3,cellstr(num2str(i)),'Color',[253/255 120/255 5/255])
xlim([0 MM])
ylim([0 NN])
x=PathStore{i,1}(loop,2)-1/2;
y=PathStore{i,1}(loop,1)-1/2;
switch Path_dir(i,loop)
case 1
xx = x+temp;
yy = y;
case 2
xx = x;
yy = y+temp;
case 3
xx = x-temp;
yy = y;
case 4
xx = x;
yy = y-temp;
end
line([x,xx],[y,yy],'color','k','linestyle','-','lineWidth',5);
elseif PathStore{i,1}(loop,1)==X(i) && PathStore{i,1}(loop,2)==Y(i)
if loop==1
axis([0,MM,0,NN])
axis equal
plot(PathStore{i,1}(loop,2)-1/2,PathStore{i,1}(loop,1)-1/2,'o','MarkerEdgeColor','y','MarkerFaceColor','y','MarkerSize',10)
text(PathStore{i,1}(loop,2)-1/3,PathStore{i,1}(loop,1)-1/3,cellstr(num2str(i)),'Color',[253/255 120/255 5/255])
xlim([0 MM])
ylim([0 NN])
x=PathStore{i,1}(loop,2)-1/2;
y=PathStore{i,1}(loop,1)-1/2;
switch Path_dir(i,loop)
case 1
xx = x+temp;
yy = y;
case 2
xx = x;
yy = y+temp;
case 3
xx = x-temp;
yy = y;
case 4
xx = x;
yy = y-temp;
end
line([x,xx],[y,yy],'color','k','linestyle','-','lineWidth',5);
else
axis([0,MM,0,NN])
axis equal
plot(PathStore{i,1}(loop,2)-1/2,PathStore{i,1}(loop,1)-1/2,'o','MarkerEdgeColor','r','MarkerFaceColor','r','MarkerSize',10) %中途经过起点
text(PathStore{i,1}(loop,2)-1/3,PathStore{i,1}(loop,1)-1/3,cellstr(num2str(i)),'Color',[253/255 120/255 5/255])
xlim([0 MM])
ylim([0 NN])
x=PathStore{i,1}(loop,2)-1/2;
y=PathStore{i,1}(loop,1)-1/2;
switch Path_dir(i,loop)
case 1
xx = x+temp;
yy = y;
case 2
xx = x;
yy = y+temp;
case 3
xx = x-temp;
yy = y;
case 4
xx = x;
yy = y-temp;
end
line([x,xx],[y,yy],'color','k','linestyle','-','lineWidth',5);
end
else
axis([0,MM,0,NN])
axis equal
plot(PathStore{i,1}(loop,2)-1/2,PathStore{i,1}(loop,1)-1/2,'o','MarkerEdgeColor','r','MarkerFaceColor','r','MarkerSize',10)
text(PathStore{i,1}(loop,2)-1/3,PathStore{i,1}(loop,1)-1/3,cellstr(num2str(i)),'Color',[253/255 120/255 5/255])
xlim([0 MM])
ylim([0 NN])
x=PathStore{i,1}(loop,2)-1/2;
y=PathStore{i,1}(loop,1)-1/2;
switch Path_dir(i,loop)
case 1
xx = x+temp;
yy = y;
case 2
xx = x;
yy = y+temp;
case 3
xx = x-temp;
yy = y;
case 4
xx = x;
yy = y-temp;
end
line([x,xx],[y,yy],'color','k','linestyle','-','lineWidth',5);
end
end
end
writeVideo(video,getframe(ax))
globaltime = globaltime + 1;
end
% disp('系统总消耗时刻:')
% disp(globaltime);
%disp(loop);
% close(gca);
close(video);
% for i = 1:RobotNum
% disp(Path_num{i,1}(end)-Goal(i))
% end