Gripper Component

A gripper is a robotic grasping device that can open and close, often attached to the end of an arm or to a gantry.

Supported models

To use your gripper with Viam, check whether one of the following built-in models or modular resources supports your gripper.

Built-in models

For configuration information, click on the model name:

ModelDescription
softroboticsThe _m_Grip soft gripper by Soft Robotics
fakeA model used for testing, with no physical hardware.

Modular resources

Search for additional gripper models that you can add from the Viam Registry:

For configuration information, click on the model name:

Model
Description

Control your gripper 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 Code sample tab, select your preferred programming language, and copy the sample code generated.

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 a gripper called "my_gripper" configured as a component of your machine. If your gripper has a different name, change the name in the code.

Be sure to import the gripper package for the SDK you are using:

from viam.components.gripper import Gripper
import (
  "go.viam.com/rdk/components/gripper"
)

API

The gripper component supports the following methods:

Method NameDescription
OpenOpen the gripper.
GrabClose the gripper until it grabs something or closes completely.
StopStop the gripper’s movement.
IsMovingReport whether the gripper is currently moving.
GetGeometriesGet all the geometries associated with the gripper in its current configuration, in the frame of the gripper.
DoCommandSend or receive model-specific commands.
CloseSafely shut down the resource and prevent further use.

Open

Opens the gripper.

Parameters:

  • None

Returns:

  • None

For more information, see the Python SDK Docs.

my_gripper = Gripper.from_robot(robot=robot, name="my_gripper")

# Open the gripper.
await my_gripper.open()

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.

myGripper, err := gripper.FromRobot(robot, "my_gripper")

// Open the gripper.
err := myGripper.Open(context.Background(), nil)

Grab

Closes the gripper until it grabs something or closes completely, and returns whether it grabbed something or not.

Parameters:

  • None

Returns:

  • (bool): Whether or not the gripper grabbed something.

For more information, see the Python SDK Docs.

my_gripper = Gripper.from_robot(robot=robot, name="my_gripper")

# Grab with the gripper.
grabbed = await my_gripper.grab()

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:

  • (bool): True if the gripper grabbed something with nonzero thickness.
  • (error): An error, if one occurred.

For more information, see the Go SDK Docs.

myGripper, err := gripper.FromRobot(robot, "my_gripper")

// Grab with the gripper.
grabbed, err := myGripper.Grab(context.Background(), nil)

Stop

Stops the gripper. It is assumed that the gripper stops immediately, so IsMoving will return false after calling Stop.

Parameters:

  • None

Returns:

  • None

For more information, see the Python SDK Docs.

my_gripper = Gripper.from_robot(robot=robot, name="my_gripper")

# Stop the gripper.
await my_gripper.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.

myGripper, err := gripper.FromRobot(robot, "my_gripper")

// Stop the gripper.
err := myGripper.Stop(context.Background(), nil)

IsMoving

Returns whether the gripper is actively moving (or attempting to move) under its own power.

Parameters:

  • None

Returns:

  • (bool): True if the gripper is currently moving; false if not.

For more information, see the Python SDK Docs.

my_gripper = Gripper.from_robot(robot=robot, name="my_gripper")

# Check whether the gripper is currently moving.
moving = await my_gripper.is_moving()
print('Moving:', moving)

Parameters:

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

Returns:

  • (bool): If the gripper is currently moving.
  • (error): An error, if one occurred.

For more information, see the Go SDK Docs.

myGripper, err := gripper.FromRobot(robot, "my_gripper")

// Check whether the gripper is currently moving.
moving, err := myGripper.IsMoving(context.Background())
logger.Info("Is moving?")
logger.Info(moving)

GetGeometries

Get all the geometries associated with the gripper in its current configuration, in the frame of the gripper. 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:

For more information, see the Python SDK Docs.

my_gripper = Gripper.from_robot(robot=robot, name="my_gripper")

geometries = await my_gripper.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:

For more information, see the Go SDK Docs.

myGripper, err := gripper.FromRobot(robot, "my_gripper")

geometries, err := myGripper.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 gripper and add features that have no built-in API method, you can access them with DoCommand.

Parameters:

Returns:

my_gripper = Gripper.from_robot(robot=robot, name="my_gripper")

raw_dict = {
  "command": "raw",
  "raw_input": "home"
}
await my_gripper.do_command(raw_dict)

For more information, see the Python SDK Docs.

Parameters:

Returns:

myGripper, err := gripper.FromRobot(robot, "my_gripper")

resp, err := myGripper.DoCommand(ctx, map[string]interface{}{"command": "example"})

For more information, see the Go SDK Code.

Close

Safely shut down the resource and prevent further use.

Parameters:

  • None

Returns:

  • None
my_gripper = Gripper.from_robot(robot, "my_gripper")

await my_gripper.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.
myGripper, err := gripper.FromRobot(robot, "my_gripper")

err := myGripper.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 Viam Community Slack and we will be happy to help.

Next steps