Skip to content

Commit

Permalink
DOCS-2889: Turn access arm tutorial into how-to (#3650)
Browse files Browse the repository at this point in the history
  • Loading branch information
sguequierre authored Nov 14, 2024
1 parent 100547b commit 6927777
Show file tree
Hide file tree
Showing 22 changed files with 235 additions and 503 deletions.
Binary file added assets/how-tos/access-arm/config.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ err = myArmComponent.MoveToPosition(context.Background(), cmdArmPose, referencef
You can use any robotic arm with Viam.
Configure it as an arm component. Then you can move it using the arm API.

[Move a robotic arm →](/tutorials/services/accessing-and-moving-robot-arm/)
[Move a robotic arm →](/how-tos/move-robot-arm/)

</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion docs/components/arm/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ For general configuration, development, and usage info, see:
{{< cards >}}
{{% card link="/how-tos/configure/" noimage="true" %}}
{{% card link="/how-tos/develop-app/" noimage="true" %}}
{{% card link="/tutorials/services/accessing-and-moving-robot-arm" noimage="true" %}}
{{% card link="/how-tos/move-robot-arm/" noimage="true" %}}
{{< /cards >}}

You can also use the arm component with the following services:
Expand Down
2 changes: 1 addition & 1 deletion docs/components/arm/eva.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@ For more configuration and usage info, see:
{{< cards >}}
{{% card link="/appendix/apis/components/arm/" customTitle="Arm API" noimage="true" %}}
{{% card link="/how-tos/configure/" noimage="true" %}}
{{% card link="/tutorials/services/accessing-and-moving-robot-arm/" noimage="true" %}}
{{% card link="/how-tos/move-robot-arm/" noimage="true" %}}
{{< /cards >}}
2 changes: 1 addition & 1 deletion docs/components/arm/fake.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,5 @@ For more configuration and usage info, see:
{{< cards >}}
{{% card link="/appendix/apis/components/arm/" customTitle="Arm API" noimage="true" %}}
{{% card link="/how-tos/configure/" noimage="true" %}}
{{% card link="/tutorials/services/accessing-and-moving-robot-arm/" noimage="true" %}}
{{% card link="/how-tos/move-robot-arm/" noimage="true" %}}
{{< /cards >}}
2 changes: 1 addition & 1 deletion docs/components/arm/lite6.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,5 +176,5 @@ For more configuration and usage info, see:
{{< cards >}}
{{% card link="/appendix/apis/components/arm/" customTitle="Arm API" noimage="true" %}}
{{% card link="/how-tos/configure/" noimage="true" %}}
{{% card link="/tutorials/services/accessing-and-moving-robot-arm/" noimage="true" %}}
{{% card link="/how-tos/move-robot-arm/" noimage="true" %}}
{{< /cards >}}
2 changes: 1 addition & 1 deletion docs/components/arm/ur5e.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,5 @@ For more configuration and usage info, see:
{{< cards >}}
{{% card link="/appendix/apis/components/arm/" customTitle="Arm API" noimage="true" %}}
{{% card link="/how-tos/configure/" noimage="true" %}}
{{% card link="/tutorials/services/accessing-and-moving-robot-arm/" noimage="true" %}}
{{% card link="/how-tos/move-robot-arm/" noimage="true" %}}
{{< /cards >}}
2 changes: 1 addition & 1 deletion docs/components/arm/xarm6.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,5 +177,5 @@ For more configuration and usage info, see:
{{< cards >}}
{{% card link="/appendix/apis/components/arm/" customTitle="Arm API" noimage="true" %}}
{{% card link="/how-tos/configure/" noimage="true" %}}
{{% card link="/tutorials/services/accessing-and-moving-robot-arm/" noimage="true" %}}
{{% card link="/how-tos/move-robot-arm/" noimage="true" %}}
{{< /cards >}}
2 changes: 1 addition & 1 deletion docs/components/arm/xarm7.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,5 +177,5 @@ For more configuration and usage info, see:
{{< cards >}}
{{% card link="/appendix/apis/components/arm/" customTitle="Arm API" noimage="true" %}}
{{% card link="/how-tos/configure/" noimage="true" %}}
{{% card link="/tutorials/services/accessing-and-moving-robot-arm/" noimage="true" %}}
{{% card link="/how-tos/move-robot-arm/" noimage="true" %}}
{{< /cards >}}
2 changes: 1 addition & 1 deletion docs/components/arm/yahboom-dofbot.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,5 @@ For more configuration and usage info, see:
{{< cards >}}
{{% card link="/appendix/apis/components/arm/" customTitle="Arm API" noimage="true" %}}
{{% card link="/how-tos/configure/" noimage="true" %}}
{{% card link="/tutorials/services/accessing-and-moving-robot-arm/" noimage="true" %}}
{{% card link="/how-tos/move-robot-arm/" noimage="true" %}}
{{< /cards >}}
3 changes: 2 additions & 1 deletion docs/how-tos/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ The guides on this page provide solutions for common tasks and workflows. Browse

<div id="how-to-paths">

{{< how-to-expand title="Get started with Viam basics" tasks="4" level="BEGINNER-FRIENDLY" >}}
{{< how-to-expand title="Get started with Viam basics" tasks="5" level="BEGINNER-FRIENDLY" >}}
{{< cards >}}
{{% card link="/how-tos/drive-rover/" noimage="true" %}}
{{% card link="/how-tos/control-motor/" noimage="true" %}}
{{% card link="/how-tos/detect-people/" noimage="true" %}}
{{% card link="/how-tos/collect-data/" noimage="true" %}}
{{% card link="/how-tos/move-robot-arm/" noimage="true" %}}
{{< /cards >}}
{{< /how-to-expand >}}

Expand Down
219 changes: 219 additions & 0 deletions docs/how-tos/move-robot-arm.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
---
title: "Move a robot arm"
linkTitle: "Move a robot arm"
weight: 70
type: "docs"
tags: ["arm", "components"]
images: ["/how-tos/move_to_position.gif"]
videos: ["/how-tos/move_to_position.webm", "/how-tos/move_to_position.mp4"]
description: "Connect to a robotic arm and control it with the arm API."
aliases:
- /tutorials/motion/accessing-and-moving-robot-arm
- /tutorials/motion/
languages: ["Python", "Go"]
viamresources: ["arm"]
platformarea: ["mobility"]
level: "Intermediate"
date: "2024-10-31"
# updated: "" # When the tutorial was last entirely checked
cost: "8400"
---

In this guide you'll use Viam's Python or Go SDK to get the current position of your robot arm and issue movement commands.

{{< alert title="In this page" color="tip" >}}

1. [Access the arm](#access-the-arm)
1. [Move the arm](#move-the-arm)

{{< /alert >}}

## Requirements

You need the following hardware to complete this tutorial:

- A single-board computer or other computer to run `viam-server`.
- A Linux, macOS or Windows computer that can run SDK code.
- A [robotic arm](/components/arm/).

## Access the arm

{{< table >}}
{{% tablestep link="/configure/" %}}
**1. Configure a machine with an arm**

{{% snippet "setup.md" %}}

Add an arm component.
Select a model that supports your arm. Refer to the [documentation for the model](/components/arm/#configuration) for information about your arm's configuration attributes.

{{<imgproc src="/how-tos/access-arm/config.png" resize="500x" class="fill aligncenter" style="width: 400px" declaredimensions=true alt="Configuration builder UI with a blank arm component">}}
Save your config.

{{% /tablestep %}}
{{% tablestep link="/appendix/apis/components/arm/#getendposition" %}}
**2. Get the position of the end effector**

One way to describe the state of a robot arm is with the position of the end effector, or the "tool" or "hand" of the arm.
The code to get this information is a part of the autogenerated code sample the Viam app provides for your machine.
Go to the **Code sample** page of the **CONNECT** tab and select either Python or Go.

{{% snippet "show-secret.md" %}}

Then, copy and paste the sample code into a file and run the resulting script to see the resources available on your screen and the position of the end effector output as a [`Pose`](/internals/orientation-vector/).
For more information, see [`GetEndPosition`](/appendix/apis/components/arm/#getendposition).

{{% /tablestep %}}
{{% tablestep %}}
**3. Get the joint positions**

The state of a robot arm can also be described as the list of positions of each joint attached to the arm.
To get that information, add the following code right after the code that gets the end effector pose from the prior code sample:

{{< tabs >}}
{{% tab name="Python" %}}

```python
# Joint Positions of arm1
my_arm_joint_positions = await arm_1.get_joint_positions()
print(f"myArm get_joint_positions return value: {my_arm_joint_positions}")
```

{{% /tab %}}
{{% tab name="Go" %}}

```go
// Joint Positions of arm1
myArmJointPositions, err := arm1.JointPositions(context.Background(), nil)
if err != nil {
logger.Error(err)
return
}
logger.Infof("myArm JointPositions return value:", myArmJointPositions)
```

{{% /tab %}}
{{< /tabs >}}

Run your code again.
Each individual value corresponds to the current position of a particular joint on your robot.
You can also see these values reflected on the **CONTROL** tab in the Viam app for your robot arm.

{{% /tablestep %}}
{{< /table >}}

## Move the arm

The two main options for controlling arm movement 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.

{{< alert title="Caution" color="caution" >}}
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.
{{< /alert >}}

{{< table >}}
{{% tablestep %}}
**1. Initiate motion with a joint position command**

{{< tabs >}}
{{% tab name="Python" %}}
Add the following line to your import list to be able to assign values to a `JointPositions` data structure:

```python
from viam.proto.component.arm import JointPositions
```

Add the following code to your script:

```python
# 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)
```

{{% /tab %}}
{{% tab name="Go" link="/appendix/apis/components/arm/#movetojointpositions" %}}
Add `armapi "go.viam.com/api/component/arm/v1"` to your import list.
Add the following code to your script:

```go
// 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
}
```

{{% /tab %}}
{{< /tabs >}}

{{<gif webm_src="/how-tos/joint_positions.webm" mp4_src="/how-tos/joint_positions.mp4" alt="The robot arm moving through joint position commands" max-width="200px" class="alignleft">}}

Run the code.
The third joint of your arm should move 30 degrees.
For more information, see [`MoveToJointPositions`](/appendix/apis/components/arm/#movetojointpositions).

{{% /tablestep %}}
{{% tablestep link="/appendix/apis/components/arm/#movetoposition" %}}
**2. Command to move to position**

{{< tabs >}}
{{% tab name="Python" %}}

Add the following code to your script:

```python
# 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)
```

{{% /tab %}}
{{% tab name="Go" %}}
Add `"go.viam.com/rdk/spatialmath"` to your import list.

Add the following code to your script:

```go
// 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
}
```

{{% /tab %}}
{{< /tabs >}}

{{<gif webm_src="/how-tos/move_to_position.webm" mp4_src="/how-tos/move_to_position.mp4" alt="A robot arm moving to a commanded position" max-width="200px" class="alignright">}}

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`](/internals/orientation-vector/) when commanding arm motion.
Run the code to see your arm move 100 mm upwards.
For more information, see [`MoveToPosition`](/appendix/apis/components/arm/#movetoposition).

{{% /tablestep %}}
{{< /table >}}

## Next steps

{{< cards >}}
{{% card link="/tutorials/services/plan-motion-with-arm-gripper" %}}
{{% card link="/tutorials/projects/claw-game/" %}}
{{< /cards >}}

For more resources on robot kinematics, read through the Wikipedia pages for [Forward kinematics](https://en.wikipedia.org/wiki/Forward_kinematics) and [Inverse kinematics](https://en.wikipedia.org/wiki/Inverse_kinematics).
2 changes: 1 addition & 1 deletion docs/services/motion/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,6 @@ The `plan_deviation_m` for `MoveOnMap()` on calls issued from the **CONTROL** ta
The following tutorials contain complete example code for interacting with a robot arm through the arm component API, and with the motion service API, respectively:

{{< cards >}}
{{% card link="/tutorials/services/accessing-and-moving-robot-arm" %}}
{{% card link="/how-tos/move-robot-arm/" %}}
{{% card link="/tutorials/services/plan-motion-with-arm-gripper" %}}
{{< /cards >}}
Loading

0 comments on commit 6927777

Please sign in to comment.