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.
Configuration
For configuration information, click on your gripper’s model:
Model | Description |
---|---|
softrobotics | The mGrip soft gripper by Soft Robotics |
fake | A model used for testing, with no physical hardware. |
If you have another gripper model, you can define a custom component.
Control your gripper with Viam’s client SDK libraries
To get started using Viam’s SDKs to connect to and control your robot, go to your robot’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 robot as a client. Then control your robot 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 robot.
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
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. |
DoCommand | Send or receive model-specific commands. |
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)
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.
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 there is anything we could be doing better, please create an issue.
We're sorry about that. If you'd like to talk to us for help, please join the Community Discord. To ensure we know what's wrong with this page, you can also open an issue.