Manage Robots with Viam's Robot API

The robot API is the application programming interface that manages each of your robots running viam-server. It is the API for high level operations of each robot part. To interact with the robot API with Viam’s SDKs, instantiate a RobotClient (gRPC client) and use that class for all interactions.

These are some of the supported robot API methods. For a full list see GitHub.

Method NameDescription
DiscoverComponentsGet a list of discovered component configurations.
FrameSystemConfigGet the configuration of a robot’s frame system.
StatusGet the status of each of the resources on the robot.
CloseClose the connections and stop periodic tasks across the robot.
StopAllCancel all operations for the robot and stop its movement.
ResourceNamesGet a list of all the robot’s resources.

DiscoverComponents

Get a list of discovered component configurations.

Parameters:

Returns:

# Define a new discovery query.
q = robot.DiscoveryQuery(subtype=acme.API, model="some model")

# Define a list of discovery queries.
qs = [q]

# Get component configurations with these queries.
component_configs = await robot.discover_components(qs)

For more information, see the Python SDK Docs

Parameters:

Returns:

  • ([]resource.Discovery): The search query qs and the corresponding list of discovered component configurations as an interface called Results. Results may be comprised of primitives, a list of primitives, maps with string keys (or at least can be decomposed into one), or lists of the forementioned type of maps.
  • (error): An error, if one occurred.
// Define a new discovery query.
q := resource.NewDiscoveryQuery(acme.API, resource.Model{Name: "some model"})

// Define a list of discovery queries.
qs := []resource.DiscoverQuery{q}

// Get component configurations with these queries.
component_configs, err := robot.DiscoverComponents(ctx.Background(), qs)

For more information, see the Go SDK Docs.

Parameters:

Returns:

// Define a new discovery query.
const q = new proto.DiscoveryQuery(acme.API, resource.Model{Name: "some model"})

// Define an array of discovery queries.
let qs:  proto.DiscoveryQuery[] = [q]

// Get the array of discovered component configurations.
const componentConfigs = await robot.discoverComponents(queries);

For more information, see the Typescript SDK Docs.

FrameSystemConfig

Get the configuration of the frame system of a given robot.

Parameters:

Returns:

# Get a list of each of the reference frames configured on the robot.
frame_system = await robot.get_frame_system_config()
print(f"frame system configuration: {frame_system}")

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:

For more information, see the Go SDK Docs.

// Print the frame system configuration
frameSystem, err := robot.FrameSystemConfig(context.Background(), nil)
fmt.Println(frameSystem)

Parameters:

Returns:

For more information, see the TypeScript SDK Docs.

// Get the frame system configuration.
console.log("FrameSytemConfig:", await robot.frameSystemConfig());

Status

Get the status of the resources on the robot. You can provide a list of ResourceNames for which you want statuses. If no names are passed in, the status of every resource configured on the robot is returned.

Parameters:

Returns:

  • (List[str]): A list containing the status of each resource.

For more information, see the Python SDK Docs.

# Get the status of the resources on the robot.
statuses = await robot.get_status()

Parameters:

  • ctx (Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.
  • resourceNames ([]resource.Name): An optional list of ResourceNames for components you want the status of. If no names are passed in, all resource statuses are returned.

Returns:

For more information, see the Go SDK Docs.

// Get the status of the resources on the robot.
status, err = robot.Status(ctx.Background())

Parameters:

  • resourceNames (commonApi.ResourceName[]): An optional array of ResourceNames for components you want the status of. If no names are passed in, all resource statuses are returned.

Returns:

For more information, see the TypeScript SDK Docs.

// Get the status of the resources on the robot.
const status = await robot.getStatus();

Close

Close the underlying connections and stop any periodic tasks across all constituent parts of the robot.

Parameters:

  • None

Returns:

  • None

For more information, see the Python SDK Docs.

# Cleanly close the underlying connections and stop any periodic tasks.
await robot.close()

Parameters:

  • ctx (Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.

Returns:

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

For more information, see the Go SDK Docs.

// Cleanly close the underlying connections and stop any periodic tasks,
err := robot.Close(ctx.Background())

Parameters:

  • None

Returns:

  • None

For more information, see the TypeScript SDK Docs.

// Cleanly close the underlying connections and stop any periodic tasks
await robot.disconnect();

StopAll

Cancel all current and outstanding operations for the robot and stop all actuators and movement.

Parameters:

Returns:

  • None

For more information, see the Python SDK Docs.

# Cancel all current and outstanding operations for the robot and stop all
# actuators and movement.
await robot.stop_all()

Parameters:

Returns:

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

For more information, see the Go SDK Docs.

// Cancel all current and outstanding operations for the robot and stop all actuators and movement.
err := robot.StopAll(ctx.Background())

Parameters:

  • None

Returns:

  • None

For more information, see the TypeScript SDK Docs.

// Cancel all current and outstanding operations for the robot and stop all actuators and movement.
await robot.stopAll();

ResourceNames

Get a list of all known resource names connected to this robot.

Parameters:

  • None

Returns:

resource_names = robot.resource_names

Parameters:

  • None

Returns:

resource_names := robot.ResourceNames()

For more information, see the Go SDK Docs.

Parameters:

  • None

Returns:

// Get a list of all resources on the robot.
const resource_names = await robot.resourceNames();

For more information, see the Typescript SDK Docs.



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