Navigate to a waypoint
Once your GPS movement sensor reports accurate position and heading, the navigation service can drive the base to a coordinate you choose. This guide adds the navigation service to an existing base-and-GPS machine and sends the robot to its first waypoint, first from the Control tab and then from code.
Prerequisites
- A configured base that drives your robot.
- A configured movement sensor that provides GPS position and compass heading. Verify it reports accurate data before proceeding.
- Your machine is online in the Viam app.
Add the navigation service
- Click the + button.
- Select Configuration block.
- Search for navigation and select the builtin model.
- Name it (for example,
my-nav) and click Create.
Configure required attributes
Set these attributes in the configuration panel:
- base: the name of your base component (for example,
my-base). - movement_sensor: the name of your GPS movement sensor (for example,
my-gps). - map_type: select GPS.
Leave the other attributes at their defaults for now. See navigation service configuration for all available attributes and what they control.
Click Save.
Send the robot to a waypoint
You can add waypoints through the Viam app’s Control tab or from code.
Using the Control tab
- Go to your machine’s CONTROL tab.
- Find the navigation service card. It shows a map centered on your robot’s GPS position. If the card shows Resource is configuring…, wait for the navigation service’s status badge to read Ready.
- Click on the map to add a waypoint. A marker appears at that location.
- Above the map, find the Mode toggle (options: Manual / Waypoint) and select Waypoint.
- The robot begins navigating to the waypoint. Watch its position update on the map.
When the robot reaches the waypoint, it marks the waypoint as visited. If you’ve added multiple waypoints, it navigates to the next one in order.
Using code
Add a waypoint and set the mode to Waypoint programmatically.
To get the credentials for the code below, go to your machine’s page in the Viam app, click the CONNECT tab, and select API keys. Copy the API key and API key ID. Copy the machine address from the same tab.
What to expect
When navigation starts, the robot turns to face the waypoint, drives toward it, and marks the waypoint visited on arrival. If more waypoints are queued, the service drives to the next one automatically.
Two conditions trigger a replan during this sequence:
- The robot drifts more than
plan_deviation_m(default 2.6 meters) from the planned path. - A configured obstacle detector reports a new obstacle on the path.
Troubleshooting
If the robot does not move, moves erratically, or stops short, see Monitor and troubleshoot navigation. That page covers the common failure modes in one place.
What’s next
- Follow a patrol route: navigate a sequence of waypoints in a loop.
- Avoid obstacles: add vision-based obstacle detection.
- Tune navigation behavior: adjust speed, deviation, and polling for your environment.
Was this page helpful?
Glad to hear it! If you have any other feedback please let us know:
We're sorry about that. To help us improve, please tell us what we can do better:
Thank you!