Skip to content

Commit e0a519b

Browse files
committed
Bring dummy perception nodes up-to-date
1 parent b65a9ef commit e0a519b

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

feeding_web_app_ros2_test/feeding_web_app_ros2_test/SegmentFromPoint.py

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env python3
2+
import array
23
from ada_feeding_msgs.action import SegmentFromPoint
34
from ada_feeding_msgs.msg import Mask
45
import cv2
@@ -15,6 +16,16 @@
1516
import time
1617

1718

19+
# The fixed header that ROS2 Humble's compressed depth image transport plugin prepends to
20+
# the data. The exact value was empirically determined, but the below link shows the code
21+
# that prepends additional data:
22+
#
23+
# https://github.com/ros-perception/image_transport_plugins/blob/5ef79d74c4347e6a2d151df63230d5fea1357137/compressed_depth_image_transport/src/codec.cpp#L337
24+
_COMPRESSED_DEPTH_16UC1_HEADER = array.array(
25+
"B", [0, 0, 0, 0, 46, 32, 133, 4, 192, 24, 60, 78]
26+
)
27+
28+
1829
class SegmentFromPointNode(Node):
1930
def __init__(self, sleep_time=2.0, send_feedback_hz=10):
2031
"""
@@ -44,8 +55,8 @@ def __init__(self, sleep_time=2.0, send_feedback_hz=10):
4455

4556
# Subscribe to the depth topic, to store the latest image
4657
self.depth_subscriber = self.create_subscription(
47-
Image,
48-
"/camera/aligned_depth_to_color/image_raw",
58+
CompressedImage,
59+
"/camera/aligned_depth_to_color/image_raw/compressedDepth",
4960
self.depth_callback,
5061
1,
5162
)
@@ -125,7 +136,9 @@ def goal_callback(self, goal_request):
125136

126137
# Reject if there is already an active goal
127138
if self.active_goal_request is not None:
128-
self.get_logger().info("Rejecting goal request")
139+
self.get_logger().info(
140+
"Rejecting goal request because there is already an active goal"
141+
)
129142
return GoalResponse.REJECT
130143

131144
# Reject if this node has not received an RGB and depth image
@@ -137,8 +150,11 @@ def goal_callback(self, goal_request):
137150
or self.latest_depth_msg is None
138151
or self.camera_info is None
139152
):
140-
self.get_logger().info("Rejecting cancel request")
141-
return CancelResponse.REJECT
153+
self.get_logger().info(
154+
"Rejecting goal request because RGB and depth images "
155+
"have not been received"
156+
)
157+
return GoalResponse.REJECT
142158

143159
# Otherwise accept
144160
self.get_logger().info("Accepting goal request")
@@ -183,7 +199,12 @@ def segment_image(self, seed_point, result, segmentation_success):
183199
result.camera_info = camera_info
184200
img = self.bridge.compressed_imgmsg_to_cv2(latest_img_msg, "bgr8")
185201
width, height, _ = img.shape
186-
depth_img = self.bridge.imgmsg_to_cv2(latest_depth_msg, "passthrough")
202+
depth_img = cv2.imdecode(
203+
np.frombuffer(
204+
latest_depth_msg.data[len(_COMPRESSED_DEPTH_16UC1_HEADER) :], np.uint8
205+
),
206+
cv2.IMREAD_UNCHANGED,
207+
)
187208

188209
# Sleep (dummy segmentation)
189210
time.sleep(self.sleep_time)

feeding_web_app_ros2_test/feeding_web_app_ros2_test/TableDetection.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ class TableDetectionNode(Node):
1616
frame_id="root",
1717
),
1818
# NOTE: This pose should be the same as the default pose in
19-
# `ada_planning_scene.yaml`
19+
# `ada_planning_scene.yaml` plus the `table_detection_offsets` in the
20+
# same file.
2021
pose=Pose(
21-
position=Point(x=0.08, y=-0.5, z=-0.48),
22+
position=Point(x=0.08 + 0.2, y=-0.5 + 0.25, z=-0.56 + 0.735),
2223
orientation=Quaternion(x=0.0, y=0.0, z=0.0, w=1.0),
2324
),
2425
)

0 commit comments

Comments
 (0)