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.
Related services
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:
Model | Description |
---|---|
softrobotics | The _m_Grip soft gripper by Soft Robotics |
fake | A 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:
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.
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.
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 Code sample tab. You can also see your API key and API key ID on your machine’s Security tab.
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 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 Name | Description |
---|---|
Open | Open the gripper. |
Grab | Close the gripper until it grabs something or closes completely. |
Stop | Stop the gripper’s movement. |
IsMoving | Report whether the gripper is currently moving. |
GetGeometries | Get all the geometries associated with the gripper in its current configuration, in the frame of the gripper. |
DoCommand | Send or receive model-specific commands. |
Close | Safely 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:
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:
- (List[Geometry]): The geometries associated with the gripper, in any order.
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:
[]spatialmath.Geometry
: The geometries associated with the gripper, in any order.- (error): An error, if one occurred.
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:
command
(Dict[str, Any]): The command to execute.
Returns:
- (Dict[str, Any]): Result of the executed command.
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:
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.
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
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!