MATLAB Examples

# Tune the Number of Nodes

Use the NumNodes property on the PRM object to tune the algorithm. NumNodes specifies the number of points, or nodes, placed on the map, which the algorithm uses to generate a roadmap. Using the ConnectionDistance property as a threshold for distance, the algorithm connects all points that do not have obstacles blocking the direct path between them.

Increasing the number of nodes can increase the efficiency of the path by giving more feasible paths. However, the increased complexity increases computation time. To get good coverage of the map, you might need a large number of nodes. Due to the random placement of nodes, some areas of the map may not have enough nodes to connect to the rest of the map. In this example, you create a large and small number of nodes in a roadmap.

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 simple roadmap with 50 nodes.

```prmSimple = robotics.PRM(map,50); show(prmSimple) ```

Create a dense roadmap with 250 nodes.

```prmComplex = robotics.PRM(map,250); show(prmComplex) ```

The additional nodes increase the complexity but yield more options to improve the path. Given these two maps, you can calculate a path using the PRM algorithm and see the effects.

Calculate a simple path.

```startLocation = [2 1]; endLocation = [12 10]; path = findpath(prmSimple,startLocation,endLocation); show(prmSimple) ```

Calculate a complex path.

```path = findpath(prmComplex, startLocation, endLocation); show(prmComplex) ```

Increasing the nodes allows for a more direct path, but adds more computation time to finding a feasible path. Because of the random placement of points, the path is not always more direct or efficient. Using a small number of nodes can make paths worse than depicted and even restrict the ability to find a complete path.