> ## Documentation Index
> Fetch the complete documentation index at: https://docs.generalrobotics.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Navigation

## Path Planning

Most AirGen maps come with precomputed occupany maps that allow for collision-avoidant path planning. AirGen offers API for computing paths between start and goal points, and the ability to navigate smoothly through a computed safe path. Depending on whether the main robot is aerial or wheeled, AirGen switches between a 3D octree-based occupancy grid, or a 2D navmesh for path planning. Hence, for drones, AirGen computes a 3D path, and for wheeled robots, a path on the ground, such that the path avoids obstacles.

* **Path Planning between two points:** The *simPlanPath* function computes a collision-free path between two points.

```python theme={null}
client = airgen.MultirotorClient()
start = airgen.Vector3r(0, 0, 5)
goal = airgen.Vector3r(10, 10, 5)
path = simPlanPath(start, goal, smooth_path=True, draw_path=True)
```

Setting *smooth\_path* to True yields a smooth spline trajectory instead of a coarse A\*-like path, and draw\_path can be used to visualize the trajectory.

If either the start or the goal point lies within an obstacle/occupied area, *simPlanPath* will fail, returning just the start/goal points back.

* **Path Planning to a Random Free Point:** Another functionality offered by AirGen allows for randomly sampling a free/unoccupied point and planning a path to it, which results in behaviors such as random safe exploration. This can be achieved through the `simPlanPathToRandomFreePoint()` function, which takes in a search radius as the main argument.

```python theme={null}
client = airgen.MultirotorClient()
search_radius = 50 # in meters
path = simPlanPathToRandomFreePoint(search_radius, smooth_path=True, draw_path=True)
```

<Warning>
  When visualizing a path through *draw\_path=True*, the drawing of the path also makes it appear in the FPV camera images of the robot. If you're capturing onboard camera images from the robot, you might want to set *draw\_path=False*.

  After a path is computed, the drone can be asked to fly through it using the `moveOnPathAsync()` function, such as below.

  ```python theme={null}
  start = airgen.Vector3r(0, 0, 5)
  goal = airgen.Vector3r(10, 10, 5)
  path = simPlanPath(start, goal, smooth_path=True, draw_path=True)
  points = []
  for waypoint in trajectory:
      points.append(
          airgen.Vector3r(waypoint["x_val"], waypoint["y_val"], waypoint["z_val"])
      )

  # Move the drone along the planned path at a velocity of 5 m/s
  velocity = 5.0
  self.drone_client.moveOnPathAsync(points, velocity, 120, airgen.DrivetrainType.ForwardOnly, airgen.YawMode(False, 0), -1, 0).join()
  ```
</Warning>

<Warning>
  The path tracking/control functionality currently is only available for drones, and is in the works for the wheeled vehicles.
</Warning>

* **Navigation Extents:** AirGen uses a "navigation mesh" to inform which areas of the map are navigable. It is possible to access the extents of this navigation mesh to sample points from, or to understand which parts of the map are accessible through the planning API.

```python theme={null}
nav_mesh_info = client.getNavMeshInfo()
print("Navmesh extents: {}".format(nav_mesh_info))
```

## Tips

<Tip> Consider visualizing paths before executing. </Tip>
<Tip> Remember, smooth paths might deviate slightly compared to direct paths. </Tip>
