forked from plumewind/ekf_slam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompute_steering.m
45 lines (40 loc) · 1.11 KB
/
compute_steering.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
function [G,iwp]= compute_steering(x, wp, iwp, minD, G, rateG, maxG, dt)
%function [G,iwp]= compute_steering(x, wp, iwp, minD, G, rateG, maxG, dt)
%
% INPUTS:
% x - true position
% wp - waypoints
% iwp - index to current waypoint
% minD - minimum distance to current waypoint before switching to next
% G - current steering angle
% rateG - max steering rate (rad/s)
% maxG - max steering angle (rad)
% dt - timestep
%
% OUTPUTS:
% G - new current steering angle
% iwp - new current waypoint
%
% determine if current waypoint reached
cwp= wp(:,iwp);
d2= (cwp(1)-x(1))^2 + (cwp(2)-x(2))^2;
if d2 < minD^2
iwp= iwp+1; % switch to next
if iwp > size(wp,2) % reached final waypoint, flag and return
iwp=0;
return;
end
cwp= wp(:,iwp); % 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