Drive a base directly from code
A wheeled base does not always need navigation. A demo that drives in a
square, an operator joystick that sets velocity in real time, or a
sensor-driven control loop that adjusts power on the fly all call for
commanding the base directly rather than planning a route to it. The base
component API gives you four methods for these cases: MoveStraight and
Spin for known-distance moves, SetPower and SetVelocity for continuous
control.
For autonomous waypoint following or SLAM-based navigation, use the navigation
service instead. See
Navigate to a waypoint and
MoveOnMap.
Before you start
- A configured base component. See the base component documentation for hardware setup.
- The base’s motors run through the TEST section on each motor’s configure card (press and hold forward or backward under Quick move). If a motor’s Test section shows Resource is configuring…, wait for the motor’s status badge to read Ready before attempting Quick move.
- An SDK client connected to your machine. See Create a web app or the language-specific quickstart.
Direct motion commands
The base component API provides four motion methods:
| Method | What it does |
|---|---|
MoveStraight | Drive forward or backward a given distance at a given speed. Blocks until done. |
Spin | Rotate in place by a given angle at a given angular speed. Blocks until done. |
SetPower | Set linear and angular power as normalized values (-1.0 to 1.0). Non-blocking. |
SetVelocity | Set linear and angular velocity directly (mm/s and deg/s). Non-blocking. |
Use MoveStraight and Spin when you know the distance or angle you want.
Use SetPower or SetVelocity for continuous control (for example, an
operator stick, or a sensor-driven control loop).
Drive a base in a square
This example uses MoveStraight and Spin to walk a base around a 500 mm
square, stopping at each corner to turn 90 degrees.
Replace my-base with your base component’s name, and replace the
credentials and address placeholders with the values from the CONNECT
tab in the Viam app.
Set continuous power or velocity
For operator-driven control or sensor-driven loops, use SetPower or
SetVelocity rather than MoveStraight/Spin. Both methods take a linear
vector and an angular vector.
For wheeled bases, only two of the six fields matter in practice:
| Vector field | Meaning |
|---|---|
linear.Y | Forward and backward. Positive Y drives forward. |
angular.Z | Yaw. Positive Z turns left (counterclockwise, viewed above). |
The other four fields (linear.X, linear.Z, angular.X, angular.Y) exist
for bases with more degrees of freedom. Built-in wheeled base drivers ignore
them.
SetPower values range from -1.0 to 1.0 (fraction of maximum). SetVelocity
takes linear velocity in millimeters per second and angular velocity in
degrees per second.
When to use direct commands instead of motion planning
| Path | Use when | Trade-off |
|---|---|---|
| Direct commands | Short, well-defined movements with no obstacles to avoid | No path checking; you are responsible for the route |
MoveOnGlobe | Autonomous GPS waypoint navigation | Needs a movement sensor with GPS |
MoveOnMap | Driving to a pose on a SLAM-generated map | Needs a SLAM service |
Details for both planned paths:
Navigate to a waypoint and
MoveOnMap.
What’s next
- Navigate to a waypoint: autonomous GPS navigation with replanning.
- Monitor a running plan: track non-blocking MoveOnGlobe or MoveOnMap executions.
- Base API reference: full base component API surface.
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!