Control your gripper with the gripper API
The gripper API allows you to give commands to your gripper components for opening and closing a device.
The gripper component supports the following methods:
Method Name | Description |
---|---|
Open | Opens the gripper. |
Grab | Closes the gripper until it grabs something or closes completely, and returns whether it grabbed something or not. |
IsMoving | Returns whether the gripper is actively moving (or attempting to move) under its own power. |
Stop | Stops the gripper. |
GetGeometries | Get all the geometries associated with the gripper in its current configuration, in the frame of the gripper. |
Reconfigure | Reconfigure this resource. |
DoCommand | Execute model-specific commands that are not otherwise defined by the component API. |
GetResourceName | Get the ResourceName for this gripper with the given name. |
Close | Safely shut down the resource and prevent further use. |
Establish a connection
To get started using Viam’s SDKs to connect to and control your gripper and the rest of 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.
To show your machine’s API key in the sample code, toggle Include API key.
Caution: Keep your API key and machine address safe
We strongly recommend that you add your API key and machine address as an environment variable. Anyone with these secrets can access your machine, and the computer running your machine.
When executed, this sample code creates a connection to your machine as a client.
The following 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.
Import the gripper package for the SDK you are using:
from viam.components.gripper import Gripper
import (
"go.viam.com/rdk/components/gripper"
)
API
Open
Opens the gripper.
Parameters:
extra
(Mapping[str, Any]) (optional): Extra options to pass to the underlying RPC call.timeout
(float) (optional): An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call.
Returns:
- None.
Example:
my_gripper = Gripper.from_robot(robot=machine, name="my_gripper")
# Open the gripper.
await my_gripper.open()
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.extra
(map[string]interface{}): Extra options to pass to the underlying RPC call.
Returns:
- (error): An error, if one occurred.
Example:
myGripper, err := gripper.FromRobot(machine, "my_gripper")
// Open the gripper.
err := myGripper.Open(context.Background(), nil)
For more information, see the Go SDK Docs.
Parameters:
Returns:
- Future<void>
Example:
await myGripper.open();
For more information, see the Flutter SDK Docs.
Grab
Closes the gripper until it grabs something or closes completely, and returns whether it grabbed something or not.
Parameters:
extra
(Mapping[str, Any]) (optional): Extra options to pass to the underlying RPC call.timeout
(float) (optional): An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call.
Returns:
- (bool): Indicates if the gripper grabbed something.
Example:
my_gripper = Gripper.from_robot(robot=machine, name="my_gripper")
# Grab with the gripper.
grabbed = await my_gripper.grab()
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.extra
(map[string]interface{}): Extra options to pass to the underlying RPC call.
Returns:
- (bool): True if the gripper grabbed something with non-zero thickness.
- (error): An error, if one occurred.
Example:
myGripper, err := gripper.FromRobot(machine, "my_gripper")
// Grab with the gripper.
grabbed, err := myGripper.Grab(context.Background(), nil)
For more information, see the Go SDK Docs.
Parameters:
Returns:
- Future<void>
Example:
await myGripper.grab();
For more information, see the Flutter SDK Docs.
IsMoving
Returns whether the gripper is actively moving (or attempting to move) under its own power.
Parameters:
timeout
(float) (optional): An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call.
Returns:
- (bool): Whether the gripper is moving.
Example:
my_gripper = Gripper.from_robot(robot=machine, name="my_gripper")
# Check whether the gripper is currently moving.
moving = await my_gripper.is_moving()
print('Moving:', moving)
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:
Example:
// This example shows using IsMoving with an arm component.
myArm, err := arm.FromRobot(machine, "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)
For more information, see the Go SDK Docs.
Parameters:
- None.
Returns:
Example:
var isItMoving = await myGripper.isMoving();
For more information, see the Flutter SDK Docs.
Stop
Stops the gripper.
It is assumed that the gripper stops immediately, so IsMoving
will return false after calling Stop
.
Parameters:
extra
(Mapping[str, Any]) (optional): Extra options to pass to the underlying RPC call.timeout
(float) (optional): An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call.
Returns:
- None.
Example:
my_gripper = Gripper.from_robot(robot=machine, name="my_gripper")
# Stop the gripper.
await my_gripper.stop()
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.extra
(map[string]interface{}): Extra options to pass to the underlying RPC call.
Returns:
- (error): An error, if one occurred.
Example:
// This example shows using Stop with an arm component.
myArm, err := arm.FromRobot(machine, "my_arm")
// Stop all motion of the arm. It is assumed that the arm stops immediately.
err = myArm.Stop(context.Background(), nil)
For more information, see the Go SDK Docs.
Parameters:
Returns:
- Future<void>
Example:
await myGripper.stop();
For more information, see the Flutter SDK Docs.
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
(Mapping[str, Any]) (optional): Extra options to pass to the underlying RPC call.timeout
(float) (optional): An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call.
Returns:
- (List[viam.proto.common.Geometry]): The geometries associated with the Component.
Example:
my_gripper = Gripper.from_robot(robot=machine, 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}")
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.extra
(map[string]interface{}): Extra options to pass to the underlying RPC call.
Returns:
- ([]spatialmath.Geometry): The geometries associated with this resource, in any order.
- (error): An error, if one occurred.
Example:
// This example shows using Geometries with an gripper component.
myGripper, err := gripper.FromRobot(machine, "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.Pose())
}
For more information, see the Go SDK Docs.
Reconfigure
Reconfigure this resource. Reconfigure must reconfigure the resource atomically and in place.
Parameters:
ctx
(Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.deps
(Dependencies): The resource dependencies.conf
(Config): The resource configuration.
Returns:
- (error): An error, if one occurred.
For more information, see the Go SDK Docs.
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
.
GetResourceName
Get the ResourceName
for this gripper with the given name.
Parameters:
name
(str) (required): The name of the Resource.
Returns:
- (viam.proto.common.ResourceName): The ResourceName of this Resource.
Example:
my_gripper_name = Gripper.get_resource_name("my_gripper")
For more information, see the Python SDK Docs.
Close
Safely shut down the resource and prevent further use.
Parameters:
- None.
Returns:
- None.
Example:
my_gripper = Gripper.from_robot(robot=machine, name="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.
Example:
myGripper, err := gripper.FromRobot(machine, "my_gripper")
err = myGripper.Close(context.Background())
For more information, see the Go SDK Docs.
Have questions, or want to meet other people working on robots? Join our Community Discord.
If you notice any issues with the documentation, feel free to file an issue or edit this file.
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!