Create bidirectional RRT planner for geometric planning
Since R2021a
expand all in page
Description
The plannerBiRRT
object is a single-query planner that uses the bidirectional rapidly exploring random tree (RRT) algorithm with an optional connect heuristic for increased speed.
The bidirectional RRT planner creates one tree with a root node at the specified start state and another tree with a root node at the specified goal state. To extend each tree, the planner generates a random state and, if valid, takes a step from the nearest node based on the MaxConnectionDistance property. The start and goal trees alternate this extension process until both trees are connected. If the EnableConnectHeuristic property is enabled, the extension process ignores the MaxConnectionDistance property. Invalid states or connections that collide with the environment are not added to the tree.
Creation
Syntax
planner = plannerBiRRT(stateSpace,stateVal)
planner = plannerBiRRT(___,Name=Value)
Description
creates a bidirectional RRT planner from a state space object, planner
= plannerBiRRT(stateSpace
,stateVal
)stateSpace
, and a state validator object, stateVal
. The state space of stateVal
must be the same as stateSpace
. The stateSpace
and stateVal
arguments also set the StateSpace and StateValidator properties, respectively, of the planner.
example
sets properties using one or more name-value arguments in addition to the input arguments in the previous syntax. You can specify the MaxConnectionDistance, MaxIterations, MaxNumTreeNodes, and EnableConnectHeuristic properties as name-value arguments.planner
= plannerBiRRT(___,Name=Value
)
Properties
expand all
StateSpace
— State space for planner
state space object
State space for the planner, specified as a state space object. You can use state space objects such as stateSpaceSE2, stateSpaceDubins, stateSpaceReedsShepp, and stateSpaceSE3. You can also customize a state space object using the nav.StateSpace class.
StateValidator
— State validator for planner
state validator object
State validator for the planner, specified as a state validator object. You can use state validator objects such as validatorOccupancyMap, validatorVehicleCostmap, and validatorOccupancyMap3D.
StateSampler
— State space sampler for sampling input space
stateSamplerUniform
object (default) | stateSamplerGaussian
object | stateSamplerMPNET
object | nav.StateSampler
object
Since R2023b
State space sampler used for finding state samples in the input space, specified as a stateSamplerUniform object, stateSamplerGaussian object, stateSamplerMPNET object, or nav.StateSampler object. By default, the plannerBiRRT
uses uniform state sampling.
MaxConnectionDistance
— Maximum length between planned configurations
0.1
(default) | positive scalar
Maximum length between planned configurations, specified as a positive scalar.
If the EnableConnectHeuristic property is set to true
, the object ignores this distance when connecting the two trees during the connect stage.
Example: MaxConnectionDistance=0.3
Data Types: single
| double
MaxIterations
— Maximum number of iterations
1e4
(default) | positive integer
Maximum number of iterations, specified as a positive integer.
Example: MaxIterations=2500
Data Types: single
| double
MaxNumTreeNodes
— Maximum number of nodes in search tree
1e4
(default) | positive integer
Maximum number of nodes in the search tree, specified as a positive integer.
Example: MaxNumTreeNodes=2500
Data Types: single
| double
EnableConnectHeuristic
— Directly join trees during connect phase
false
or 0
(default) | true
or 1
Directly join trees during the connect phase of the planner, specified as a logical 0
(false
) or 1
(true
).
Setting this property to true
causes the object to ignore the MaxConnectionDistance property when attempting to connect the two trees together.
Example: EnableConnectHeuristic=true
Data Types: logical
Object Functions
plan | Plan path between two states |
copy | Create deep copy of planner object |
Examples
collapse all
Plan Path Between Two States Using Bidirectional RRT
Open Live Script
Use the plannerBiRRT
object to plan a path between two states in an environment with obstacles. Visualize the planned path with interpolated states.
Create a state space.
ss = stateSpaceSE2;
Create an occupancyMap
-based state validator using the created state space.
sv = validatorOccupancyMap(ss);
Create an occupancy map from an example map and set map resolution as 10 cells per meter.
load exampleMapsmap = occupancyMap(ternaryMap,10);
Assign the occupancy map to the state validator object. Specify the sampling distance interval.
sv.Map = map;sv.ValidationDistance = 0.01;
Update the state space bounds to be the same as the map limits.
ss.StateBounds = [map.XWorldLimits; map.YWorldLimits; [-pi pi]];
Create the path planner and increase the maximum connection distance.
planner = plannerBiRRT(ss,sv);planner.MaxConnectionDistance = 0.3;
Specify the start and goal states.
start = [20 10 0];goal = [40 40 0];
Plan a path. Due to the randomness of the RRT algorithm, set the rng
seed for repeatability.
rng(100,'twister')[pthObj,solnInfo] = plan(planner,start,goal);
Display the number of iterations taken for the tree to converge.
fprintf("Number of iterations: %d\n",solnInfo.NumIterations)
Number of iterations: 346
Visualize the results.
show(map)hold on% Plot start pose and goal poseplot(start(1), start(2),plannerLineSpec.start{:});plot(goal(1), goal(2), plannerLineSpec.goal{:});% Start tree expansionplot(solnInfo.StartTreeData(:,1),solnInfo.StartTreeData(:,2), ... plannerLineSpec.tree{:})% Goal tree expansionplot(solnInfo.GoalTreeData(:,1),solnInfo.GoalTreeData(:,2), ... plannerLineSpec.goalTree{:})% Draw pathplot(pthObj.States(:,1),pthObj.States(:,2),plannerLineSpec.path{:})legendhold off
Replan the path with the EnableConnectHeuristic
property set to true.
planner.EnableConnectHeuristic = true;[pthObj,solnInfo] = plan(planner,start,goal);
Display the number of iterations taken for the tree to converge. Observe that the planner requires significantly fewer iterations compared to when the EnableConnectHeuristic
property is set to false.
fprintf("Number of iterations: %d\n",solnInfo.NumIterations)
Number of iterations: 192
Visualize the results.
figureshow(map)hold on% Start tree expansion% Plot start pose and goal poseplot(start(1), start(2),plannerLineSpec.start{:});plot(goal(1), goal(2), plannerLineSpec.goal{:});plot(solnInfo.StartTreeData(:,1),solnInfo.StartTreeData(:,2), ... plannerLineSpec.tree{:})% Goal tree expansionplot(solnInfo.GoalTreeData(:,1),solnInfo.GoalTreeData(:,2), ... plannerLineSpec.goalTree{:})% Draw pathplot(pthObj.States(:,1),pthObj.States(:,2),plannerLineSpec.path{:})legendhold off
Plan Path Through 3-D Occupancy Map Using Bidirectional RRT Planner
Open Live Script
Load a 3-D occupancy map of a city block into the workspace. Specify the threshold to consider cells as obstacle-free.
mapData = load("dMapCityBlock.mat");omap = mapData.omap;omap.FreeThreshold = 0.5;
Inflate the occupancy map to add a buffer zone for safe operation around the obstacles.
inflate(omap,1)
Create an SE(3) state space object with bounds for state variables.
ss = stateSpaceSE3([0 220;0 220;0 100;inf inf;inf inf;inf inf;inf inf]);
Create a 3-D occupancy map state validator using the created state space. Assign the occupancy map to the state validator object. Specify the sampling distance interval.
sv = validatorOccupancyMap3D(ss, ... Map = omap, ... ValidationDistance = 0.1);
Create a bidirectional RRT path planner with increased maximum connection distance and reduced maximum number of iterations. Set EnableConnectHeuristic
property to true.
planner = plannerBiRRT(ss,sv, ... MaxConnectionDistance = 50, ... MaxIterations = 1000, ... EnableConnectHeuristic = true);
Specify start and goal poses.
start = [40 180 25 0.7 0.2 0 0.1];goal = [150 33 35 0.3 0 0.1 0.6];
Configure the random number generator for repeatable result.
rng(1,"twister");
Plan the path.
[pthObj,solnInfo] = plan(planner,start,goal);
Visualize the planned path.
show(omap)axis equalview([-10 55])hold on% Start statescatter3(start(1,1),start(1,2),start(1,3),"g","filled")% Start tree expansionplot3(solnInfo.StartTreeData(:,1),solnInfo.StartTreeData(:,2), ... solnInfo.StartTreeData(:,3),".-",Color="g")% Goal statescatter3(goal(1,1),goal(1,2),goal(1,3),"y","filled")% Goal tree expansionplot3(solnInfo.GoalTreeData(:,1),solnInfo.GoalTreeData(:,2), ... solnInfo.GoalTreeData(:,3),".-",Color="y")% Pathplot3(pthObj.States(:,1),pthObj.States(:,2),pthObj.States(:,3), ... "m-",LineWidth=2)
References
[1] Kuffner, J. J., and S. M. LaValle. “RRT-Connect: An Efficient Approach to Single-Query Path Planning.” In Proceedings 2000 ICRA. Millennium Conference. IEEE International Conference on Robotics and Automation. Symposia Proceedings (Cat. No.00CH37065), 2:995–1001. San Francisco, CA, USA: IEEE, 2000. https://doi:10.1109/ROBOT.2000.844730.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Version History
Introduced in R2021a
expand all
R2023b: Specify Sampling Approach for Path Planning
You can now specify uniform sampling, Gaussian sampling, MPNet sampling, or a custom sampling approach to generate samples for path planning. Use the name, value argument StateSampler
to specify the sampling approach.
See Also
Objects
- plannerRRT | plannerRRTStar | stateSpaceReedsShepp | stateSpaceDubins | stateSpaceSE2 | stateSpaceSE3 | validatorOccupancyMap | validatorVehicleCostmap | validatorOccupancyMap3D
Functions
- plan | copy
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- Deutsch
- English
- Français
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本 (日本語)
- 한국 (한국어)
Contact your local office