-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuserinterface.m
285 lines (264 loc) · 9.83 KB
/
userinterface.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
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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
function varargout = userinterface(varargin)
% USERINTERFACE MATLAB code for userinterface.fig
% USERINTERFACE, by itself, creates a new USERINTERFACE or raises the existing
% singleton*.
%
% H = USERINTERFACE returns the handle to a new USERINTERFACE or the
% handle to
% the existing singleton*.
%
% USERINTERFACE('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in USERINTERFACE.M with the given input arguments.
%
% USERINTERFACE('Property','Value',...) creates a new USERINTERFACE or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before userinterface_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to userinterface_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help userinterface
% Last Modified by GUIDE v2.5 22-Jun-2023 14:14:03
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @userinterface_OpeningFcn, ...
'gui_OutputFcn', @userinterface_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before userinterface is made visible.
function userinterface_OpeningFcn(hObject, ~, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to userinterface (see VARARGIN)
% Choose default command line output for userinterface
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes userinterface wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = userinterface_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in pushbuttonscenario.
function pushbuttonscenario_Callback(hObject, eventdata, handles)
global x G CriticalRadius ro numofrobots enablelinks
global hRobots hEdges viet_ten thres hTargets Target Robot RP
enablelinks=[];
thres = 0.9;
RP = zeros(numofrobots,numofrobots);
cla(handles.figure);
alpha=[-pi:pi/10:pi];
comrangeobj=findobj('Tag','comrange');
comrangestr=get(comrangeobj,'string');
CriticalRadius=str2num(comrangestr);
ro=0.8*CriticalRadius;
x=createrandomscenario1(); % goi ham createrandomscenario1
% fileID = fopen('scenarioX.txt','r');
% formatSpec = '%f';
% A = fscanf(fileID,formatSpec);
% fclose(fileID);
% fileID = fopen('scenarioY.txt','r');
% formatSpec = '%f';
% B = fscanf(fileID,formatSpec);
% fclose(fileID);
% x = [A,B];
% G=generateGraph(x,CriticalRadius,ro);
numofrobots=size(x,1);
% setup for figure windowwidthstr
fh=handles.figure; % Generating the global graph
hold on;
grid off;
% Robot(1).x = [15, 17];
% Robot(2).x = [17.4642568162135,19.1507837665802];
% Robot(3).x = [20.4638161167498,19.0844000304649];
% Robot(4).x = [22.3056384222507,20.8366994405982];
% Robot(5).x = [24.8375965968732,22.1482174797537];
% Robot(7).x = [21.1332941170788,26.0857240533298];
% Robot(8).x = [22.7885399259971,28.5602161262768];
% Robot(6).x = [22.1267811755082,23.6042020669595];
% Robot(9).x = [17.1799899423913,22.8767018979164];
% Robot(10).x = [18.6288634007536,25.5637069768154];
% Robot(11).x = [17.6084891516628,28.1551209078760];
% Robot(12).x = [15.2698965599490,29.5745082737879];
% Robot(13).x = [19.8346228135871,29.6149185828548];
% Robot(14).x = [21.1878429237510,28.8507725530829];
% Robot(15).x = [24.1795783927349,30.1381347073212];
% x(1,:) = Robot(1).x;
% x(2,:) = Robot(2).x;
% x(3,:) = Robot(3).x;
% x(4,:) = Robot(4).x;
% x(5,:) = Robot(5).x;
% x(6,:) = Robot(6).x;
% x(7,:) = Robot(7).x;
% x(8,:) = Robot(8).x;
% x(9,:) = Robot(9).x;
% x(10,:) = Robot(10).x;
% x(11,:) = Robot(11).x;
% x(12,:) = Robot(12).x;
% x(13,:) = Robot(13).x;
% x(14,:) = Robot(14).x;
% x(15,:) = Robot(15).x;
viet_ten = showid(x,1);
for a=1:size(x,1),
RobotInit(a);
end
for a=1:numofrobots,
targetInit(a);
hRobots(a) = plot(x(a,1), x(a,2), 'ro'); %draw robots
if a <= 15
hTargets(a) = plot(Target(a).x(1), Target(a).x(2), 'r.'); %draw robots
end
end
Init_network();
% insert obstacles with single click, robots with double click
set(fh,'ButtonDownFcn',@clickcallback);
function pushbuttonclear_Callback(hObject, eventdata, handles)
cla(handles.figure);
clear global
clear all;
clc;
% --- Executes on button press in Start.
function Start_Callback(hObject, eventdata, handles)
% hObject handle to Start (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global x numofrobots Robot Target banchor RP RPsp
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
banchor = [];
idx = 1;
stt = "No";
step =1;
while(1)
Robot(idx).target = Target(idx).x;
Robot(idx).status = "move goal";
if norm(Robot(idx).x-Target(idx).x) < 0.1
Robot(idx).status = "lanmark";
Robot(idx).V = [0 0];
idx = idx + 1;
Robot(idx).status = "move goal";
end
N_f =[];
N_a =[];
for temp = 1:numofrobots
find_neighbor(temp);
end
for temp = 1:numofrobots
find_triangle(temp);
if (Robot(temp).status == "free" || Robot(temp).status == "anchor" || Robot(temp).status == "Support")
Robot(temp).status = "free";
if size(Robot(temp).Neighbor,2) ~= 1
for neighbor_idx = Robot(temp).Neighbor
if ~ismember(neighbor_idx, Robot(temp).Neighbor_topo(:,2))
Robot(temp).status = "anchor";
end
end
end
end
Robot(temp).status;
if Robot(temp).status == "free"
N_f = [N_f, temp];
else
N_a = [N_a, temp];
end
end
for id = 1:numofrobots
if id == idx
Robot(id).status = "move goal";
end
if Robot(id).status == "move goal"
find_triangle(id);
dis_min = 999;
id_min = id;
for id_temp = 1:numofrobots
distance = norm(Robot(id_temp).x - Target(id).x);
if dis_min > distance
dis_min = distance;
id_min = id_temp;
end
end
path = [];
path = dijkstra(RP,id,id_min);
path = path(path~=id);
if size(path,2) > 0
Robot(id).target = Robot(path(size(path,2))).x;
else
Robot(id).target = Target(id).x;
distance_sample = norm(Robot(id).x_sample(1)-Robot(id).x_sample(size(Robot(id).x_sample,1)));
if distance_sample < 1
Robot(id).help = "Help";
dis_min = 999;
if size(N_f,2) > 0
sp = N_f(1);
for sp_temp = N_f
distance = norm(Robot(sp_temp).x - Robot(id).x);
if dis_min > distance
dis_min = distance;
sp = sp_temp;
end
end
if sp ~= 0
if Robot(id).support ~= 0
Robot(Robot(id).support).status = "free";
Robot(Robot(id).support).minimize = 0;
end
Robot(id).support = sp;
Robot(Robot(id).support).status = "Support";
Robot(Robot(id).support).minimize = id;
end
end
else
Robot(id).help = "No";
if Robot(id).support ~= 0
Robot(Robot(id).support).status = "free";
Robot(Robot(id).support).minimize = 0;
end
end
end
BC(id);
elseif Robot(id).status == "lanmark"
if Robot(id).support ~= 0
Robot(Robot(id).support).status = "free";
Robot(Robot(id).support).minimize = 0;
end
find_triangle(id);
elseif Robot(id).status == "Support"
% step = step + 1
% id
find_triangle(id);
path = [];
path = dijkstra(RP,id,Robot(id).minimize);
path = path(path~=id);
if size(path,2) > 0
Robot(id).target = Robot(path(size(path,2))).x;
else
Robot(id).target = Robot(Robot(id).minimize).x;
end
BC(id);
else
find_triangle(id);
BC(id);
end
end
pause(0);
end