Run actions at waypoints
The navigation service drives the robot between waypoints, but it doesn’t perform actions at each stop. To capture an image, take a sensor reading, or trigger an alert at each waypoint, write code that monitors the robot’s progress and acts when a waypoint is reached.
The pattern
- Add waypoints to the navigation service.
- Set the mode to Waypoint.
- Poll GetWaypoints to detect when a waypoint is visited (it disappears from the list).
- When a waypoint is visited, run your action.
- Repeat until all waypoints are visited.
Example: capture an image at each waypoint
This example navigates to a sequence of GPS coordinates and captures a camera image at each one.
How it works
The navigation service marks waypoints as visited when the robot arrives at each one. GetWaypoints returns only unvisited waypoints. By tracking the count, you detect arrivals.
When a waypoint is visited:
- Switch to Manual mode to pause navigation and hold position.
- Perform your action (capture image, read sensor, send alert).
- Switch back to Waypoint mode to resume navigation to the next waypoint.
Switching to Manual mode stops the current motion plan but preserves the remaining waypoints. Switching back to Waypoint mode resumes navigation from the next unvisited waypoint.
Other actions you can run at waypoints
The pattern works with any Viam API call:
- Sensor readings:
await sensor.get_readings()to log environmental data at each location. - Vision detections:
await vision.get_detections_from_camera("cam")to run object detection at each stop. - Alerts: send a webhook or log entry when the robot reaches a specific location.
- Gripper operations: pick up or place objects at designated waypoints.
What’s next
- Follow a patrol route: run waypoint actions on a repeating patrol.
- Capture and sync data: configure automatic data capture for your camera or sensors.
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!