forked from IITISoC-IVR/PathPlanning-IVR5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTrackData.m
112 lines (82 loc) · 2.43 KB
/
TrackData.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
%% Tracks - Austin and Silverstone
%% Austin- Min Curv
if NTrack == 1
X = AustinMinCurvature{:,1};
Y = AustinMinCurvature{:,2};
x = AustinBoundary{:,1};
y = AustinBoundary{:,2};
twr = Austin{:,3};
twl = Austin{:,4};
plot(X, Y, 'k');
end
%% Austin- Shortest Path
if NTrack == 2
X = AustinShortest{:,1};
Y = AustinShortest{:,2};
x = AustinBoundary{:,1};
y = AustinBoundary{:,2};
twr = Austin{:,3};
twl = Austin{:,4};
plot(X, Y, 'k');
end
%% Silverstone- Min Curv
if NTrack == 3
X = SilverstoneMinCurvature{:,1};
Y = SilverstoneMinCurvature{:,2};
x = SilverstoneBoundary{:,1};
y = SilverstoneBoundary{:,2};
twr = Silverstone{:,3};
twl = Silverstone{:,4};
plot(X, Y, 'k');
end
%% Silverstone- Shortest Path
if NTrack == 4
X = SilverstoneShortestPath{:,1};
Y = SilverstoneShortestPath{:,2};
x = SilverstoneBoundary{:,1};
y = SilverstoneBoundary{:,2};
twr = Silverstone{:,3};
twl = Silverstone{:,4};
plot(X, Y, 'k');
end
%% Track Sides
lHalfTrackWidth = 2.5;
% interpolate data to get finer curve with equal distances between each segment
% higher no. of segments causes trajectory to follow the reference line
nseg = 1500;
pathXY = [x y];
stepLengths = sqrt(sum(diff(pathXY,[],1).^2,2));
stepLengths = [0; stepLengths]; % add the starting point
cumulativeLen = cumsum(stepLengths);
finalStepLocs = linspace(0,cumulativeLen(end), nseg);
finalPathXY = interp1(cumulativeLen, pathXY, finalStepLocs);
xt = finalPathXY(:,1);
yt = finalPathXY(:,2);
twrt = interp1(cumulativeLen, twr, finalStepLocs,'spline')';
twlt = interp1(cumulativeLen, twl, finalStepLocs,'spline')';
% normal direction for each vertex
dx = gradient(xt);
dy = gradient(yt);
dL = hypot(dx,dy);
% offset curve - anonymous function
xoff = @(a) -a*dy./dL + xt;
yoff = @(a) a*dx./dL + yt;
% plot reference line
plot(xt,yt,'g')
hold on
% offset data
offset = [-twrt twlt];
for i = 1:numel(xt)
xin = xoff(offset(i,1)); % get inner offset curve
yin = yoff(offset(i,1));
xout = xoff(offset(i,2)); % get outer offset curve
yout = yoff(offset(i,2));
end
%% End
xStartLine=[X(1),X(1)];
yStartLine=Y(1)+1.5*[-lHalfTrackWidth,lHalfTrackWidth];
lTrack=0;
for i=2:length(X)
lTrack=lTrack+sqrt((X(i)-X(i-1))^2+(Y(i)-Y(i-1))^2);
end
clear X Y