Skip to main content

Grasp Planner Service

The Grasp Planner Service provides grasp planning capabilities.

Skill development

To access grasp planning capabilities, a skill can depend on a Grasp Planner Service in its implementation.

Declare dependency

In the skill's manifest, add to existing dependencies or create a new dependencies value. For more detailed information on skill manifest, check out Interact with a service

Add a new required_equipment key value pair to existing dependencies map or create a new dependencies map value if there isn't one:

dependencies {
required_equipment {
key: "grasp_planner_service"
value {
capability_names: "intrinsic_proto.grasping.service.grasp_planner_service.v1.GraspPlannerService"
}
}
}

Initialize Grasp Planner Client in skill execute

To initialize a client of the Grasp Planner Service, use the following code snippet in skill's implementation. For more detailed information on skill interacting with a service, check out Interact with a service.

from intrinsic.manipulation.service import grasp_planner_service_pb2_grpc
from intrinsic.manipulation.planning import grasp_planner_client

def make_grpc_stub(resource_handle):
"""Helper function to connect to grasp planning service."""
logging.info(f"Address: {resource_handle.connection_info.grpc.address}")
logging.info(f"Server Instance: {resource_handle.connection_info.grpc.server_instance}")
logging.info(f"Header: {resource_handle.connection_info.grpc.header}")

# Create a gRPC channel without using TLS.
grpc_info = resource_handle.connection_info.grpc
grpc_channel = grpc.insecure_channel(grpc_info.address)
connection_params = connection.ConnectionParams(
grpc_info.address, grpc_info.server_instance, grpc_info.header
)

intercepted_channel = grpc.intercept_channel(
grpc_channel,
interceptor.HeaderAdderInterceptor(connection_params.headers),
)
return intercepted_channel, grasp_planner_service_pb2_grpc.GraspPlannerServiceStub(intercepted_channel)

@overrides(skill_interface.Skill)
def execute(
self, request, context,
):
"""A skill's execute implementation connecting to grasp planner service."""

# Same as the key for the grasp planner service dependnecy in the skill's manifest.
GRASP_PLANNER_SERVICE_KEY = "grasp_planner_service"
grasp_planner_service_handle = context.resource_handles[GRASP_PLANNER_SERVICE_KEY]
channel, grasp_planner_service_stub = make_grpc_stub(grasp_planner_service_handle)
gps_client = grasp_planner_client.GraspPlannerClient(grasp_planner_service_stub)

# Use gps_client for grasp planning ...

channel.close()

Grasp Planning Capabilities

The grasp planner serivce provides a gRPC interface that contains two main rpcs:

Use PlanGrasps

PlanGrasps plans a list of grasps using the specified targets, e.g. all objects with "my_product" as the product part name:

@overrides(skill_interface.Skill)
def execute(
self,
request,
context,
):
"""A skill's execute implementation planning a list of grasps to all objects with `"my_product"` as the product part name.
"""
channel, grasp_planner_service_stub = make_grpc_stub(grasp_planner_service_handle)
gps_client = grasp_planner_client.GraspPlannerClient(grasp_planner_service_stub)
grasp_plan = gps_client.plan_grasps(
planner_id="my_planner",
plan_grasps_params=grasp_planner_service_pb2.GPSPlanGraspsParams(
world_id="world",
grasp_targets=[grasp_pb2.GraspTarget(object_category="my_product")],
start_robot_joint_positions=request.start_robot_joint_positions,
),
)
channel.close()

plan_grasps also provides this capability as a skill. Please see plan grasps reference manual and plan grasps guide for more details.

Use RankGrasps

RankGrasps ranks a list of given grasps using the specified grasp rankers, e.g. with a IkCollisionChecker and a TopDownGraspRanker:

@overrides(skill_interface.Skill)
def execute(
self,
request,
context,
):
"""A skill's execute implementation ranking a list of given grasps with a `IkCollisionChecker` and a `TopDownGraspRanker`.
"""
channel, grasp_planner_service_stub = make_grpc_stub(grasp_planner_service_handle)
gps_client = grasp_planner_client.GraspPlannerClient(grasp_planner_service_stub)
grasp_plan = gps_client.rank_grasps(
grasps=request.params.grasps_to_rank,
robot_name=request.params.robot_name,
tool_frame=request.params.tool_frame,
rankers_params=grasp_ranker_params_pb2.GraspRankersParams(
visibility_ranker_params=grasp_ranker_params_pb2.VisibilityRankerParams(
visibility_threshold=0.2,
),
ik_collision_checker_params=grasp_ranker_params_pb2.IkCollisionCheckerParams(
eoat_name=request.params.eoat_name,
require_same_branch_ik=False,
check_collision_at_grasp_pose=True,
),
),
world_id=context.object_world.world_id,
score_threshold=1.0,
)
channel.close()