Skip to content

Commit c035dcb

Browse files
committed
2.0 Changes
- Unreal integration in ModelAndControlAutonomousHaulTruck+Simulink model - MPC variant introduced in path following module - CreatePathFollowingMPCController.mlx writeup added - Visualization helpers added for MATLAB/Simulink - Improved Stateflow/model organization - General cleanup & performance improvements
1 parent cc3d19c commit c035dcb

File tree

461 files changed

+3429
-89
lines changed

Some content is hidden

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

461 files changed

+3429
-89
lines changed

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,11 @@ codegen/
3131

3232
# Cloud based storage dotfile
3333
.MATLABDriveTag
34+
35+
# Bus/ROS-msg folders
36+
**/+bus_conv_fcns/*
37+
**/*_msg/*
38+
**/*_msg_gen/*
39+
**/*.slx.original
40+
**/*.msg
41+
**/*.srv
-49.6 KB
Binary file not shown.
87.9 KB
Binary file not shown.
132 KB
Binary file not shown.
-95.9 KB
Binary file not shown.

Helpers/Graph/exampleHelperConnectRSToPath.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
onrampIdx = nan;
4646
onrampPath = zeros(0,2);
4747
halfCellSize = 1/(2*binMap.Resolution);
48-
states = exampleHelperSmoothPath(path);
48+
states = exampleHelperSmoothReferencePath(path);
4949
for i = 1:numel(iSorted)
5050
idx = iSorted(i);
5151
rsConnection = reedsSheppConnection("MinTurningRadius",minTurnRadius);

Helpers/Graph/exampleHelperSmoothPath.m renamed to Helpers/Graph/exampleHelperSmoothReferencePath.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
function resampledPath = exampleHelperSmoothPath(path,step)
2-
%exampleHelperSmoothPath Attempts to smooth the path by fitting a cubic polynomial
1+
function resampledPath = exampleHelperSmoothReferencePath(path,step)
2+
%exampleHelperSmoothReferencePath Attempts to smooth the path by fitting a cubic polynomial
33
% Fits a cubic polynomial through every third point along a path.
44
% Path is then resampled and with orientation computed via
55
% finite-differencing. This provides the TEB controller with a
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
function [S,R,dTh,c,in] = exampleHelperArcDist(poses)
2+
%exampleHelperArcDist Compute arc parameters between successive poses
3+
%
4+
% Copyright 2024 The MathWorks, Inc.
5+
6+
% Assumes each segment is tangent with origination pose and intersects
7+
% the XY coordinate of the following pose.
8+
9+
% Prepare outputs
10+
nSeg = size(poses,1)-1;
11+
S = zeros(nSeg,1);
12+
R = zeros(nSeg,1);
13+
dTh = zeros(nSeg,1);
14+
c = zeros(nSeg,1);
15+
16+
% Compute arc parameters for each segment. Assume segment is tangent with
17+
% origination pose and intersects the next pose.
18+
for i = 1:nSeg
19+
[R(i),c(i),dTh(i),S(i)] = nav.algs.internal.ControlPolicies.posePointArc(poses(i,:),poses(i+1,1:2));
20+
end
21+
22+
% Handle degenerate line case
23+
in = isnan(S);
24+
in = in | any(abs(mod(dTh,pi)-[0 pi]) < sqrt(eps),2);
25+
idx = find(in);
26+
S(in) = vecnorm(poses(idx+1,1:2)-poses(idx,1:2),2,2);
27+
end
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
function [pArcInterp,kOut,id] = exampleHelperArcInterp(poses,nv)
2+
%exampleHelperArcInterp Fit arcs between SE2 poses and evenly interpolate wrt arclength
3+
%
4+
% Copyright 2024 The MathWorks, Inc.
5+
6+
arguments
7+
poses (:,3)
8+
nv.StepSize (1,1) {mustBePositive, mustBeReal} = 1;
9+
nv.Direction (:,1) {mustBeMember(nv.Direction,[0 1])} = 1;
10+
end
11+
12+
% Assumes each segment is tangent with origination pose and intersects
13+
% the XY coordinate of the following pose.
14+
15+
% Dirs must be scalar or equal number of poses
16+
dirs = repmat(nv.Direction,size(poses,1)/numel(nv.Direction),1);
17+
18+
poses(~dirs,3) = poses(~dirs,3)+pi;
19+
20+
% Compute distances between poses when fitting a tangent arc
21+
[S,R,dTh,~,in] = exampleHelperArcDist(poses);
22+
23+
% Compute segment arclengths
24+
S = cumsum([0;S]);
25+
26+
% Identify segment for interpolated points
27+
s = 0:(nv.StepSize):S(end);
28+
if size(poses,1) > 1
29+
id = reshape(discretize(s,S),[],1);
30+
else
31+
id = ones(numel(s),1);
32+
end
33+
dS = s(:)-S(id);
34+
pArcInterp = zeros(0,3);
35+
kOut = 1./R(id);
36+
37+
% Interpolate each segment
38+
for i = 1:numel(R)
39+
ds = dS(id==i);
40+
if ~isempty(ds)
41+
if in(i)
42+
% Handle degenerate line-segment case
43+
p0 = poses(i,1:2);
44+
v = normalize(poses(i+1,1:2)-p0,'norm');
45+
pts = p0 + v.*ds;
46+
dth = zeros(size(pts,1),1);
47+
else
48+
pts = nav.algs.internal.ControlPolicies.evaluateArc(poses(i,:),R(i),ds')';
49+
dth = dTh(i)*ds(:)/diff(S(i+[0 1]));
50+
end
51+
52+
th = poses(i,3)+dth;
53+
if ~dirs(i)
54+
th = th - pi;
55+
end
56+
57+
pArcInterp = [pArcInterp; [pts th]]; %#ok<AGROW>
58+
end
59+
end
60+
end
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
function cost = exampleHelperBicycleCost_MultiStage(i,x,u,udot,params)
2+
%exampleHelperBicycleCost_MultiStage Compute cost for bicycle kinematic model
3+
%
4+
% i: (current timestep)
5+
% x: [x y theta] (i'th state)
6+
% u: [v steeringAngle] (i'th control)
7+
% dmv: [v steeringAngle] (rate of change of the manipulated variables)
8+
% params: [refState(1:3) predictionHorizon] (the target state and total number of timesteps)
9+
%
10+
% Copyright 2024 The MathWorks, Inc.
11+
12+
%#codegen
13+
14+
arguments
15+
i (1,1) double {mustBePositive}
16+
x (:,1) double {mustBeReal}
17+
u (:,1) double {mustBeReal} %#ok<INUSA>
18+
udot (:,1) double {mustBeReal}
19+
params (:,1) double {mustBeReal}
20+
end
21+
22+
cost = 0;
23+
24+
if i > 1
25+
W = diag([3 3 3].^2); %weight vector squared
26+
err = x-params(1:3);
27+
cost = cost + err'*W*err;
28+
end
29+
30+
if i <= params(4)
31+
Wdmv = diag([0.1 .1].^2); %weight vector squared
32+
% dmv is used to penalize high-frequency control movement
33+
cost = cost + udot'*Wdmv*udot;
34+
end
35+
end

0 commit comments

Comments
 (0)