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.

A robot comprised of a wheeled base (motors, wheels and chassis) as well as some other components. The wheels are highlighted to indicate that they are part of the concept of a ‘base’, while the non-base components are not highlighted. The width and circumference are required attributes when configuring a base component.

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.

Configuration

For configuration information, click on one of the supported base models:

ModelDescription
wheeledMobile wheeled robot
agilex-limoAgilex LIMO Mobile Robot
fakeA model used for testing, with no physical hardware

Control your base with Viam’s client SDK libraries

To get started using Viam’s SDKs to connect to and control your robot, go to your robot’s page on the Viam app, navigate to the Code sample tab, select your preferred programming language, and copy the sample code generated.

When executed, this sample code will create a connection to your robot as a client. Then control your robot 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 robot. 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 NameDescription
MoveStraightMove the base in a straight line across the given distance at the given velocity.
SpinMove the base to the given angle at the given angular velocity.
SetPowerSet the relative power (out of max power) for linear and angular propulsion of the base.
SetVelocitySet the linear velocity and angular velocity of the base.
IsMovingReturn whether the base is moving or not.
StopStop the base.
GetPropertiesGet the width and turning radius of the base in meters.
DoCommandSend or receive model-specific commands.

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:

  • (bool): True if the base is currently moving.
  • (error): An error, if one occurred.

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 two fields, width and turning_radius_meters, representing the width and turning radius 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 in meters: {properties.width}")

# Get the turning radius
print(f"Turning radius of base in meters: {properties.turning_radius_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 two fields, WidthMeters and TurningRadiusMeters, representing the width and turning radius 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

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:

Returns:

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:

Returns:

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.

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