-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathlane_change.m
56 lines (54 loc) · 1.66 KB
/
lane_change.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
function [x, y, t] = lane_change(start, width, slope, pathLength, speed, num, ...
type, varargin)
% Generates the time and coordinates for either a single or double lane change
% manuever at a particular speed.
%
% Parameters
% ----------
% start : float
% The starting point along the x axis in meters.
% width : float
% The width of the lane deviation.
% slope : float
% The slope of the lane change.
% pathLength : float
% The length of path.
% speed : float
% Speed of travel.
% num : integer
% Number of time steps.
% type : string
% Either 'single' or 'double'. A double lane change return to x = 0.
% laneLength : float, optional
% Length of the lane for a double lane change.
%
% Returns
% -------
% x : matrix, (num, 1)
% The longitudinal path.
% y : matrix, (num, 1)
% The lateral path.
% t : matrix, (num, 1)
% Time.
x = 0:pathLength / num:pathLength;
x = x';
t = x / speed;
y = zeros(length(x), 1);
endOfSlope = width / slope + start;
slopeInd = find((x > start) & (x <= endOfSlope));
y(slopeInd) = slope * (x(slopeInd) - start);
if strcmp(type, 'single')
theRest = slopeInd(end) + 1:length(y);
y(theRest) = width * ones(length(theRest), 1);
elseif strcmp(type, 'double');
if length(varargin) < 1
error('Double lane change needs length of lane.')
else
laneLength = varargin{1};
startOfSlope = start + laneLength - width / slope;
lane = find((x > endOfSlope) & (x <= startOfSlope));
y(lane) = width * ones(length(lane), 1);
downSlope = find((x > startOfSlope) & (x <= start + laneLength));
y(downSlope) = slope * (start + laneLength - x(downSlope));
end
end