Base API

The base API allows you to give commands to your base components for moving all configured components attached to a platform as a whole without needing to send commands to individual components.

The base component supports the following methods:

Method NameDescriptionviam-micro-server Support
MoveStraightMove the base in a straight line across the given distance (mm) at the given velocity (mm/sec).

SpinTurn the base in place, rotating it to the given angle (degrees) at the given angular velocity (degrees/sec).

SetPowerSet 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].

SetVelocitySet the linear velocity (mm/sec) and angular velocity (degrees/sec) of the base.

GetPropertiesGet the width and turning radius of the model of base in meters.

IsMovingReturns whether the base is actively moving (or attempting to move) under its own power.

StopStop the base from moving immediately.

GetGeometriesGet all the geometries associated with the base in its current configuration, in the frame of the base.

ReconfigureReconfigure this resource.

DoCommandExecute model-specific commands that are not otherwise defined by the component API.

GetResourceNameGet the ResourceName for this base with the given name.

CloseSafely shut down the resource and prevent further use.

Establish a connection

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.

When executed, this sample code creates a connection to your machine as a client.

The following 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

MoveStraight

Move the base in a straight line across the given distance (mm) at the given velocity (mm/sec).

Parameters:

  • distance (int) (required): The distance (in millimeters) to move. Negative implies backwards.
  • velocity (float) (required): The velocity (in millimeters per second) to move. Negative implies backwards.
  • extra (Mapping[str, Any]) (optional): Extra options to pass to the underlying RPC call.
  • timeout (float) (optional): An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call.

Returns:

  • None.

Example:

my_base = Base.from_robot(robot=machine, 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)

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.
  • 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.

Example:

myBase, err := base.FromRobot(machine, "my_base")
// Move the base forward 40 mm at a velocity of 90 mm/s.
myBase.MoveStraight(context.Background(), 40, 90, nil)

// Move the base backward 40 mm at a velocity of -90 mm/s.
myBase.MoveStraight(context.Background(), 40, -90, nil)

For more information, see the Go SDK Docs.

Parameters:

Returns:

Example:

// Move the base 40mm forward at 90 mm/s
await myBase.moveStraight(40, 90);

For more information, see the Flutter SDK Docs.

Spin

Turn the base in place, rotating it to the given angle (degrees) at the given angular velocity (degrees/sec).

Parameters:

  • angle (float) (required): The angle (in degrees) to spin.
  • velocity (float) (required): The angular velocity (in degrees per second) to spin. Given a positive angle and a positive velocity, the base will turn to the left.
  • extra (Mapping[str, Any]) (optional): Extra options to pass to the underlying RPC call.
  • timeout (float) (optional): An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call.

Returns:

  • None.

Example:

my_base = Base.from_robot(robot=machine, name="my_base")

# Spin the base 10 degrees at an angular velocity of 15 deg/sec.
await my_base.spin(angle=10, velocity=15)

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.
  • 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.

Example:

myBase, err := base.FromRobot(machine, "my_base")

// Spin the base 10 degrees at an angular velocity of 15 deg/sec.
myBase.Spin(context.Background(), 10, 15, nil)

For more information, see the Go SDK Docs.

Parameters:

Returns:

Example:

// Spin the base 10 degrees at 15 deg/s
await myBase.spin(10, 15);

For more information, see the Flutter SDK Docs.

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]. Supported by viam-micro-server.

Parameters:

  • linear (viam.components.base.Vector3) (required): The linear component. Only the Y component is used for wheeled base. Positive implies forwards.
  • angular (viam.components.base.Vector3) (required): The angular component. Only the Z component is used for wheeled base. Positive turns left; negative turns right.
  • extra (Mapping[str, Any]) (optional): Extra options to pass to the underlying RPC call.
  • timeout (float) (optional): An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call.

Returns:

  • None.

Example:

my_base = Base.from_robot(robot=machine, 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))

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.
  • 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.

Example:

myBase, err := base.FromRobot(machine, "my_base")

// Make your wheeled base move forward. Set linear power to 75%.
logger.Info("move forward")
err = myBase.SetPower(context.Background(), r3.Vector{Y: .75}, r3.Vector{}, nil)

// Make your wheeled base move backward. Set linear power to -100%.
logger.Info("move backward")
err = myBase.SetPower(context.Background(), r3.Vector{Y: -1}, r3.Vector{}, nil)

// Make your wheeled base spin left. Set angular power to 100%.
logger.Info("spin left")
err = myBase.SetPower(context.Background(), r3.Vector{}, 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)

For more information, see the Go SDK Docs.

Parameters:

Returns:

Example:

// Move the base straight forward at 75% power:
await myBase.setPower(Vector3(0, 0.75, 0), Vector3());

// Move the base straight backward at 100% power:
await myBase.setPower(Vector3(0, -1, 0), Vector3());

// Turn the base to the left at 50% power:
await myBase.setPower(Vector3(), Vector3(0, 0, 0.5));

// Turn the base to the right at 60% power:
await myBase.setPower(Vector3(), Vector3(0, 0, -0.6));

For more information, see the Flutter SDK Docs.

SetVelocity

Set the linear velocity (mm/sec) and angular velocity (degrees/sec) of the base.

Parameters:

  • linear (viam.components.base.Vector3) (required): Velocity in mm/sec.
  • angular (viam.components.base.Vector3) (required): Velocity in deg/sec.
  • extra (Mapping[str, Any]) (optional): Extra options to pass to the underlying RPC call.
  • timeout (float) (optional): An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call.

Returns:

  • None.

Example:

my_base = Base.from_robot(robot=machine, 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))

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.
  • 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.

Example:

myBase, err := base.FromRobot(machine, "my_base")

// Set the linear velocity to 50 mm/sec and the angular velocity to 15 deg/sec.
myBase.SetVelocity(context.Background(), r3.Vector{Y: 50}, r3.Vector{Z: 15}, nil)

For more information, see the Go SDK Docs.

Parameters:

Returns:

Example:

// Set the linear velocity to 50mm/s forward, and the angular velocity
to 15 deg/s counterclockwise
//
await myBase.setVelocity(Vector3(0, 50, 0), Vector3(0, 0, 15));

For more information, see the Flutter SDK Docs.

GetProperties

Get the width and turning radius of the model of base in meters.

Parameters:

  • extra (Mapping[str, Any]) (optional): Extra options to pass to the underlying RPC call.
  • timeout (float) (optional): An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call.

Returns:

Example:

my_base = Base.from_robot(robot=machine, 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}")

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.
  • extra (map[string]interface{}): Extra options to pass to the underlying RPC call.

Returns:

  • (Properties): A structure with three fields, WidthMeters, TurningRadiusMeters, and WheelCircumferenceMeters representing the width, turning radius, and wheel circumference of the physical base in meters (m).
  • (error): An error, if one occurred.

Example:

myBase, err := base.FromRobot(machine, "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

For more information, see the Go SDK Docs.

IsMoving

Returns whether the base is actively moving (or attempting to move) under its own power.

Parameters:

  • timeout (float) (optional): An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call.

Returns:

  • (bool): Whether the base is moving.

Example:

my_base = Base.from_robot(robot=machine, name="my_base")

# Check whether the base is currently moving.
moving = await my_base.is_moving()
print('Moving: ', moving)

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:

  • (bool): Whether this resource is moving (true) or not (false).
  • (error): An error, if one occurred.

Example:

// This example shows using IsMoving with an arm component.
myArm, err := arm.FromRobot(machine, "my_arm")

// Stop all motion of the arm. It is assumed that the arm stops immediately.
myArm.Stop(context.Background(), nil)

// Log if the arm is currently moving.
is_moving, err := myArm.IsMoving(context.Background())
logger.Info(is_moving)

For more information, see the Go SDK Docs.

Parameters:

  • None.

Returns:

Example:

bool baseIsMoving = await myBase.isMoving();

For more information, see the Flutter SDK Docs.

Stop

Stop the base from moving immediately. Supported by viam-micro-server.

Parameters:

  • extra (Mapping[str, Any]) (optional): Extra options to pass to the underlying RPC call.
  • timeout (float) (optional): An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call.

Returns:

  • None.

Example:

my_base = Base.from_robot(robot=machine, 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()

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.
  • extra (map[string]interface{}): Extra options to pass to the underlying RPC call.

Returns:

  • (error): An error, if one occurred.

Example:

// This example shows using Stop with an arm component.
myArm, err := arm.FromRobot(machine, "my_arm")

// Stop all motion of the arm. It is assumed that the arm stops immediately.
err = myArm.Stop(context.Background(), nil)

For more information, see the Go SDK Docs.

Parameters:

Returns:

Example:

await myBase.stop();

For more information, see the Flutter SDK Docs.

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 (Mapping[str, Any]) (optional): Extra options to pass to the underlying RPC call.
  • timeout (float) (optional): An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call.

Returns:

Example:

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}")

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.
  • extra (map[string]interface{}): Extra options to pass to the underlying RPC call.

Returns:

Example:

// This example shows using Geometries with an base component.
myBase, err := base.FromRobot(machine, "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.Pose())
}

For more information, see the Go SDK Docs.

Reconfigure

Reconfigure this resource. Reconfigure must reconfigure the resource atomically and in place.

Parameters:

  • ctx (Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.
  • deps (Dependencies): The resource dependencies.
  • conf (Config): The resource configuration.

Returns:

  • (error): An error, if one occurred.

For more information, see the Go SDK Docs.

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. Supported by viam-micro-server.

Parameters:

  • command (Mapping[str, ValueTypes]) (required): The command to execute.
  • timeout (float) (optional): An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call.

Returns:

  • (Mapping[str, viam.utils.ValueTypes]): Result of the executed command.

Raises:

  • (NotImplementedError): Raised if the Resource does not support arbitrary commands.

Example:

command = {"cmd": "test", "data1": 500}
result = await my_base.do_command(command)

For more information, see the Python SDK Docs.

Parameters:

Returns:

Example:

myBase, err := base.FromRobot(machine, "my_base")

command := map[string]interface{}{"cmd": "test", "data1": 500}
result, err := myBase.DoCommand(context.Background(), command)

For more information, see the Go SDK Docs.

Parameters:

Returns:

Example:

// Example using doCommand with an arm component
const command = {'cmd': 'test', 'data1': 500};
var result = myArm.doCommand(command);

For more information, see the Flutter SDK Docs.

GetResourceName

Get the ResourceName for this base with the given name.

Parameters:

  • name (str) (required): The name of the Resource.

Returns:

Example:

my_base_name = Base.get_resource_name("my_base")

For more information, see the Python SDK Docs.

Parameters:

Returns:

For more information, see the Flutter SDK Docs.

Close

Safely shut down the resource and prevent further use.

Parameters:

  • None.

Returns:

  • None.

Example:

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.

Example:

myBase, err := base.FromRobot(machine, "my_base")

err = myBase.Close(context.Background())

For more information, see the Go SDK Docs.

Have questions, or want to meet other people working on robots? Join our Community Discord.

If you notice any issues with the documentation, feel free to file an issue or edit this file.