Base Component
A base is the platform that the other parts of a mobile robot attach to.
By configuring a base component, organizing individual components to produce coordinated movement, you gain an interface to control the movement of the whole physical base of the robot without needing to send separate commands to individual motors.
Most mobile robots with a base need at least the following hardware:
- A board.
- Some sort of actuators to move the base. Usually motors attached to wheels or propellers.
- A power supply for the board.
- A power supply for the actuators.
- Some sort of chassis to hold everything together.
Related services
Supported models
To use your base with Viam, check whether one of the following built-in models or modular resources supports your base.
Built-in models
For configuration information, click on the model name:
Model | Description |
---|---|
wheeled | Mobile wheeled robot |
sensor-controlled | A model that wraps other base models with feedback control from a movement sensor |
fake | A model used for testing, with no physical hardware |
Modular resources
Search for additional base models that you can add from the Viam Registry:
For configuration information, click on the model name:
Add support for other models
If none of the existing models fit your use case, you can create a modular resource to add support for it.
Micro-RDK
If you are using the micro-RDK, navigate to Micro-RDK Base for supported model information.
Control your base with Viam’s client SDK libraries
To get started using Viam’s SDKs to connect to and control your machine, go to your machine’s page on the Viam app, navigate to the CONNECT tab’s Code sample page, select your preferred programming language, and copy the sample code generated.
API key and API key ID
By default, the sample code does not include your machine API key and API key ID. We strongly recommend that you add your API key and API key ID as an environment variable and import this variable into your development environment as needed.
To show your machine’s API key and API key ID in the sample code, toggle Include secret on the CONNECT tab’s Code sample page.
Caution
Do not share your API key or machine address publicly. Sharing this information could compromise your system security by allowing unauthorized access to your machine, or to the computer running your machine.
When executed, this sample code will create a connection to your machine as a client. Then control your machine programmatically by adding API method calls as shown in the following examples.
These examples assume you have a wheeled base called "my_base"
configured as a component of your machine.
If your base has a different name, change the name
in the code.
Be sure to import the base package for the SDK you are using:
from viam.components.base import Base
import (
"go.viam.com/rdk/components/base"
)
API
The base component supports the following methods:
Method Name | Description |
---|---|
MoveStraight | Move the base in a straight line across the given distance at the given velocity. |
Spin | Move the base to the given angle at the given angular velocity. |
SetPower | Set the relative power (out of max power) for linear and angular propulsion of the base. |
SetVelocity | Set the linear velocity and angular velocity of the base. |
IsMoving | Return whether the base is moving or not. |
Stop | Stop the base. |
GetProperties | Get the width and turning radius of the base in meters. |
GetGeometries | Get all the geometries associated with the base in its current configuration, in the frame of the base. |
DoCommand | Send or receive model-specific commands. |
Close | Safely shut down the resource and prevent further use. |
MoveStraight
Move the base in a straight line across the given distance (mm) at the given velocity (mm/sec).
Parameters:
distance
(int): The distance to move in millimeters. Positive implies forwards. Negative implies backwards.velocity
(float): The velocity at which to move in millimeters per second. Positive implies forwards. Negative implies backwards.
Returns:
- None.
For more information, see the Python SDK Docs.
my_base = Base.from_robot(robot=robot, name="my_base")
# Move the base 40 mm at a velocity of 90 mm/s, forward.
await my_base.move_straight(distance=40, velocity=90)
# Move the base 40 mm at a velocity of -90 mm/s, backward.
await my_base.move_straight(distance=40, velocity=-90)
Parameters:
ctx
(Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.distanceMm
(int): The distance to move the base in millimeters. Positive implies forwards. Negative implies backwards.mmPerSec
(float64): The velocity at which to move the base in millimeters per second. Positive implies forwards. Negative implies backwards.extra
(map[string]interface{}): Extra options to pass to the underlying RPC call.
Returns:
- (error): An error, if one occurred.
For more information, see the Go SDK Docs.
myBase, err := base.FromRobot(robot, "my_base")
// Move the base forward 40 mm at a velocity of 90 mm/s.
myBase.MoveStraight(context.Background(), distanceMm: 40, mmPerSec: 90, nil)
// Move the base backward 40 mm at a velocity of -90 mm/s.
myBase.MoveStraight(context.Background(), distanceMm: 40, mmPerSec: -90, nil)
Spin
Turn the base in place, rotating it to the given angle (degrees) at the given angular velocity (degrees/sec).
Parameters:
angle
(float): The angle to spin in degrees. Positive implies turning to the left.velocity
(float): The angular velocity at which to spin in degrees per second. Given a positive angle and a positive velocity, the base turns to the left (for built-in base models).
Returns:
- None.
For more information, see the Python SDK Docs.
my_base = Base.from_robot(robot=robot, name="my_base")
# Spin the base 10 degrees at an angular velocity of 15 deg/sec.
await my_base.spin(angle=10, velocity=15)
Parameters:
ctx
(Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.angleDeg
(float64): The angle to spin in degrees. Positive implies turning to the left.degsPerSec
(float64): The angular velocity at which to spin in degrees per second. Given a positive angle and a positive velocity, the base turns to the left (for built-in base models).extra
(map[string]interface{}): Extra options to pass to the underlying RPC call.
Returns:
- (error): An error, if one occurred.
For more information, see the Go SDK Docs.
myBase, err := base.FromRobot(robot, "my_base")
// Spin the base 10 degrees at an angular velocity of 15 deg/sec.
myBase.Spin(context.Background(), angleDeg: 10, degsPerSec: 15, nil)
SetPower
Set the linear and angular power of the base, represented as a percentage of max power for each direction in the range of [-1.0 to 1.0].
Parameters:
linear
(Vector3): The percentage of max power of the base’s linear propulsion. In the range of -1.0 to 1.0, with 1.0 meaning 100% power. Viam’s coordinate system considers +Y to be the forward axis (+/- X right/left, +/- Z up/down), so use the Y component of this vector to move forward and backward when controlling a wheeled base. Positive “Y” values imply moving forwards. Negative “Y” values imply moving backwards.angular
(Vector3): The percentage of max power of the base’s angular propulsion. In the range of -1.0 to 1.0, with 1.0 meaning 100% power. Use the Z component of this vector to spin left or right when controlling a wheeled base. Positive “Z” values imply spinning to the left (for built-in base models).
Returns:
- None.
For more information, see the Python SDK Docs.
my_base = Base.from_robot(robot=robot, name="my_base")
# Make your wheeled base move forward. Set linear power to 75%.
print("move forward")
await my_base.set_power(
linear=Vector3(x=0, y=-.75, z=0),
angular=Vector3(x=0, y=0, z=0))
# Make your wheeled base move backward. Set linear power to -100%.
print("move backward")
await my_base.set_power(
linear=Vector3(x=0, y=-1.0, z=0),
angular=Vector3(x=0, y=0, z=0))
# Make your wheeled base spin left. Set angular power to 100%.
print("spin left")
await my_base.set_power(
linear=Vector3(x=0, y=0, z=0),
angular=Vector3(x=0, y=0, z=1))
# Make your wheeled base spin right. Set angular power to -75%.
print("spin right")
await my_base.set_power(
linear=Vector3(x=0, y=0, z=0),
angular=Vector3(x=0, y=0, z=-.75))
Parameters:
ctx
(Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.linear
(r3.Vector): The percentage of max power of the base’s linear propulsion. In the range of -1.0 to 1.0, with 1.0 meaning 100% power. Viam’s coordinate system considers +Y to be the forward axis (+/- X right/left, +/- Z up/down), so use the Y component of this vector to move forward and backward when controlling a wheeled base. Positive “Y” values imply moving forwards. Negative “Y” values imply moving backwards.angular
(r3.Vector): The percentage of max power of the base’s angular propulsion. In the range of -1.0 to 1.0, with 1.0 meaning 100% power. Use the Z component of this vector to spin left or right when controlling a wheeled base. Positive “Z” values imply spinning to the left (for built-in base models).extra
(map[string]interface{}): Extra options to pass to the underlying RPC call.
Returns:
- (error): An error, if one occurred.
For more information, see the Go SDK Docs.
myBase, err := base.FromRobot(robot, "my_base")
// Make your wheeled base move forward. Set linear power to 75%.
logger.Info("move forward")
err = myBase.SetPower(context.Background(), linear: r3.Vector{Y: .75}, angular: r3.Vector{}, nil)
// Make your wheeled base move backward. Set linear power to -100%.
logger.Info("move backward")
err = myBase.SetPower(context.Background(), linear: r3.Vector{Y: -1}, angular: r3.Vector{}, nil)
// Make your wheeled base spin left. Set angular power to 100%.
logger.Info("spin left")
err = myBase.SetPower(context.Background(), linear: r3.Vector{}, angular: r3.Vector{Z: 1}, nil)
// Make your wheeled base spin right. Set angular power to -75%.
logger.Info("spin right")
err = mybase.SetPower(context.Background(), r3.Vector{}, r3.Vector{Z: -.75}, nil)
SetVelocity
Set the linear velocity (mm/sec) and angular velocity (degrees/sec) of the base.
Parameters:
linear
(Vector3): The linear velocity in millimeters per second. Only the Y component of the vector is used for a wheeled base, since Viam’s coordinate system considers +Y to be the forward axis.angular
(Vector3): The angular velocity in degrees per second. Only the Z component of the vector is used for a wheeled base, since Viam’s coordinate system considers +Z to point up and the angular velocity to rotate around the Z axis.
Returns:
- None.
For more information, see the Python SDK Docs.
my_base = Base.from_robot(robot=robot, name="my_base")
# Set the linear velocity to 50 mm/sec and the angular velocity to
# 15 degree/sec.
await my_base.set_velocity(
linear=Vector3(x=0, y=50, z=0), angular=Vector3(x=0, y=0, z=15))
Parameters:
ctx
(Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.linear
(r3.Vector): The linear velocity in millimeters per second. Only the Y component of the vector is used for a wheeled base.angular
(r3.Vector): The angular velocity in degrees per second. Only the Z component of the vector is used for a wheeled base.extra
(map[string]interface{}): Extra options to pass to the underlying RPC call.
Returns:
- (error): An error, if one occurred.
For more information, see the Go SDK Docs.
// import "github.com/golang/geo/r3" ...
myBase, err := base.FromRobot(robot, "my_base")
// Set the linear velocity to 50 mm/sec and the angular velocity to 15 deg/sec.
myBase.SetVelocity(context.Background(), linear: r3.Vector{Y: 50}, angular: r3.Vector{Z: 15}, nil)
Stop
Stop the base from moving immediately.
Parameters:
- None.
Returns:
- None.
For more information, see the Python SDK Docs.
my_base = Base.from_robot(robot=robot, name="my_base")
# Move the base forward 10 mm at a velocity of 50 mm/s.
await my_base.move_straight(distance=10, velocity=50)
# Stop the base.
await my_base.stop()
Parameters:
ctx
(Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.extra
(map[string]interface{}): Extra options to pass to the underlying RPC call.
Returns:
- (error): An error, if one occurred.
For more information, see the Go SDK Docs.
myBase, err := base.FromRobot(robot, "my_base")
// Move the base forward 10 mm at a velocity of 50 mm/s.
myBase.MoveStraight(context.Background(), 10, 50, nil)
// Stop the base.
myBase.Stop(context.Background(), nil)
IsMoving
Returns whether the base is actively moving (or attempting to move) under its own power.
Parameters:
- None.
Returns:
- (bool): True if the base is currently moving; false if not.
For more information, see the Python SDK Docs.
my_base = Base.from_robot(robot=robot, name="my_base")
# Check whether the base is currently moving.
moving = await my_base.is_moving()
print('Moving: ', moving)
Parameters:
ctx
(Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.
Returns:
For more information, see the Go SDK Docs.
myBase, err := base.FromRobot(robot, "my_base")
// Check whether the base is currently moving.
moving, err := myBase.IsMoving(context.Background())
logger.Info("Is moving?")
logger.Info(moving)
GetProperties
Get the width and turning radius of the model of base in meters.
Parameters:
timeout
(Optional[float]): An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call.
Returns:
- (Properties): A dataclass with three fields,
width_meters
,turning_radius_meters
, andwheel_circumference_meters
representing the width, turning radius, and wheel circumference of the physical base in meters (m).
For more information, see the Python SDK Docs.
my_base = Base.from_robot(robot=robot, name="my_base")
# Get the width and turning radius of the base
properties = await my_base.get_properties()
# Get the width
print(f"Width of base: {properties.width_meters}")
# Get the turning radius
print(f"Turning radius of base: {properties.turning_radius_meters}")
# Get the wheel circumference
print(f"Wheel circumference of base: {properties.wheel_circumference_meters}")
Parameters:
ctx
(Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.extra
(map[string]interface{}): Extra options to pass to the underlying RPC call.
Returns:
- (Properties): A structure with three fields,
WidthMeters
,TurningRadiusMeters
, andWheelCircumferenceMeters
representing the width, turning radius, and wheel circumference of the physical base in meters (m). - (error): An error, if one occurred.
For more information, see the Go SDK Docs.
myBase, err := base.FromRobot(robot, "my_base")
// Get the width and turning radius of the base
properties, err := myBase.Properties(context.Background(), nil)
// Get the width
myBaseWidth := properties.WidthMeters
// Get the turning radius
myBaseTurningRadius := properties.TurningRadiusMeters
// Get the wheel circumference
myBaseWheelCircumference := properties.WheelCircumferenceMeters
GetGeometries
Get all the geometries associated with the base in its current configuration, in the frame of the base. The motion and navigation services use the relative position of inherent geometries to configured geometries representing obstacles for collision detection and obstacle avoidance while motion planning.
Parameters:
extra
(Optional[Dict[str, Any]]): Extra options to pass to the underlying RPC call.timeout
(Optional[float]): An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call.
Returns:
- (List[Geometry]): The geometries associated with the base, in any order.
For more information, see the Python SDK Docs.
my_base = Base.from_robot(robot=robot, name="my_base")
geometries = await my_base.get_geometries()
if geometries:
# Get the center of the first geometry
print(f"Pose of the first geometry's centerpoint: {geometries[0].center}")
Parameters:
ctx
(Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.
Returns:
[]spatialmath.Geometry
: The geometries associated with the base, in any order.- (error): An error, if one occurred.
For more information, see the Go SDK Docs.
myBase, err := base.FromRobot(robot, "my_base")
geometries, err := myBase.Geometries(context.Background(), nil)
if len(geometries) > 0 {
// Get the center of the first geometry
elem := geometries[0]
fmt.Println("Pose of the first geometry's center point:", elem.center)
}
DoCommand
Execute model-specific commands that are not otherwise defined by the component API.
For built-in models, model-specific commands are covered with each model’s documentation.
If you are implementing your own base and add features that have no built-in API method, you can access them with DoCommand
.
Parameters:
command
(Dict[str, Any]): The command to execute.
Returns:
- (Dict[str, Any]): Result of the executed command.
my_base = Base.from_robot(robot, "my_base")
command = {"cmd": "test", "data1": 500}
result = my_base.do(command)
For more information, see the Python SDK Docs.
Parameters:
ctx
(Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.cmd
(map[string]interface{}): The command to execute.
Returns:
- (map[string]interface{}): Result of the executed command.
- (error): An error, if one occurred.
myBase, err := base.FromRobot(robot, "my_base")
command := map[string]interface{}{"cmd": "test", "data1": 500}
result, err := myBase.DoCommand(context.Background(), command)
For more information, see the Go SDK Code.
Close
Safely shut down the resource and prevent further use.
Parameters:
- None
Returns:
- None
my_base = Base.from_robot(robot, "my_base")
await my_base.close()
For more information, see the Python SDK Docs.
Parameters:
ctx
(Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.
Returns:
- (error) : An error, if one occurred.
myBase, err := base.FromRobot(robot, "my_base")
err := myBase.Close(ctx)
For more information, see the Go SDK Docs.
Troubleshooting
You can find additional assistance in the Troubleshooting section.
You can also ask questions in the Community Discord and we will be happy to help.
Next steps
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!