Skip to content

Commit 7ef3b41

Browse files
MoveToGrasp now works. The static transform was causing joints to not be broadcast correctly, making transform lookups fail in MoveToGrasp - this has been replaced with a wait_for_transform call to a tf buffer. A U16C1 (unsigned int, 1 channel) compressed depth map in millimeters is now published on the depth/compressed topics.
1 parent 6680bd9 commit 7ef3b41

File tree

2 files changed

+56
-29
lines changed

2 files changed

+56
-29
lines changed

stretch_simulation/launch/stretch_simulation_web_interface.launch.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ def generate_launch_description():
4141
)
4242
],
4343
)
44-
map_yaml = DeclareLaunchArgument(
45-
"map_yaml", description="filepath to previously captured map", default_value=""
44+
map = DeclareLaunchArgument(
45+
"map", description="filepath to previously captured map", default_value=""
4646
)
4747
tts_engine = DeclareLaunchArgument(
4848
"tts_engine",
@@ -62,7 +62,7 @@ def generate_launch_description():
6262
# Start collecting nodes to launch
6363
ld = LaunchDescription(
6464
[
65-
map_yaml,
65+
map,
6666
tts_engine,
6767
nav2_params_file_param,
6868
params_file,
@@ -129,11 +129,12 @@ def generate_launch_description():
129129
"use_sim_time": True
130130
}
131131
],
132+
remappings=[("/gripper_camera/color/camera_info","/gripper_camera/camera_info")]
132133
)
133134
ld.add_action(configure_video_streams_node)
134135

135136
navigation_bringup_launch = GroupAction(
136-
condition=LaunchConfigurationNotEquals("map_yaml", ""),
137+
condition=LaunchConfigurationNotEquals("map", ""),
137138
actions=[
138139
IncludeLaunchDescription(
139140
PythonLaunchDescriptionSource(
@@ -142,13 +143,7 @@ def generate_launch_description():
142143
launch_arguments={
143144
"use_sim_time": "true",
144145
"autostart": "true",
145-
"map": PathJoinSubstitution(
146-
[
147-
teleop_interface_package,
148-
"maps",
149-
LaunchConfiguration("map_yaml"),
150-
]
151-
),
146+
"map": LaunchConfiguration("map"),
152147
"params_file": LaunchConfiguration("nav2_params_file"),
153148
"use_rviz": "false",
154149
}.items(),
@@ -208,7 +203,12 @@ def generate_launch_description():
208203
executable="move_to_pregrasp.py",
209204
output="screen",
210205
arguments=[LaunchConfiguration("params")],
211-
parameters=[],
206+
parameters=[{
207+
"use_sim_time": True}],
208+
remappings=[
209+
("/camera/aligned_depth_to_color/camera_info", "/camera/depth/camera_info"),
210+
("/camera/aligned_depth_to_color/image_raw/compressedDepth", "/camera/depth/image_rect_raw/compressed")
211+
]
212212
)
213213
ld.add_action(move_to_pregrasp_node)
214214

stretch_simulation/stretch_mujoco_driver/stretch_mujoco_driver.py

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#! /usr/bin/env python3
22

3+
import array
34
import copy
45
from functools import cache
6+
import cv2
57
import numpy as np
68
import threading
79

@@ -691,13 +693,14 @@ def publish_camera_and_lidar(self, current_time: TimeMsg | None = None):
691693
)
692694
self.camera_info_publishers[camera.name].publish(camera_info)
693695

694-
if not camera.is_depth:
696+
if camera.is_depth:
697+
ros_image_compressed = compress_depth_image(frame)
698+
else:
695699
ros_image_compressed: CompressedImage = (
696-
self.bridge.cv2_to_compressed_imgmsg(frame)
697-
)
698-
self.camera_compressed_publishers[camera.name].publish(
699-
ros_image_compressed
700+
self.bridge.cv2_to_compressed_imgmsg(frame, "png")
700701
)
702+
ros_image_compressed.header.frame_id = get_camera_frame(camera)
703+
self.camera_compressed_publishers[camera.name].publish(ros_image_compressed)
701704

702705
if camera.is_depth:
703706
if camera == StretchCameras.cam_d405_depth:
@@ -903,7 +906,7 @@ def get_joint_states_callback(self, request, response):
903906
min_limit, max_limit = min_max
904907
if actuator == Actuators.arm:
905908
joint_name = "joint_arm" # Instead of the telescoping names
906-
max_limit *= 4 # 4x the telescoping limit
909+
max_limit *= 4 # 4x the telescoping limit
907910
if actuator == Actuators.gripper:
908911
joint_name = "gripper_aperture" # A different mapping from stretch_core command_groups
909912
if actuator in [
@@ -987,6 +990,7 @@ def stow_the_robot(self):
987990

988991
def is_runstopped(self):
989992
return self.robot_mode == "runstopped"
993+
990994
def runstop_the_robot(self, runstopped, just_change_mode=False):
991995
if runstopped:
992996
self.robot_mode_rwlock.acquire_read()
@@ -1054,7 +1058,6 @@ def ros_setup(self):
10541058
"controller_calibration_file",
10551059
str(stretch_core_path / "config" / "controller_calibration_head.yaml"),
10561060
)
1057-
10581061
# large_ang = np.radians(45.0)
10591062
# filename = self.get_parameter('controller_calibration_file').value
10601063
# self.get_logger().debug('Loading controller calibration parameters for the head from YAML file named {0}'.format(filename))
@@ -1113,14 +1116,16 @@ def ros_setup(self):
11131116

11141117
self.odom_pub = self.create_publisher(Odometry, "odom", 1)
11151118
self.laser_scan_pub = self.create_publisher(
1116-
LaserScan, "/scan_filtered", qos_profile=QoSProfile(
1117-
depth=1, reliability=ReliabilityPolicy.BEST_EFFORT
1118-
)
1119+
LaserScan,
1120+
"/scan_filtered",
1121+
qos_profile=QoSProfile(depth=1, reliability=ReliabilityPolicy.BEST_EFFORT),
11191122
)
11201123

11211124
self.camera_publishers = {
11221125
camera.name: self.create_publisher(
1123-
Image, get_camera_topic_name(camera), qos_profile=QoSProfile(
1126+
Image,
1127+
get_camera_topic_name(camera),
1128+
qos_profile=QoSProfile(
11241129
depth=1, reliability=ReliabilityPolicy.BEST_EFFORT
11251130
),
11261131
)
@@ -1135,11 +1140,11 @@ def ros_setup(self):
11351140
),
11361141
)
11371142
for camera in self.sim._cameras_to_use
1138-
if not camera.is_depth
11391143
}
11401144
self.pointcloud_publishers = {
11411145
camera.name: self.create_publisher(
1142-
PointCloud2, get_camera_pointcloud_topic_name(camera),
1146+
PointCloud2,
1147+
get_camera_pointcloud_topic_name(camera),
11431148
qos_profile=QoSProfile(
11441149
depth=1, reliability=ReliabilityPolicy.BEST_EFFORT
11451150
),
@@ -1149,14 +1154,15 @@ def ros_setup(self):
11491154
}
11501155
self.camera_info_publishers = {
11511156
camera.name: self.create_publisher(
1152-
CameraInfo, get_camera_info_topic_name(camera),
1157+
CameraInfo,
1158+
get_camera_info_topic_name(camera),
11531159
qos_profile=QoSProfile(
11541160
depth=1, reliability=ReliabilityPolicy.BEST_EFFORT
11551161
),
11561162
)
11571163
for camera in self.sim._cameras_to_use
11581164
}
1159-
1165+
11601166
self.clock_pub = self.create_publisher(
11611167
msg_type=Clock, topic="/clock", qos_profile=5
11621168
)
@@ -1463,8 +1469,28 @@ def create_pointcloud_rgb_msg(
14631469
return cloud_msg
14641470

14651471

1472+
__COMPRESSED_DEPTH_16UC1_HEADER = array.array("B", [0] * 12)
1473+
1474+
1475+
def compress_depth_image(frame: np.ndarray):
1476+
"""
1477+
Converts a F32 depth map in meters to a U16 map in millimeters
1478+
"""
1479+
normalized_array = (frame * 1000).astype(np.uint16)
1480+
1481+
_, encoded_image = cv2.imencode(".png", normalized_array)
1482+
1483+
ros_image_compressed = CompressedImage()
1484+
ros_image_compressed.format = "16uc1; compressedDepth"
1485+
ros_image_compressed.data = __COMPRESSED_DEPTH_16UC1_HEADER + array.array(
1486+
"B", encoded_image.tobytes()
1487+
)
1488+
1489+
return ros_image_compressed
1490+
1491+
14661492
def create_camera_info(
1467-
camera_settings:CameraSettings, frame_id: str, timestamp: TimeMsg
1493+
camera_settings: CameraSettings, frame_id: str, timestamp: TimeMsg
14681494
):
14691495
camera_info_msg = CameraInfo()
14701496
camera_info_msg.header = Header()
@@ -1474,7 +1500,6 @@ def create_camera_info(
14741500
camera_info_msg.height = camera_settings.height
14751501
camera_info_msg.distortion_model = "plumb_bob"
14761502

1477-
14781503
camera_info_msg.d = camera_settings.get_distortion_params_d()
14791504
camera_info_msg.k = camera_settings.get_intrinsic_params_k()
14801505
camera_info_msg.p = camera_settings.get_projection_matrix_p()
@@ -1506,6 +1531,7 @@ def get_camera_topic_name(camera: StretchCameras):
15061531

15071532
raise NotImplementedError(f"Camera {camera} topic mapping is not implemented")
15081533

1534+
15091535
@cache
15101536
def get_camera_info_topic_name(camera: StretchCameras):
15111537
"""
@@ -1524,6 +1550,7 @@ def get_camera_info_topic_name(camera: StretchCameras):
15241550

15251551
raise NotImplementedError(f"Camera {camera} topic mapping is not implemented")
15261552

1553+
15271554
@cache
15281555
def get_camera_pointcloud_topic_name(camera: StretchCameras):
15291556
"""

0 commit comments

Comments
 (0)