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. |
IsHoldingSomething | Return if the gripper is holding something. |
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. |
GetKinematics | Get the kinematics information associated with the gripper as the format and byte contents of the kinematics file. |
GetResourceName | Get the ResourceName for this gripper. |
Close | Safely shut down the resource and prevent further use. |
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.FromProvider(machine, "my_gripper")
// Open the gripper.
err := myGripper.Open(context.Background(), nil)
For more information, see the Go SDK Docs.
Parameters:
extra(None) (optional)callOptions(CallOptions) (optional)
Returns:
- (Promise
)
Example:
const gripper = new VIAM.GripperClient(machine, 'my_gripper');
// Open the gripper
await gripper.open();
For more information, see the TypeScript 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.FromProvider(machine, "my_gripper")
// Grab with the gripper.
grabbed, err := myGripper.Grab(context.Background(), nil)
For more information, see the Go SDK Docs.
Parameters:
extra(None) (optional)callOptions(CallOptions) (optional)
Returns:
- (Promise
)
Example:
const gripper = new VIAM.GripperClient(machine, 'my_gripper');
// Close the gripper to grab
await gripper.grab();
For more information, see the TypeScript 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.FromProvider(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:
callOptions(CallOptions) (optional)
Returns:
- (Promise
)
Example:
const gripper = new VIAM.GripperClient(machine, 'my_gripper');
// Check if the gripper is currently moving
const moving = await gripper.isMoving();
console.log('Gripper is moving:', moving);
For more information, see the TypeScript SDK Docs.
Parameters:
- None.
Returns:
Example:
var isItMoving = await myGripper.isMoving();
For more information, see the Flutter SDK Docs.
IsHoldingSomething
Return if the gripper is holding something.
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:
- (viam.components.gripper.gripper.Gripper.HoldingStatus): : see documentation on HoldingStatus for more information.
Example:
my_gripper = Gripper.from_robot(robot=machine, name="my_gripper")
# Grab with the gripper.
holding_status = await my_gripper.is_holding_something()
# get the boolean result
is_holding_something = holding_status.is_holding_something
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:
- (HoldingStatus)
- (error): An error, if one occurred.
For more information, see the Go 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.FromProvider(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:
extra(None) (optional)callOptions(CallOptions) (optional)
Returns:
- (Promise
)
Example:
const gripper = new VIAM.GripperClient(machine, 'my_gripper');
// Stop the gripper's current motion
await gripper.stop();
For more information, see the TypeScript 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.FromProvider(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.
Parameters:
extra(None) (optional)callOptions(CallOptions) (optional)
Returns:
Example:
const gripper = new VIAM.GripperClient(machine, 'my_gripper');
// Get the geometries of this component
const geometries = await gripper.getGeometries();
console.log('Geometries:', geometries);
For more information, see the TypeScript 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.
Most models do not implement DoCommand.
Any available model-specific commands should be covered in the model’s documentation.
If you are implementing your own gripper and want to add features that have no corresponding built-in API method, you can implement them with DoCommand.
Parameters:
command(Mapping[str, ValueTypes]) (required): The command to execute.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:
- (Mapping[str, viam.utils.ValueTypes]): : Result of the executed command.
Raises:
- (NotImplementedError): Raised if the Resource does not support arbitrary commands.
Example:
my_gripper = Gripper.from_robot(robot=machine, name="my_gripper")
command = {"cmd": "test", "data1": 500}
result = await my_gripper.do_command(command)
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{}): The command response.
- (error): An error, if one occurred.
Example:
myGripper, err := gripper.FromProvider(machine, "my_gripper")
command := map[string]interface{}{"cmd": "test", "data1": 500}
result, err := myGripper.DoCommand(context.Background(), command)
For more information, see the Go SDK Docs.
Parameters:
command(Struct) (required): The command to execute. Accepts either a Struct or a plain object, which will be converted automatically.callOptions(CallOptions) (optional)
Returns:
- (Promise<JsonValue>)
Example:
// Plain object (recommended)
const result = await resource.doCommand({
myCommand: { key: 'value' },
});
// Struct (still supported)
import { Struct } from '@viamrobotics/sdk';
const result = await resource.doCommand(
Struct.fromJson({ myCommand: { key: 'value' } })
);
For more information, see the TypeScript SDK Docs.
GetKinematics
Get the kinematics information associated with the gripper as the format and byte contents of the kinematics file.
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:
- (viam.components.KinematicsReturn): : A tuple containing two values; the first [0] value represents the format of the
file, either in URDF format (
KinematicsFileFormat.KINEMATICS_FILE_FORMAT_URDF) or Viam’s kinematic parameter format (spatial vector algebra) (KinematicsFileFormat.KINEMATICS_FILE_FORMAT_SVA), and the second [1] value represents the byte contents of the file. If available, a third [2] value provides meshes keyed by URDF filepath.
Example:
my_gripper = Gripper.from_robot(robot=machine, name="my_gripper")
# Get the kinematics information associated with the gripper.
kinematics = await my_gripper.get_kinematics()
# Get the format of the kinematics file.
k_file = kinematics[0]
# Get the byte contents of the file.
k_bytes = kinematics[1]
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:
- (referenceframe.Model): The kinematics model of the resource.
- (error): An error, if one occurred.
For more information, see the Go SDK Docs.
Parameters:
Returns:
Example:
var kinematics = await myGripper.getKinematics();
For more information, see the Flutter SDK Docs.
GetResourceName
Get the ResourceName for this gripper.
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.
Parameters:
- None.
Returns:
Example:
myGripper, err := gripper.FromProvider(machine, "my_gripper")
err = myGripper.Name()
For more information, see the Go SDK Docs.
Parameters:
- None.
Returns:
- (string): The name of the resource.
Example:
gripper.name
For more information, see the TypeScript SDK Docs.
Parameters:
nameString (required)
Returns:
Example:
final myGripperResourceName = myGripper.getResourceName("my_gripper");
For more information, see the Flutter 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.FromProvider(machine, "my_gripper")
err = myGripper.Close(context.Background())
For more information, see the Go SDK Docs.
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!