-
Notifications
You must be signed in to change notification settings - Fork 0
/
followpath.m
152 lines (149 loc) · 6.48 KB
/
followpath.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
function followpath(f1)
%Function follows the path determined by the a star path planner.
global nf robotid current_pos step_distance distance dir reachedflag fire_assignment stack
%% Getting the X and Y coordinates of Fire and Robot Location
for i=1:nf
robotid=fire_assignment(i);
pos=current_pos(robotid);
if reachedflag(i)
continue
end
if eq(size(stack{robotid},1),1)
c_pos=stack{robotid}(1,:);
disp('Reached Fire Position');
disp(current_pos(robotid));
reachedflag(i)=1;
if f1
orientrobot(i);
disp('Fire Extinguisher On');
end
updaterobotpatch(i,c_pos,dir(robotid));
else
% Moving the Robot closer to the Fire Location
c_pos=stack{robotid}(1,:);
n_pos=stack{robotid}(2,:);
nextpos=n_pos(1)+((n_pos(2)-1)*10);
if any(current_pos==nextpos)
tr=find(current_pos==nextpos);
if reachedflag(fire_assignment==tr)
stack{robotid}=astarpath(i,current_pos(robotid),nextpos);
disp('Changing Path');
else
disp('Skipping Movement');
end
continue;
end
moveflag=0;
stack{robotid}(1,:)=[];
while(not(moveflag))
d=dir(robotid);
switch d
case 0
if eq(n_pos(1),c_pos(1))
if n_pos(2)<c_pos(2)
disp('Turning Left');
dir(robotid)=270;
%Send /L command
elseif n_pos(2)>c_pos(2)
disp('Turning Right');
dir(robotid)=90;
%Send /R command
end
else
if n_pos(1)<c_pos(1)
disp('Moving front');
current_pos(robotid)=pos-1;
moveflag=1;
%Send /F command
elseif n_pos(1)>c_pos(1)
disp('Moving back');
current_pos(robotid)=pos+1;
moveflag=1;
%Send /B command
end
distance(robotid)=distance(robotid)+step_distance;
end
case 90
if eq(n_pos(1),c_pos(1))
if n_pos(2)<c_pos(2)
disp('Moving Back');
current_pos(robotid)=pos-10;
moveflag=1;
%Send /B command
elseif n_pos(2)>c_pos(2)
disp('Moving Front');
current_pos(robotid)=pos+10;
moveflag=1;
%Send /F command
end
else
if n_pos(1)<c_pos(1)
disp('Turning left');
%Send /L command
dir(robotid)=0;
elseif n_pos(1)>c_pos(1)
disp('Turning right');
dir(robotid)=180;
%Send /R command
end
distance(robotid)=distance(robotid)+step_distance;
end
case 180
if eq(n_pos(1),c_pos(1))
if n_pos(2)>c_pos(2)
disp('Turning Left');
dir(robotid)=90;
%Send /L command
elseif n_pos(2)<c_pos(2)
disp('Turning Right');
dir(robotid)=270;
%Send /R command
end
else
if n_pos(1)>c_pos(1)
disp('Moving front');
current_pos(robotid)=pos+1;
moveflag=1;
%Send /F command
elseif n_pos(1)<c_pos(1)
disp('Moving back');
current_pos(robotid)=pos-1;
moveflag=1;
%Send /B command
end
distance(robotid)=distance(robotid)+step_distance;
end
case 270
if eq(n_pos(1),c_pos(1))
if n_pos(2)>c_pos(2)
disp('Moving Back');
current_pos(robotid)=pos+10;
moveflag=1;
%Send /B command
elseif n_pos(2)<c_pos(2)
disp('Moving Front')
current_pos(robotid)=pos-10;
moveflag=1;
%Send /F command
end
else
if n_pos(1)>c_pos(1)
disp('Turning left');
dir(robotid)=180;
%Send /L command
elseif n_pos(1)<c_pos(1)
disp('Turning right');
dir(robotid)=0;
%Send /R command
end
distance(robotid)=distance(robotid)+step_distance;
end
end
if not(moveflag)
pause(1);
end
end
updaterobotpatch(i,c_pos,dir(robotid));
end
end
end