Skip to content

Commit fe123cc

Browse files
committed
feat: GetGrippingPointTool
1 parent cf2e36d commit fe123cc

File tree

3 files changed

+86
-0
lines changed

3 files changed

+86
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright (C) 2025 Robotec.AI
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from .tools import (
16+
GetGrippingPointTool,
17+
)
18+
19+
__all__ = [
20+
"GetGrippingPointTool",
21+
]
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Copyright (C) 2025 Robotec.AI
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from typing import Type
16+
17+
from pydantic import BaseModel, Field
18+
19+
from rai.tools.ros2.base import BaseROS2Tool
20+
from rai.tools.ros2.detection.pcl import (
21+
GrippingPointEstimator,
22+
PointCloudFilter,
23+
PointCloudFromSegmentation,
24+
)
25+
26+
27+
class GetGrippingPointToolInput(BaseModel):
28+
object_name: str = Field(
29+
...,
30+
description="The name of the object to get the gripping point of e.g. 'box', 'apple', 'screwdriver'",
31+
)
32+
33+
34+
# TODO(maciejmajek): Configuration system configurable with namespacing
35+
class GetGrippingPointTool(BaseROS2Tool):
36+
name: str = "get_gripping_point"
37+
description: str = "Get gripping points for specified object/objects. Returns 3D coordinates where a robot gripper can grasp the object."
38+
39+
point_cloud_from_segmentation: PointCloudFromSegmentation
40+
gripping_point_estimator: GrippingPointEstimator
41+
point_cloud_filter: PointCloudFilter
42+
43+
args_schema: Type[GetGrippingPointToolInput] = GetGrippingPointToolInput
44+
45+
def _run(self, object_name: str) -> str:
46+
pcl = self.point_cloud_from_segmentation.run(object_name)
47+
pcl = self.point_cloud_filter.run(pcl)
48+
gps = self.gripping_point_estimator.run(pcl)
49+
50+
message = ""
51+
if len(gps) == 0:
52+
message += f"No gripping point found for the object {object_name}\n"
53+
elif len(gps) == 1:
54+
message += f"The gripping point of the object {object_name} is {gps[0]}\n"
55+
else:
56+
message += f"Multiple gripping points found for the object {object_name}\n"
57+
58+
for i, gp in enumerate(gps):
59+
message += (
60+
f"The gripping point of the object {i + 1} {object_name} is {gp}\n"
61+
)
62+
63+
return message

src/rai_core/rai/tools/ros2/manipulation/custom.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from typing import Literal, Type
1717

1818
import numpy as np
19+
from deprecated import deprecated
1920
from geometry_msgs.msg import Point, Pose, PoseStamped, Quaternion
2021
from pydantic import BaseModel, Field
2122
from tf2_geometry_msgs import do_transform_pose
@@ -259,6 +260,7 @@ class GetObjectPositionsToolInput(BaseModel):
259260
)
260261

261262

263+
@deprecated("Use GetGrippingPointTool from rai.tools.ros2.detection instead")
262264
class GetObjectPositionsTool(BaseROS2Tool):
263265
name: str = "get_object_positions"
264266
description: str = (

0 commit comments

Comments
 (0)