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.
Detect waypoint arrivals from the client
The navigation service has no arrival callback. To run actions at each
stop, poll GetWaypoints from your client code, watch the list shrink,
and take action each time it does. The loop looks like this:
- 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 each waypoint visited on arrival, and
GetWaypoints returns only the unvisited ones. That is why a shrinking
count means the robot just reached a waypoint.
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 same poll-and-act loop works with any Viam API call. Common substitutions for the camera step:
- Sensor readings with
sensor.get_readings()to log environmental data at each location. - Vision detections with
vision.get_detections_from_camera("cam")to run object detection on arrival. - Alerts through a webhook or logger when the robot reaches a specific location.
- Gripper operations to pick or place 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!