Previous
Move a base
You have two options for moving a robotic arm:
1. Configure an arm component
First, physically connect the arm to your machine.
Then, navigate to the CONFIGURE tab of your machine’s page in the Viam app. Click the + icon next to your machine part in the left-hand menu and select Component. Search for and select a model that supports your arm.
Complete the arm configuration, then use the TEST panel in the configuration card to test that the arm is working.
2. Connect code to your arm
Go to your machine’s CONNECT tab in the Viam app. Select your preferred programming language and copy the code snippet.
See Create a web app, Create a mobile app, or Create a headless app for more information, depending on your use case.
The two main options for controlling arm movement with the arm API are through joint position commands and through pose commands. Joint position commands allow for more detailed control and flexibility instead of commanding movement with the end effector position in a pose command.
Be careful when instructing robot arms to move. Before running any code, ensure your robotic arm has enough space and that there are no obstacles. Also pay attention to your surroundings, double-check your code for correctness, and make sure anyone nearby is aware and alert before issuing commands to your machine.
1. Initiate motion with a joint position command
Add the following line to your import list to be able to assign values to a JointPositions
data structure:
from viam.proto.component.arm import JointPositions
Add the following code to your script:
# Command a joint position move: move the forearm of the arm slightly up
cmd_joint_positions = JointPositions(values=[0, 0, -30.0, 0, 0, 0])
await arm_1.move_to_joint_positions(positions=cmd_joint_positions)
Add armapi "go.viam.com/api/component/arm/v1"
to your import list.
Add the following code to your script:
// Command a joint position move: move the forearm of the arm slightly up
cmdJointPositions := &armapi.JointPositions{Values: []float64{0.0, 0.0, -30.0, 0.0, 0.0, 0.0}}
err = arm1.MoveToJointPositions(context.Background(), cmdJointPositions, nil)
if err != nil {
logger.Error(err)
return
}
Run the code.
The third joint of your arm should move 30 degrees.
For more information, see MoveToJointPositions
.
2. Command to move to position
Add the following code to your script:
# Generate a simple pose move +100mm in the +Z direction of the arm
cmd_arm_pose = await arm_1.get_end_position()
cmd_arm_pose.z += 100.0
await arm_1.move_to_position(pose=cmd_arm_pose)
Add "go.viam.com/rdk/spatialmath"
to your import list.
Add the following code to your script:
// Generate a simple pose move +100mm in the +Z direction of the arm
currentArmPose, err := arm1.EndPosition(context.Background(), nil)
if err != nil {
logger.Error(err)
return
}
adjustedArmPoint := currentArmPose.Point()
adjustedArmPoint.Z += 100.0
cmdArmPose := spatialmath.NewPose(adjustedArmPoint, currentArmPose.Orientation())
err = arm1.MoveToPosition(context.Background(), cmdArmPose, nil)
if err != nil {
logger.Error(err)
return
}
This code gets the arm’s end position, makes a 100 millimeter adjustment in the +Z direction, and then uses that adjustment as a goal Pose
when commanding arm motion.
Run the code to see your arm move 100 mm upwards.
For more information, see MoveToPosition
.
The following tutorials demonstrate how to plan complex motion with a robot arm:
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!