Arm Component
A robotic arm is a serial chain of joints and links, with a fixed end and an end effector end. Joints may rotate, translate, or both, while a link is a rigid connector between joints.
In simple terms, an arm has two ends: one fixed in place, and one with a device you can position.
When controlling an arm component, you can place the end effector at arbitrary cartesian positions relative to the base of the arm.
You can do this by calling the MoveToPosition
method to move the end effector to specified cartesian coordinates, or by controlling the joint positions directly with the MoveToJointPositions
method.
When controlling an arm with viam-server
, the following features are implemented for you:
- Linear motion planning
- Self-collision prevention
- Obstacle avoidance
Motion planning with your arm’s built-in software
Each arm model is supported with a driver that is compatible with the software API that the model’s manufacturer supports. While some arm models build inverse kinematics into their software, many do not.
Most of the arm drivers for the Viam RDK bypass any onboard inverse kinematics, and use Viam’s motion service instead.
This driver handles turning the arm on and off, querying the arm for its current joint position, sending requests for the arm to move to a specified set of joint positions, and engaging brakes as needed, if supported.
Arm drivers are also paired, in the RDK, with JSON files that describe the kinematics parameters of each arm.
When you configure a supported arm model to connect to
viam-server
, the Arm driver will load and parse the kinematics file for the Viam RDK’s frame system service to use.The frame system will allow you to easily calculate where any part of your machine is relative to any other part, other machine, or piece of the environment.
All arms have a
Home
position, which corresponds to setting all joint angles to 0.When an arm is moved with a
move_to_position
call, the movement will follow a straight line, and not deviate from the start or end orientations more than the start and orientations differ from one anotherIf there is no way for the arm to move to the desired location in a straight line, or if it would self-collide or collide with an obstacle that was passed in as something to avoid, then the
move_to_position
call will fail.
Related services
Supported models
To use your arm with Viam, check whether one of the following built-in models or modular resources supports your arm.
Built-in models
For configuration information, click on the model name:
Model | Description |
---|---|
fake | A model used for testing, with no physical hardware. |
xArm6 | UFACTORY xArm 6 |
xArm7 | UFACTORY xArm 7 |
lite6 | UFACTORY Lite 6 |
ur5e | Universal Robots UR5e |
Modular resources
Search for additional arm 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.
You can follow this guide to implement your custom arm as a modular resource.
Control your arm 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 an arm called "my_arm"
configured as a component of your machine.
If your arm has a different name, change the name
in the code.
Be sure to import the arm package for the SDK you are using:
from viam.components.arm import Arm
# To use move_to_position:
from viam.proto.common import Pose
# To use move_to_joint_positions:
from viam.proto.component.arm import JointPositions
import (
"go.viam.com/rdk/components/arm"
// To use MoveToPosition:
"go.viam.com/rdk/referenceframe"
"go.viam.com/rdk/spatialmath"
// To use MoveToJointPositions ("armapi" name optional, but necessary if importing other packages called "v1"):
armapi "go.viam.com/api/component/arm/v1"
)
API
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. |
GetJointPositions | 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. |
GetGeometries | Get all the geometries associated with the arm in its current configuration, in the frame of the arm. |
DoCommand | Send or receive model-specific commands. |
Close | Safely shut down the resource and prevent further use. |
GetEndPosition
Get the current position of the arm as a Pose.
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:
- (Pose): A representation of the arm’s current position as a 6 DOF (six degrees of freedom) pose.
The
Pose
is composed of values for location and orientation with respect to the origin. Location is expressed as distance, which is represented by x, y, and z coordinate values. Orientation is expressed as an orientation vector, which is represented by o_x, o_y, o_z, and theta values.
For more information, see the Python SDK Docs.
my_arm = Arm.from_robot(robot=robot, name="my_arm")
# Get the end position of the arm as a Pose.
pos = await my_arm.get_end_position()
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.
- (spatialmath.Pose): A representation of the arm’s current position as a 6 DOF (six degrees of freedom) pose.
The
Pose
is composed of values for location and orientation with respect to the origin. Location is expressed as distance, which is represented by x, y, and z coordinate values. Orientation is expressed as an orientation vector, which is represented by o_x, o_y, o_z, and theta values.
For more information, see the Go SDK Docs.
myArm, err := arm.FromRobot(robot, "my_arm")
// Get the end position of the arm as a Pose.
err, pos := myArm.EndPosition(context.Background(), nil)
MoveToPosition
Move the end of the arm to the desired Pose, relative to the base of the arm.
Parameters:
pose
(Pose): A representation of the arm’s current position as a 6 DOF (six degrees of freedom) pose. ThePose
is composed of values for location and orientation with respect to the origin. Location is expressed as distance, which is represented by x, y, and z coordinate values. Orientation is expressed as an orientation vector, which is represented by o_x, o_y, o_z, and theta values.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:
- None
For more information, see the Python SDK Docs.
my_arm = Arm.from_robot(robot=robot, name="my_arm")
# Create a Pose for the arm.
examplePose = Pose(x=5, y=5, z=5, o_x=5, o_y=5, o_z=5, theta=20)
# Move your arm to the Pose.
await my_arm.move_to_position(pose=examplePose)
Parameters:
ctx
(Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.Pose
(spatialmath.Pose): A representation of the arm’s current position as a 6 DOF (six degrees of freedom) pose. ThePose
is composed of values for location and orientation with respect to the origin. Location is expressed as distance, which is represented by x, y, and z coordinate values. Orientation is expressed as an orientation vector, which is represented by o_x, o_y, o_z, and theta values.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.
myArm, err := arm.FromRobot(robot, "my_arm")
// Create a Pose for the arm.
examplePose = []float64{x: 5, y: 5, z: 5, o_x: 5, o_y: 5, o_z: 5, theta:20}
// Move your arm to the Pose.
err := myArm.MoveToPosition(context.Background(), pose: examplePose, nil)
MoveToJointPositions
Move each joint on the arm to the position specified in positions
.
Caution
Collision checks are not enabled when doing direct joint control with MoveToJointPositions().
Parameters:
positions
(JointPositions): The desired position of each joint of the arm at the end of movement. JointPositions can have one attribute,values
, a list of joint positions with rotational values (degrees) and translational values (mm).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:
- None
For more information, see the Python SDK Docs
my_arm = Arm.from_robot(robot=robot, name="my_arm")
# Declare a list of values with your desired rotational value for each joint on
# the arm.
degrees = [0.0, 45.0, 0.0, 0.0, 0.0]
# Declare a new JointPositions with these values.
jointPos = arm.move_to_joint_positions(
JointPositions(values=[0.0, 45.0, 0.0, 0.0, 0.0]))
# Move each joint of the arm to the position these values specify.
await my_arm.move_to_joint_positions(positions=jointPos)
Parameters:
ctx
(Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.positions
(JointPositions): The desired position of each joint of the arm at the end of movement. JointPositions can have one attribute,values
, a list of joint positions with rotational values (degrees) and translational values (mm).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.
myArm, err := arm.FromRobot(robot, "my_arm")
// Declare an array of values with your desired rotational value for each joint on the arm.
degrees := []float64{4.0, 5.0, 6.0}
// Declare a new JointPositions with these values.
jointPos := componentpb.JointPositions{degrees}
// Move each joint of the arm to the position these values specify.
err := myArm.MoveToJointPositions(context.Background(), jointPos, nil)
GetJointPositions
Get the current position of each joint on the arm.
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:
- (JointPositions): The position of each joint of the arm.
JointPositions can have one attribute,
values
, a list of joint positions with rotational values (degrees) and translational values (mm).
For more information, see the Python SDK Docs
my_arm = Arm.from_robot(robot=robot, name="my_arm")
# Get the current position of each joint on the arm as JointPositions.
pos = await my_arm.get_joint_positions()
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.
- (JointPositions): The desired position of each joint of the arm at the end of movement.
JointPositions can have one attribute,
values
, a list of joint positions with rotational values (degrees) and translational values (mm).
For more information, see the Go SDK Docs.
my_arm, err := arm.FromRobot(robot, "my_arm")
// Get the current position of each joint on the arm as JointPositions.
pos, err := my_arm.JointPositions(context.Background(), nil)
Stop
Stop all motion of the arm.
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:
- None
For more information, see the Python SDK Docs.
my_arm = Arm.from_robot(robot=robot, name="my_arm")
# Stop all motion of the arm. It is assumed that the arm stops immediately.
await my_arm.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.
myArm, err := arm.FromRobot(robot, "my_arm")
// Stop all motion of the arm. It is assumed that the arm stops immediately.
err := myArm.Stop(context.Background(), nil)
GetKinematics
Note
This method is not yet available with the Viam Go SDK.
Get the kinematics information associated with the arm as the format and byte contents of the kinematics file.
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:
- (Tuple[KinematicsFileFormat.ValueType, bytes): A tuple containing the format of the arm’s
.URDF or.json kinematics file and the byte contents of the file.
For more information, see the Python SDK Docs.
my_arm = Arm.from_robot(robot=robot, name="my_arm")
# Get the kinematics information associated with the arm.
kinematics = await my_arm.get_kinematics()
# Get the format of the kinematics file.
k_file = kinematics[0]
# Get the byte contents of the file.
k_bytes = kinematics[1]
IsMoving
Get if the arm is currently moving.
Parameters:
- None
Returns:
- (bool): If it is true or false that the arm is currently moving.
For more information, see the Python SDK Docs.
my_arm = Arm.from_robot(robot=robot, name="my_arm")
# Stop all motion of the arm. It is assumed that the arm stops immediately.
await my_arm.stop()
# Print if the arm is currently moving.
print(my_arm.is_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.
myArm, err := arm.FromRobot(robot, "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)
GetGeometries
Get all the geometries associated with the arm in its current configuration, in the frame of the arm. 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 arm, in any order.
For more information, see the Python SDK Docs.
my_arm = Arm.from_robot(robot=robot, name="my_arm")
geometries = await my_arm.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 arm, in any order.- (error): An error, if one occurred.
For more information, see the Go SDK Docs.
myArm, err := arm.FromRobot(robot, "my_arm")
geometries, err := myArm.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 arm 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_arm = Arm.from_robot(robot, "my_arm")
command = {"cmd": "test", "data1": 500}
result = my_arm.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.
myArm, err := arm.FromRobot(robot, "my_arm")
command := map[string]interface{}{"cmd": "test", "data1": 500}
result, err := myArm.DoCommand(context.Background(), command)
For more information, see the Go SDK Docs.
Close
Safely shut down the resource and prevent further use.
Parameters:
- None
Returns:
- None
my_arm = Arm.from_robot(robot, "my_arm")
await my_arm.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.
myArm, err := arm.FromRobot(robot, "my_arm")
err := myArm.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 on 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!