Interact with Resources with Viam's client SDKs
Every Viam resource exposes an Application Programming Interface (API) described through protocol buffers. You can think of this as a description of how you can interact with that resource. Different models of resources implement the same API, which Viam SDKs expose, allowing you to control different models of resource types with a consistent interface.
The API methods provided by the SDKs for each of these resource APIs wrap gRPC client requests to the robot when you execute your program, providing you a convenient interface for accessing information about and controlling the resources you have configured on your robot.
ResourceBase Methods
In the Python SDK, the ResourceBase
class defines a basic set of API methods that all child resources should provide for users.
In the other SDKs, resource APIs implement but do not inherit these base requirements.
ResourceBase
methods include:
FromRobot
Get a resource configured on a robot by "name"
.
Parameters:
robot
(RobotClient): The robot.name
(str): Thename
of the resource.
Returns:
- (Resource): The named resource if it exists on your robot. For example, an arm.
my_arm = Arm.from_robot(robot, "my_arm")
For more information, see the Python SDK Docs.
Parameters:
r
(RobotClient): The robot.name
(string): The “name” of the resource.
Returns:
- (Resource): The named resource if it exists on your robot. For example, an arm.
my_arm = arm.FromRobot(robot, "my_arm")
For more information, see the Go SDK Docs.
In the TypeScript SDK, the equivalent of the FromRobot
is defined in each resource API’s client constructor.
For example, a component with type arm
and name my_arm
belonging to a robot robot
is instantiated as follows:
Parameters:
client
(RobotClient): The robot.name
(string): Thename
of the resource.
Returns:
- (Resource): The named resource if it exists on your robot. For example, an ArmClient.
const myArmClient = new VIAM.ArmClient(robot, "my_arm");
For more information, see the Typescript SDK Docs.
Name
Info
An equivalent for Name
is not currently provided by the TypeScript SDK.
Get the ResourceName
of a resource with the configured name
.
Parameters:
name
(str): Thename
of the resource.
Returns:
name
(proto.common.ResourceName
): TheResourceName
of the resource, including string fields for thenamespace
,type
,subtype
, andname
.
my_arm_name = my_arm.get_resource_name("my_arm")
For more information, see the Python SDK Docs.
Get the Name
of the resource.
Parameters:
- None
Returns:
name
(Name): TheName
of the resource, including fields for theAPI
withType
andSubtypeName
, and stringRemote
andName
.
MyArmName := MyArm.Name()
For more information, see the Go SDK Docs.
DoCommand
DoCommand sends commands containing arbitrary data to the resource.
Parameters:
command
(Mapping[str, viam.utils.ValueTypes]
): The command to execute.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:
- (
Mapping[str, viam.utils.ValueTypes]
): The result of the executed 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{}): The result of the executed command.
- (error): An error, if one occurred.
For more information, see the Go SDK Docs.
Parameters:
command
(StructType): The command to execute.
Returns:
- (StructType): The result of the executed command.
For more information, see the Typescript SDK Docs.
Component APIs
These APIs provide interfaces for controlling and getting information from various components of a robot. Built-in API methods are defined for every model of each component type. Documentation on using these methods in your SDK code is found on each component page as follows:
Arm
The arm component supports the following methods:
Method Name | Description |
---|---|
GetEndPosition | Get the current position of the arm as a Pose. |
MoveToPosition | Move the end of the arm to the desired Pose. |
MoveToJointPositions | Move each joint on the arm to the desired position. |
JointPositions | Get the current position of each joint on the arm. |
Stop | Stop the arm from moving. |
IsMoving | Get if the arm is currently moving. |
GetKinematics | Get the kinematics information associated with the arm. |
DoCommand | Send or receive model-specific commands. |
Base
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. |
DoCommand | Send or receive model-specific commands. |
Board
The board component supports the following methods:
Method Name | Description |
---|---|
AnalogReaderByName | Get an AnalogReader by name . |
DigitalInterruptByName | Get a DigitalInterrupt by name . |
GPIOPinByName | Get a GPIOPin by its pin number. |
AnalogReaderNames | Get the name of every AnalogReader . |
DigitalInterruptNames | Get the name of every DigitalInterrupt . |
Status | Get the current status of this board. |
ModelAttributes | Get the attributes related to the model of this board. |
SetPowerMode | Set the board to the indicated power mode. |
DoCommand | Send or receive model-specific commands. |
Camera
The camera component supports the following methods:
Method Name | Description |
---|---|
GetImage | Return an image from the camera. |
GetImages | Return multiple simultaneous images from different imagers, along with associated metadata. |
GetPointCloud | Return a point cloud from the camera. |
GetProperties | Return the camera intrinsic and camera distortion parameters, as well as whether the camera supports returning point clouds. |
DoCommand | Send or receive model-specific commands. |
Encoder
The encoder component supports the following methods:
Method Name | Description |
---|---|
GetPosition | Get the current position of the encoder. |
ResetPosition | Reset the position to zero. |
GetProperties | Get the supported properties of this encoder. |
DoCommand | Send or receive model-specific commands. |
Gantry
The gantry component supports the following methods:
Method Name | Description |
---|---|
GetPosition | Get the current positions of the axes of the gantry in mm. |
MoveToPosition | Move the axes of the gantry to the desired positions. |
Lengths | Get the lengths of the axes of the gantry in mm. |
Stop | Stop the gantry from moving. |
IsMoving | Get if the gantry is currently moving. |
DoCommand | Send or receive model-specific commands. |
Generic
The generic component supports the following methods:
Method Name | Description |
---|---|
DoCommand | Send or receive model-specific commands. |
Gripper
The gripper component supports the following methods:
Method Name | Description |
---|---|
Open | Open the gripper. |
Grab | Close the gripper until it grabs something or closes completely. |
Stop | Stop the gripper’s movement. |
IsMoving | Report whether the gripper is currently moving. |
DoCommand | Send or receive model-specific commands. |
Input Controller
The input controller component supports the following methods:
Method Name | Description |
---|---|
GetControls | Get a list of input Controls that this Controller provides. |
GetEvents | Get the current state of the Controller as a map of the most recent Event for each Control. |
RegisterControlCallback | Define a callback function to execute whenever one of the EventTypes selected occurs on the given Control. |
DoCommand | Send or receive model-specific commands. |
Motor
The motor component supports the following methods:
Method Name | Description |
---|---|
SetPower | Set the power to send to the motor as a portion of max power. |
GoFor | Spin the motor the specified number of revolutions at specified RPM. |
GoTo | Send the motor to a specified position (in terms of revolutions from home) at a specified speed. |
ResetZeroPosition | Set the current position to be the new zero (home) position. |
GetPosition | Report the position of the motor based on its encoder. Not supported on all motors. |
GetProperties | Return whether or not the motor supports certain optional features. |
IsPowered | Return whether or not the motor is currently on, and the amount of power to it. |
IsMoving | Return whether the motor is moving or not. |
Stop | Cut power to the motor off immediately, without any gradual step down. |
DoCommand | Send or receive model-specific commands. |
Movement Sensor
The movement sensor component supports the following methods. Some methods are only supported by certain models:
Method Name | Description | Models That Support This Method |
---|---|---|
GetPosition | Get the current latitude, longitude and altitude. | GPS models |
GetLinearVelocity | Get the current linear velocity as a 3D vector. | GPS models |
GetAngularVelocity | Get the current angular velocity as a 3D vector. | IMU models and gyro-mpu6050 |
GetLinearAcceleration | Get the current linear acceleration as a 3D vector. | IMU models, accel-adxl345 , and gyro-mpu6050 |
GetCompassHeading | Get the current compass heading in degrees. | GPS models and imu-vectornav |
GetOrientation | Get the current orientation. | IMU models |
GetProperties | Get the supported properties of this sensor. | all models |
GetAccuracy | Get the accuracy of the various sensors. | GPS models |
GetReadings | Obtain the measurements/data specific to this sensor. | all models |
DoCommand | Send or receive model-specific commands. | all models |
Sensor
The sensor component supports the following methods:
Method Name | Description |
---|---|
GetReadings | Get the measurements or readings that this sensor provides. |
DoCommand | Send or receive model-specific commands. |
Servo
The servo component supports the following methods:
Method Name | Description |
---|---|
Move | Move the servo to the desired angle. |
GetPosition | Get the current angle of the servo. |
Stop | Stop the servo. |
DoCommand | Send or receive model-specific commands. |
Service APIs
These APIs provide interfaces for controlling and getting information from the services you configured on a robot. Built-in API methods are defined for each service implementation. Documentation on using these methods in your SDK code is found on service pages as follows:
Base Remote Control
The base remote control service supports the following methods:
Method Name | Description |
---|---|
Close | Close out of all remote control related systems. |
ControllerInputs | Get a list of inputs from the controller that is being monitored for that control mode. |
Data Management
The data management service supports the following methods:
Method Name | Description |
---|---|
Sync | Sync data stored on the robot to the cloud. |
MLModel
The ML model service supports the following methods:
Method Name | Description |
---|---|
Infer | Take an already ordered input tensor as an array, make an inference on the model, and return an output tensor map. |
Metadata | Get the metadata (such as name, type, expected tensor/array shape, inputs, and outputs) associated with the ML model. |
Motion
The motion service supports the following methods:
Method Name | Description |
---|---|
Move | Move multiple components in a coordinated way to achieve a desired motion. |
GetPose | Get the current location and orientation of a component as a Pose . |
MoveOnMap | Move a base component to a Pose in respect to the origin of a SLAM map. |
MoveOnGlobe | Move a base component to a destination GPS point. Use a Movement Sensor to measure the robot’s GPS coordinates. |
Navigation
The navigation service supports the following methods:
Method Name | Description |
---|---|
Mode | Get the mode the service is operating in. |
SetMode | Set the mode the service is operating in. |
Location | Get the current location of the robot. |
Waypoints | Get the waypoints currently in the service’s data storage. |
AddWaypoint | Add a waypoint to the service’s data storage. |
RemoveWaypoint | Remove a waypoint from the service’s data storage. |
GetObstacles | Get the obstacles currently in the service’s data storage. |
Sensors
The sensors service supports the following methods:
Method Name | Description |
---|---|
GetSensors | Return a list of names of the available sensors. |
GetReadings | Return a list of readings from a given list of sensors. |
SLAM
The SLAM service supports the following methods:
Method Name | Description |
---|---|
GetPosition | Get the current position of the specified source component in the point cloud SLAM map. |
GetPointCloudMap | Get the point cloud SLAM map. |
GetInternalState | Get the internal state of the SLAM algorithm required to continue mapping/localization. |
GetLatestMapInfo | Get the timestamp of the last update to the point cloud SLAM map. |
Vision
Different vision service models support different methods:
Method Name | Description | Models That Support This Method |
---|---|---|
GetDetections | Get detections from an image. | detectors |
GetDetectionsFromCamera | Get detections from the next image from a camera. | detectors |
GetClassifications | Get classifications from an image. | classifiers |
GetClassificationsFromCamera | Get classifications from the next image from a camera. | classifiers |
GetObjectPointClouds | Get a list of point cloud objects from a 3D camera. | segmenters |
Signaling APIs
GPIO Pins
In addition to the board API, the board component supports the following methods for interfacing with GPIO pins on a board:
Method Name | Description |
---|---|
Set | Set the output of this pin to high/low. |
Get | Get if this pin is active (high). |
GetPWM | Get the pin’s pulse-width modulation duty cycle. |
SetPWM | Set the pin’s pulse-width modulation duty cycle. |
PWMFreq | Get the pulse-width modulation frequency of this pin. |
SetPWMFreq | Set the pulse-width modulation frequency of this pin. |
Analog-to-Digital Converters (ADCs)
In addition to the board API, the board component supports the following methods for interfacing with ADCs on a board:
Method Name | Description |
---|---|
Read | Read the current integer value of the digital signal output by the ADC. |
Digital Interrupts
In addition to the board API, the board component supports the following methods for interfacing with digital interrupts on a board:
Method Name | Description |
---|---|
Value | Get the current value of this interrupt. |
Tick | Record an interrupt. |
AddCallback | Add a channel as a callback for Tick(). |
AddPostProcessor | Add a PostProcessor function for Value(). |
Robot Management APIs
Robot API
All robots support the following methods through the robot API:
Method Name | Description |
---|---|
DiscoverComponents | Get a list of discovered component configurations. |
FrameSystemConfig | Get the configuration of a robot’s frame system. |
Status | Get the status of each of the resources on the robot. |
Close | Close the connections and stop periodic tasks across the robot. |
StopAll | Cancel all operations for the robot and stop its movement. |
ResourceNames | Get a list of all the robot’s resources. |
Cloud API
The cloud API supports the following methods (among others):
Method Name | Description |
---|---|
ListOrganizations | List the organizations the user owns. |
GetOrganizationNamespaceAvailability | Check the availability of an organization namespace. |
ListOrganizationMembers | List the members and invites of the current organization. |
UpdateOrganizationInviteAuthorizations | Update the authorizations attached to an organization invite that has already been created. |
CreateLocation | Create and name a location. |
GetLocation | Get a location by its ID. |
UpdateLocation | Change the name of and/or assign a parent location to a location. |
DeleteLocation | Delete a location. |
ListLocations | List locations. |
LocationAuth | Get a location’s authorization (location secrets). |
CreateLocationSecret | Create a new location secret. |
DeleteLocationSecret | Delete a location secret. |
GetRobot | Get a robot by robot ID. |
GetRobotParts | Get a list of all the parts under a specific robot. |
GetRobotPart | Get a robot part. |
GetRobotPartLogs | Get the logs associated with a robot part. |
TailRobotPartLogs | Get an asynchronous iterator that receives live robot part logs. |
GetRobotPartHistory | Get a list containing the history of a robot part. |
UpdateRobotPart | Update the name or configuration of a robot part. |
NewRobotPart | Create a new robot part. |
DeleteRobotPart | Delete a robot part. |
NewRobot | Create a new robot. |
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!