In this tutorial, you’ll learn how to implement waypoint-based navigation in ROS2 using the Nav2 stack, enhanced with dynamic replanning capabilities. This setup enables your robot to follow a sequence of predefined goals and recalculate the path if unexpected obstacles appear. It’s ideal for autonomous patrol or area coverage in indoor environments.
Create a list of waypoints in a YAML file with the format expected by `FollowWaypoints` behavior. Each waypoint should include a position (x, y) and orientation (quaternion z, w).
Example: waypoints.yaml
– poses:
– position:
x: 2.0
y: 1.0
orientation:
z: 0.0
w: 1.0
– position:
x: 0.5
y: 3.0
orientation:
z: 0.0
w: 1.0
Launch your standard Nav2 bringup with the robot localized on a known map. Then use a script or custom node to load the YAML and publish goals sequentially to `FollowWaypoints` action server.
To ensure the robot adapts to unexpected obstacles, activate recovery and planner plugins. Make sure your `planner_server` has recovery behaviors like `Spin`, `ClearCostmap`, and the controller allows replanning.
In your behavior tree (bt_navigator.xml):
<RecoveryNode name=”NavigateRecovery”>
<ClearEntireCostmap/>
<Spin recovery_spin_1/>
<BackUp recovery_backup/>
</RecoveryNode>
Place a dynamic obstacle (e.g., a box) in the robot’s path during navigation. Nav2 should replan or attempt a recovery behavior and continue toward the next waypoint. Observe transitions in RViz and logs.
– Waypoints not loading:
check YAML structure and action interface.
– Robot doesn’t replan: verify recovery plugins are configured and active.
– Navigation freezes:
look at BT logs and verify conditions for fallback nodes.
– Path too close to obstacle:
adjust inflation and costmap parameters.