Skip to content

Commit 20b826b

Browse files
committed
Initial commit
0 parents  commit 20b826b

File tree

290 files changed

+3001
-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.

290 files changed

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

AutonomousHaulTruck.prj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<MATLABProject xmlns="http://www.mathworks.com/MATLABProjectFile" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0"/>

CONTRIBUTING.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Contributing
2+
3+
>_If you believe you have discovered a security vulnerability, please **do not** open an issue or make a pull request. Follow the instructions in the [SECURITY.MD](SECURITY.MD) file in this repository._
4+
5+
Thank you for your interest in contributing to a MathWorks repository! We encourage contributions large and small to this repository.
6+
7+
**Contributions do not have to be code!** If you see a way to explain things more clearly or a great example of how to use something, please contribute it (or a link to your content). We welcome issues even if you don't code the solution. We also welcome pull requests to resolve issues that we haven't gotten to yet!
8+
9+
## How to contribute
10+
11+
* **Open an issue:** Start by [creating an issue](https://docs.github.com/en/issues/tracking-your-work-with-issues/creating-an-issue) in the repository that you're interested in. That will start a conversation with the maintainer. When you are creating a bug report, please include as many details as possible. Please remember that other people do not have your background or understanding of the issue; make sure you are clear and complete in your description.
12+
* **Work in your own public fork:** If you choose to make a contribution, you should [fork the repository](https://docs.github.com/en/get-started/quickstart/fork-a-repo). This creates an editable copy on GitHub where you can write, test, and refine your changes. We suggest that you keep your changes small and focused on the issue you submitted.
13+
* **Sign a Contributor License Agreement (CLA):** We require that all outside contributors sign a [CLA](https://en.wikipedia.org/wiki/Contributor_License_Agreement) before we can accept your contribution. When you create a pull request (see below), we'll reach out to you if you do not already have one on file. Essentially, the CLA gives us permission to publish your contribution as part of the repository.
14+
* **Make a pull request:** "[Pull Request](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-pull-requests)" is a confusing term, but it means exactly what it says: You're requesting that the maintainers of the repository pull your changes in. If you don't have a CLA on file, we'll reach out to you. Your contribution will be reviewed, and we may ask you to revise your pull request based on our feedback. Once everyone is satisfied, we'll merge your pull request into the repository.
15+
16+
## Guidelines
17+
18+
We don't have best practices for writing MATLAB&reg; code, but we do have some recommendations:
19+
20+
* You should not have any warnings or errors in the [code analyzer report](http://www.mathworks.com/help/matlab/matlab_prog/matlab-code-analyzer-report.html)
21+
* [Loren Shure's blog](https://blogs.mathworks.com/loren) has [great advice on improving your MATLAB code](https://blogs.mathworks.com/loren/category/best-practice/)
22+
* Examples should be written as [live scripts](https://www.mathworks.com/help/matlab/matlab_prog/what-is-a-live-script-or-function.html) and then [exported as HTML](https://www.mathworks.com/help/matlab/matlab_prog/share-live-scripts.html).
23+
* We adhere to the [CommonMark](https://commonmark.org/) specification where it does not conflict with GitHub rendering. If you edit your Markdown in Visual Studio Code or a similar editor, it uses [markdownlint](https://github.com/DavidAnson/markdownlint) to highlight issues in your Markdown.
24+
25+
**Again, thanks for contributing, and we look forward to your issues and pull requests!**
452 KB
Binary file not shown.
2.46 MB
Binary file not shown.
214 KB
Binary file not shown.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
function se2Path = TerrainAwarePlannerFcn(start,goal,dem,gridLoc,tuneableParams,fixedParams)
2+
%TerrainAwarePlannerFcn Wrapper of terrain informed plannerHybridAStar
3+
%
4+
% Copyright 2023 The MathWorks, Inc.
5+
6+
arguments
7+
start (:,3) double
8+
goal (:,3) double
9+
dem (:,:) single
10+
gridLoc (1,2) double
11+
tuneableParams
12+
fixedParams
13+
end
14+
persistent costMap prevDEM prevGridLoc prevMaxAngle
15+
16+
if isempty(costMap)
17+
% Create costMaps from dem
18+
costMap = exampleHelperDem2mapLayers(dem,tuneableParams.MaxAngle,fixedParams.Resolution);
19+
20+
% Store previous inputs
21+
prevDEM = dem;
22+
prevMaxAngle = tuneableParams.MaxAngle;
23+
prevGridLoc = gridLoc;
24+
else
25+
updateMaps = ~isequal(prevDEM,dem) || ~isequal(prevGridLoc,gridLoc) || ~isequal(prevMaxAngle,tuneableParams.MaxAngle);
26+
27+
% Store previous inputs
28+
prevDEM = dem;
29+
prevMaxAngle = tuneableParams.MaxAngle;
30+
prevGridLoc = gridLoc;
31+
32+
% Check whether costmap must be updated
33+
if updateMaps
34+
updatePlannerMaps(costMap,dem,prevMaxAngle,fixedParams.Resolution);
35+
end
36+
end
37+
38+
% Initialize planner
39+
planner = exampleHelperCreateTerrainPlanner(costMap,tuneableParams,fixedParams);
40+
41+
% Update tuneable properties
42+
names = fieldnames(tuneableParams);
43+
for i = 1:numel(names)
44+
name = names{i};
45+
if isprop(planner,name)
46+
planner.(name) = tuneableParams.(name);
47+
end
48+
end
49+
50+
% Plan a path
51+
pathObj = planner.plan(start,goal);
52+
pathObj.interpolate(max(1000,pathObj.NumStates));
53+
se2Path = pathObj.States;
54+
end
55+
56+
function updatePlannerMaps(origCostMap,dem,maxAngle,res)
57+
% Create new costMap and validator map
58+
tmpCostMap = exampleHelperDem2mapLayers(dem,maxAngle,res);
59+
60+
% Update planner's cost function
61+
origCostMap.syncWith(tmpCostMap);
62+
end
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
function planner = exampleHelperCreateTerrainPlanner(costMap,tuneableParams,fixedParams,transitionFcn)
2+
%exampleHelperCreateTerrainPlanner Creates plannerHybridAStar from incoming parameters and cost function
3+
%
4+
% Copyright 2023 The MathWorks, Inc.
5+
6+
if nargin == 3
7+
% Create plannerHybridAStar with terrain-aware cost function
8+
gWeight = 1; % Weight
9+
transitionFcn = @(motionSegment)exampleHelperZHeuristic(motionSegment, costMap, gWeight);
10+
end
11+
% Create a stateValidator object and update the statebounds
12+
map = getLayer(costMap,"terrainObstacles");
13+
ss = stateSpaceSE2([map.XLocalLimits; map.YWorldLimits; [-pi pi]]);
14+
vehDims = exampleHelperVehicleGeometry(coder.const(fixedParams.Length),coder.const(fixedParams.Width),"collisionChecker");
15+
collisionChecker = inflationCollisionChecker(vehDims,fixedParams.NumCircles);
16+
vehMap = vehicleCostmap(single(map.getOccupancy),'CollisionChecker',collisionChecker,'MapLocation',map.GridLocationInWorld);
17+
validator = validatorVehicleCostmap(ss,Map=vehMap,ThetaIndex=3);
18+
19+
% Initialize planner
20+
planner = plannerHybridAStar(validator, TransitionCostFcn=transitionFcn);
21+
22+
% Update fixed properties
23+
names = fieldnames(fixedParams);
24+
for i = 1:numel(names)
25+
name = names{i};
26+
if isprop(planner,name)
27+
planner.(name) = fixedParams.(name);
28+
end
29+
end
30+
31+
% Update tuneable properties
32+
names = fieldnames(tuneableParams);
33+
for i = 1:numel(names)
34+
name = names{i};
35+
if isprop(planner,name)
36+
planner.(name) = tuneableParams.(name);
37+
end
38+
end
39+
end
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
function [costMap,maxSlope] = exampleHelperDem2mapLayers(dem,maxInclineAngle,res)
2+
%exampleHelperDem2mapLayers Converts DEM data to a multiLayerMap storing cost,
3+
%gradients, and obstacles based on the slope limit
4+
%
5+
% Copyright 2023 The MathWorks, Inc.
6+
7+
arguments
8+
dem (:,:) double {mustBeNumeric}
9+
maxInclineAngle (1,1) double {mustBeFinite, mustBeReal} = 15;
10+
res (1,1) double {mustBePositive} = 1;
11+
end
12+
% Discretize and Store Environment Information in Map Layers
13+
14+
% Query and store the Z-height
15+
zLayer = mapLayer(dem,LayerName="Z",Resolution=res);
16+
[gx,gy] = gradient(dem);
17+
18+
dzdxLayer = mapLayer(gx*res,LayerName="dzdx",Resolution=res);
19+
dzdyLayer = mapLayer(gy*res,LayerName="dzdy",Resolution=res);
20+
maxSlope = tand(maxInclineAngle); % Max preferred slope for vehicle
21+
22+
slope2cost = @(x)exampleHelperGradient2Cost(maxSlope,x);
23+
GX = dzdxLayer.getMapData();
24+
GY = dzdyLayer.getMapData();
25+
xCost = mapLayer(slope2cost(GX),LayerName="xCost",Resolution=res);
26+
yCost = mapLayer(slope2cost(GY),LayerName="yCost",Resolution=res);
27+
diagCost = mapLayer(slope2cost(sqrt(GX.^2+GY.^2)),LayerName="diagCost",Resolution=res);
28+
29+
% Terrain Obstacles
30+
mInvalidSlope = getMapData(xCost) > 1 | getMapData(yCost) > 1 | getMapData(diagCost) > 1;
31+
terrainObstacles = binaryOccupancyMap(mInvalidSlope,LayerName="terrainObstacles",Resolution=res);
32+
33+
% Combine Individual Map Layers
34+
costMap = multiLayerMap({zLayer xCost yCost dzdxLayer dzdyLayer diagCost terrainObstacles});
35+
end

0 commit comments

Comments
 (0)