Skip to content

Commit 4af4c4b

Browse files
committed
Initial commit R2024b
0 parents  commit 4af4c4b

File tree

2,100 files changed

+322327
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,100 files changed

+322327
-0
lines changed

.gitattributes

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
* text=auto
2+
3+
*.fig binary
4+
*.mat binary
5+
*.mdl binary diff merge=mlAutoMerge
6+
*.mdlp binary
7+
*.mex* binary
8+
*.mlapp binary
9+
*.mldatx binary
10+
*.mlproj binary
11+
*.mlx binary
12+
*.p binary
13+
*.sfx binary
14+
*.sldd binary
15+
*.slreqx binary merge=mlAutoMerge
16+
*.slmx binary merge=mlAutoMerge
17+
*.sltx binary
18+
*.slxc binary
19+
*.slx binary merge=mlAutoMerge
20+
*.slxp binary
21+
22+
## Other common binary file types
23+
*.docx binary
24+
*.exe binary
25+
*.jpg binary
26+
*.pdf binary
27+
*.png binary
28+
*.xlsx binary

.gitignore

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Autosave files
2+
*.asv
3+
*.m~
4+
*.autosave
5+
*.slx.r*
6+
*.mdl.r*
7+
8+
# Derived content-obscured files
9+
10+
# Compiled MEX files
11+
*.mex*
12+
13+
# Packaged app and toolbox files
14+
*.mlappinstall
15+
*.mltbx
16+
17+
# Deployable archives
18+
*.ctf
19+
20+
# Generated helpsearch folders
21+
helpsearch*/
22+
23+
# Code generation folders
24+
slprj/
25+
sccprj/
26+
codegen/
27+
28+
# Cache files
29+
*.slxc
30+
31+
# Cloud based storage dotfile
32+
.MATLABDriveTag

LICENSE.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Copyright (c) 2021-2022, The MathWorks, Inc.
2+
All rights reserved.
3+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
5+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
6+
3. In all cases, the software is, and all modifications and derivatives of the software shall be, licensed to you solely for use in conjunction with MathWorks products and service offerings.
7+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
8+
9+
10+
11+
126 KB
Binary file not shown.
Binary file not shown.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
function scene_data = sm_car_scenedata_double_lane_change_iso3888
2+
%% Floor and Grid parameters
3+
% Copyright 2018-2024 The MathWorks, Inc.
4+
5+
scene_data.Name = 'Double_Lane_Change_ISO3888';
6+
scene_data.Dashes.pitch = 7.5; % m
7+
scene_data.Dashes.num = 58; % m
8+
scene_data.Dashes.l = 3; % m
9+
scene_data.Dashes.w = 0.15; % m
10+
scene_data.Dashes.h = 0.01; % m
11+
scene_data.Dashes.base_h = 0.025; % m
12+
scene_data.Dashes.clr = [1 1 1]; % [R G B]
13+
scene_data.Dashes.opc = 1; % (0-1)
14+
15+
% Road length matches dash length
16+
scene_data.Road.l = scene_data.Dashes.pitch*scene_data.Dashes.num; % m
17+
scene_data.Road.w = 8; % m
18+
scene_data.Road.h = 0.1; % m
19+
scene_data.Road.clr = [1 1 1]*0.5; % [R G B]
20+
scene_data.Road.opc = 1; % (0-1)
21+
scene_data.Road.x = 218.4; % m
22+
scene_data.Road.y = -1.2; % m
23+
scene_data.Road.z = 0; % m
24+
scene_data.Road.roll = 0*pi/180; % rad
25+
scene_data.Road.pitch = 0*pi/180; % rad
26+
scene_data.Road.yaw = 0*pi/180; % rad
27+
28+
scene_data.Cones.lane_a_offset = 175; % m
29+
scene_data.Cones.lane_width = 3.3; % m
30+
scene_data.Cones.lane_lateral_offset = 3.5;%4.1; % m
31+
scene_data.Cones.lane_a_length = 15; % m
32+
scene_data.Cones.gap_a_to_b = 30; % m
33+
scene_data.Cones.lane_b_length = 25; % m
34+
scene_data.Cones.gap_b_to_c = 25; % m
35+
scene_data.Cones.lane_c_length = 30; % m
36+
scene_data.Cones.height = 0.6; % m
37+
scene_data.Cones.base_thickness = 0.04; % m
38+
scene_data.Cones.base_width = 0.35; % m
39+
scene_data.Cones.bottom_diameter = 0.24; % m
40+
scene_data.Cones.top_diameter = 0.06; % m
41+
scene_data.Cones.strip_height = 0.3; % m
42+
scene_data.Cones.clr = [248 78 25]/255; % [RGB]
43+
scene_data.Cones.strip_clr = [0.75 0.75 0.75]; % [RGB]
44+
45+
46+
47+
48+
49+
50+
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
function sm_car_trajectory_double_lane_change_iso3888
2+
% Function to construct double-lane change maneuver according to ISO-3888
3+
% Copyright 2018-2024 The MathWorks, Inc.
4+
5+
cd(fileparts(which(mfilename)))
6+
% Parameters for trajectory
7+
maneuver_lateral_offset = -3.35; % m
8+
cone_set_lat_separation = 4.1;%3.5; % m
9+
10+
% Longitudinal gate locations (m)
11+
gate0 = 0; % Start
12+
13+
gate1 = 175; % Entry 1st set of cones
14+
gate2 = gate1+15; % Exit 1st set of cones
15+
16+
gate3 = gate2+30; % Entry 2nd set of cones
17+
gate4 = gate3+25; % Exit 2nd set of cones
18+
19+
gate5 = gate4+25; % Entry 3rd set of cones
20+
gate6 = gate5+30; % Exit 3rd set of cones
21+
22+
gate7 = 700; % End
23+
24+
v_lc = 22; % Speed during lane change (m/s)
25+
x_testv = 100; % Distance when target speed is reached (m)
26+
27+
% Assemble waypoints, foundation for interpolation
28+
x_waypoints = [gate0 x_testv gate1:1:gate2 gate3:1:gate4 gate5:1:gate6 ];
29+
y_waypoints = [0 0 zeros(1,gate2-gate1+1) ones(1,gate4-gate3+1) zeros(1,gate6-gate5+1) ]*cone_set_lat_separation+maneuver_lateral_offset;
30+
vx_waypoints = [1 v_lc v_lc*ones(1,gate2-gate1+1) v_lc*ones(1,gate4-gate3+1) v_lc*ones(1,gate6-gate5+1)];
31+
32+
% Construct query points for interpolation
33+
x_new = [...
34+
gate0:(gate1-gate0)/30: (gate1-(gate1-gate0)/30) ...
35+
gate1:(gate2-gate1)/10: (gate2-(gate2-gate1)/10) ...
36+
gate2:(gate3-gate2)/20: (gate3-(gate3-gate2)/20) ...
37+
gate3:(gate4-gate3)/10: (gate4-(gate4-gate3)/10) ...
38+
gate4:(gate5-gate4)/20: (gate5-(gate5-gate4)/20) ...
39+
gate5:(gate6-gate5)/15: (gate6-(gate6-gate5)/15) ...
40+
gate6:(gate7-gate6)/10: (gate7)];
41+
42+
% Interpolate to get lateral distance and speed
43+
y_new = interp1(x_waypoints, y_waypoints, x_new, 'pchip');
44+
vx_new = interp1(x_waypoints, vx_waypoints, x_new, 'pchip');
45+
46+
% Plot waypoints and interpolated trajectory
47+
fig_handle_name = 'h1_sm_car_double_lane_change';
48+
49+
handle_var = evalin('base',['who(''' fig_handle_name ''')']);
50+
if(isempty(handle_var))
51+
evalin('base',[fig_handle_name ' = figure(''Name'', ''' fig_handle_name ''');']);
52+
elseif ~isgraphics(evalin('base',handle_var{:}))
53+
evalin('base',[fig_handle_name ' = figure(''Name'', ''' fig_handle_name ''');']);
54+
end
55+
figure(evalin('base',fig_handle_name))
56+
clf(evalin('base',fig_handle_name))
57+
58+
plot(x_waypoints,y_waypoints,'bo');
59+
hold on
60+
plot(x_new,y_new,'r-x')
61+
hold off
62+
xlabel('Lateral Distance (m)')
63+
ylabel('Longitudinal Distance (m)');
64+
title('Double-Lane Change Trajectory, ISO 3888');
65+
legend({'Waypoints','Interpolated'},'Location','Best');
66+
axis equal
67+
68+
% Calculate distance traveled
69+
xTrajectory_new = [0 cumsum(sqrt((diff(x_new)).^2+diff(y_new).^2))];
70+
71+
fig_handle_name = 'h2_sm_car_double_lane_change';
72+
73+
handle_var = evalin('base',['who(''' fig_handle_name ''')']);
74+
if(isempty(handle_var))
75+
evalin('base',[fig_handle_name ' = figure(''Name'', ''' fig_handle_name ''');']);
76+
elseif ~isgraphics(evalin('base',handle_var{:}))
77+
evalin('base',[fig_handle_name ' = figure(''Name'', ''' fig_handle_name ''');']);
78+
end
79+
figure(evalin('base',fig_handle_name))
80+
clf(evalin('base',fig_handle_name))
81+
subplot(211)
82+
plot(xTrajectory_new,vx_new)
83+
xlabel('Distance Traveled (m)');
84+
ylabel('Target Speed (m/s)');
85+
title('Target Speed Along Trajectory');
86+
87+
% Calculate target yaw angle (rad)
88+
yaw_interval = 10; % 10
89+
aYaw_new = atan2(...
90+
y_new(yaw_interval+1:end)-y_new(1:end-yaw_interval),...
91+
x_new(yaw_interval+1:end)-x_new(1:end-yaw_interval));
92+
93+
%aYaw_new = atan2(...
94+
% y_new(yaw_interval+1:end)-y_new(1:end-yaw_interval),...
95+
% x_new(yaw_interval+1:end)-x_new(1:end-yaw_interval));
96+
97+
98+
aYaw_new = [repmat(aYaw_new(1),1,yaw_interval) aYaw_new];
99+
100+
subplot(212)
101+
plot(xTrajectory_new,aYaw_new,'-o')
102+
xlabel('Distance Traveled (m)');
103+
ylabel('Target Yaw Angle (rad)');
104+
title('Target Yaw Angle Along Trajectory');
105+
106+
% Assign parameters for trajectory definition
107+
x.Value = x_new;
108+
x.Units = 'm';
109+
x.Comments = '';
110+
111+
y.Value = y_new;
112+
y.Units = 'm';
113+
y.Comments = '';
114+
115+
z.Value = zeros(size(x_new));
116+
z.Units = 'm';
117+
z.Comments = '';
118+
119+
xTrajectory.Value = xTrajectory_new;
120+
xTrajectory.Units = 'm';
121+
xTrajectory.Comments = 'Distance traveled';
122+
123+
vx.Value = vx_new;
124+
vx.Units = 'm/s';
125+
vx.Comments = 'Vehicle speed along direction of travel';
126+
127+
aYaw.Value = aYaw_new;
128+
aYaw.Units = 'rad';
129+
aYaw.Comments = 'Yaw Angle, non-wrapping';
130+
131+
save Double_Lane_Change_ISO3888_trajectory_default x y z vx aYaw xTrajectory
132+
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
function sm_car_crg_to_stl(crg_file,stl_file,varargin)
2+
%sm_car_crg_to_stl Create STL file from CRG file
3+
% sm_car_crg_to_stl(crg_file,stl_file)
4+
% Use CRG functions to generate MATLAB surface,
5+
% and convert that surface to an STL.
6+
%
7+
% Copyright 2018-2024 The MathWorks, Inc.
8+
9+
% Defaults
10+
x_extension = 0;
11+
showplot = 'n';
12+
13+
% Check if extension specified
14+
if (nargin >= 2)
15+
x_extension = varargin{1};
16+
end
17+
% Check if plot requested
18+
if (nargin >= 2)
19+
showplot = varargin{2};
20+
end
21+
22+
% Create STL from CRG
23+
% crg_read is a from OpenCRG
24+
crg_data = crg_read(crg_file);
25+
data = crg_data;
26+
[nu, nv] = size(data.z);
27+
28+
iu = [1 nu];
29+
iv = [1 nv];
30+
31+
%% Generate Auxiliary Data
32+
nuiu = iu(2) - iu(1) + 1;
33+
nviv = iv(2) - iv(1) + 1;
34+
35+
u = zeros(1, nuiu);
36+
for i = 1:nuiu
37+
u(i) = data.head.ubeg + (i-1+iu(1)-1)*data.head.uinc;
38+
end
39+
40+
if isfield(data.head, 'vinc')
41+
v = zeros(1, nviv);
42+
for i=1:nviv
43+
v(i) = data.head.vmin + (i-1+iv(1)-1)*data.head.vinc;
44+
end
45+
else
46+
v = double(data.v(iv(1):iv(2)));
47+
end
48+
49+
% Grid Coordinates in Inertial System
50+
x = zeros(nuiu, nviv);
51+
y = zeros(nuiu, nviv);
52+
z = zeros(nuiu, nviv);
53+
puv = zeros(nviv, 2);
54+
for i = 1:nuiu
55+
puv(:, 1) = u(i);
56+
puv(:, 2) = v';
57+
[pxy, data] = crg_eval_uv2xy(data, puv);
58+
x(i, :) = pxy(: , 1);
59+
y(i, :) = pxy(: , 2);
60+
[pz, data] = crg_eval_uv2z(data, puv);
61+
z(i, :) = pz;
62+
end
63+
64+
% Add flat surface at end along +x axis if desired
65+
x1 = [x;x(end,:)+x_extension];
66+
y1 = [y;y(end,:)];
67+
z1 = [z;z(end,:)];
68+
69+
% Write STLs for upper and lower surface temporarily
70+
surf2stl('temp_stl_upper.stl',flipud(x1),flipud(y1),flipud(z1),'ascii')
71+
surf2stl('temp_stl_lower.stl',x1,y1,z1,'ascii')
72+
73+
% Merge upper and lower surfaces into a single STL file.
74+
upr_fid = fopen('temp_stl_upper.stl');
75+
low_fid = fopen('temp_stl_lower.stl');
76+
uprlow_fid = fopen(stl_file,'w');
77+
line_of_text = 'firstline';
78+
79+
while(~contains(line_of_text,'endsolid'))
80+
line_of_text = fgets(upr_fid);
81+
if(~contains(line_of_text,'endsolid'))
82+
fprintf(uprlow_fid,line_of_text);
83+
end
84+
end
85+
86+
skip_line = 1;
87+
while(~feof(low_fid))
88+
line_of_text = fgets(low_fid);
89+
if((skip_line==1) && contains(line_of_text,'facet normal'))
90+
skip_line = 0;
91+
end
92+
if(skip_line==0)
93+
fprintf(uprlow_fid,line_of_text);
94+
end
95+
end
96+
97+
% Close files
98+
fclose(upr_fid);
99+
fclose(low_fid);
100+
fclose(uprlow_fid);
101+
102+
% Delete temporary STL files
103+
delete('temp_stl_lower.stl');
104+
delete('temp_stl_upper.stl');
105+
106+
% Plot surface if desired
107+
if (strcmpi(showplot,'plot'))
108+
109+
% Figure name
110+
figString = ['h1_' mfilename];
111+
% Only create a figure if no figure exists
112+
figExist = 0;
113+
fig_hExist = evalin('base',['exist(''' figString ''')']);
114+
if (fig_hExist)
115+
figExist = evalin('base',['ishandle(' figString ') && strcmp(get(' figString ', ''type''), ''figure'')']);
116+
end
117+
if ~figExist
118+
fig_h = figure('Name',figString);
119+
assignin('base',figString,fig_h);
120+
else
121+
fig_h = evalin('base',figString);
122+
end
123+
figure(fig_h)
124+
clf(fig_h)
125+
126+
% Plot surface
127+
surf(x1',y1',z1','LineStyle','none')
128+
title(strrep(stl_file,'_','\_'));
129+
axis equal
130+
box on
131+
end
132+
133+

0 commit comments

Comments
 (0)