> For the complete documentation index, see [llms.txt](https://docs.hello-robot.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.hello-robot.com/stretch4_docs/working-with-stretch/nav_u/global-planning.md).

# Global Planning

In this tutorial, we will learn how to configure the global planner in a static environment (i.e. no moving obstacles).

The global planner is the algorithm that takes a start location and goal location and calculates a path between the two locations that does not collide with obstacles.

## Global Planner Demo

To demonstrate how the global planner works, we will be using an offline interactive demonstration that uses neither the real robot or the simulator. All you need is the location of the map you created in the previous tutorial.

```bash
ros2 launch stretch_nav2 global_plan_demo.launch.py map_yaml:=/PATH/TO/MAP.yaml
```

This should launch RViz with only your map initially displayed.

<div align="center"><img src="/files/d7RdVtmmmQRrMMeIYijJ" alt="base" width="400"></div>

At the top of the RViz window, there are two tools:

* **2D Pose Estimate**
* **2D Goal Pose**

These tools are used to specify the start and goal positions.

1. Click **2D Pose Estimate** and select a starting pose on the map.
2. Click **2D Goal Pose** and select a goal pose.
3. Once both poses are specified, a red path should appear connecting them, assuming a valid path exists.

<div align="center"><img src="/files/kcTBlZ9fVtyiVYQ5g6qs" alt="base" width="400"></div>

## Taking Up Space

However, note that the calculated path (at least in this example) travels very close to the walls. The path travels only through unoccupied cells of the map, but it also assumes that the robot takes up no space. There are multiple ways to work around this, but for computational efficiency, we keep the planner the same and change the map that planning is performed on.

To do that, we are going to edit the global costmap configuration. The global costmap is used for the global planner. For purposes of this demo, the file is located at `stretch_nav2/config/planner_demo.yaml`. Once you make changes to this file, you may need to recompile for your changes to take effect.

For now, simply comment out the line that reads `plugins: [static_layer]` and uncomment the line that reads `plugins: [static_layer, inflation_layer]`. When you rerun the demo, you should see something similar to this:

<div align="center"><img src="/files/iKcAYgXWAe90ubqgqMw7" alt="base" width="400"></div>

The global planning algorithm will now stay at least 0.22 meters away from any obstacle. By enabling the inflation layer, we "inflated" each obstacle so that there was impassible space for 0.22 meters around each obstacle.

If we wanted to increase that space so that the robot absolutely could not move any closer to obstacles, we could simply increase the `robot_radius` and `inflation_radius` parameters in the parameter file. Try increasing both values to 0.7 and you get this:

<div align="center"><img src="/files/49pLZ2EeIEvAAWNhYD00" alt="base" width="400"></div>

Note that now there is more blocked space around each obstacle, but that also includes making it so that the doorways cannot be drive through anymore.

To give the planning algorithm a preference for staying away from obstacles, but not blocking that space entirely if needed, we can set the inflation radius to have a larger value than the robot radius, for example, robot\_radius=0.22 and inflation\_radius=0.7.

<div align="center"><img src="/files/H35sCJ7CW5HsmcyVaXJ6" alt="base" width="400"></div>

**Note: setting the inflation radius to be less than the robot radius generally does not make sense, and will have equivalent behavior to setting the robot radius to be equal to the inflation radius.**

We will learn more about configuring the costmaps in a later tutorial.

## Configuring the Planner

The default planner is NavFn, a standard grid-based planner. You can also experiment with different planners by changing the `planner_plugins` parameter in `planner_demo.yaml`. This demo will visualize the planned paths for all of the plugins specified.

<div align="center"><img src="/files/XD5sl6abVKZLeNgAGmJO" alt="base" width="400"></div>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.hello-robot.com/stretch4_docs/working-with-stretch/nav_u/global-planning.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
