MATLAB Examples

# Tune the Connection Distance

Use the ConnectionDistance property on the PRM object to tune the algorithm. ConnectionDistance is an upper threshold for points that are connected in the roadmap. Each node is connected to all nodes within this connection distance that do not have obstacles between them. By lowering the connection distance, you can limit the number of connections to reduce the computation time and simplify the map. However, a lowered distance limits the number of available paths from which to find a complete obstacle-free path. When working with simple maps, you can use a higher connection distance with a small number of nodes to increase efficiency. For complex maps with lots of obstacles, a higher number of nodes with a lowered connection distance increases the chance of finding a solution.

Load a map file and create an occupancy grid.

```filePath = fullfile(fileparts(which('PathPlanningExample')),'data','exampleMaps.mat'); load(filePath) map = robotics.OccupancyGrid(simpleMap,2); ```

Create a roadmap with 100 nodes and calculate the path. The default ConnectionDistance is set to inf. Save the random number generation settings using the rng function. The saved settings enable you to reproduce the same points and see the effect of changing ConnectionDistance.

```rngState = rng; prm = robotics.PRM(map,100); startLocation = [2 1]; endLocation = [12 10]; path = findpath(prm,startLocation,endLocation); show(prm) ```

Reload the random number generation settings to have PRM use the same nodes. Lower ConnectionDistance to 2 m. Show the calculated path.

```rng(rngState); prm.ConnectionDistance = 2; path = findpath(prm,startLocation,endLocation); show(prm) ```