-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfastslam2.m~
51 lines (45 loc) · 1.2 KB
/
fastslam2.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
function fastslam2( lm, wp )
% Initialisations
particles= initialise_particles(100);
xtrue= zeros(3,1);
index_wp=1; % index to first waypoint
G= 0; % initial steer angle
rateG=0.3491; %
dt=0.025; %
while index_wp<size(wp,2)
% compute true data
% determine if current waypoint reached
cwp= wp(:,index_wp);
d2= (cwp(1)-xtrue(1))^2 + (cwp(2)-xtrue(2))^2;
minD=1;
if d2 < minD^2
index_wp= index_wp+1; % switch to next
if index_wp > size(wp,2) % reached final waypoint, flag and return
break;
end
cwp= wp(:,index_wp); % next waypoint
end
% compute change in G to point towards current waypoint
deltaG= pi_to_pi(atan2(cwp(2)-x(2), cwp(1)-x(1)) - x(3) - G);
% limit rate
maxDelta= rateG*dt;
if abs(deltaG) > maxDelta
deltaG= sign(deltaG)*maxDelta;
end
% limit angle
G= G+deltaG;
if abs(G) > maxG
G= sign(G)*maxG;
end
end
end
function p= initialise_particles(np)
for i=1:np
p(i).w= 1/np; %weight
p(i).xv= [0;0;0]; %sample of pose
p(i).Pv= zeros(3); %covariation of pose prodict
p(i).xf= [];
p(i).Pf= [];
p(i).da= [];
end
end