Welcome to ROSMASTER A1 PRO repository
4.Depth Camera Distance Measurement (Depth Camera Only)
📏 Depth Camera Distance Measurement (Depth Camera Distance Measurement)
1. Course Content
Using the Angstrong Nuwa-HP60C 3D depth camera, obtain the 16-bit depth image stream (/ascamera_hp60c/camera_publisher/depth0/image_raw), render the depth data with pseudo-color on the screen and display the center point in real-time, and show the physical straight-line distance (in millimeters mm) of a mouse-clicked point in 3D space.
Important
This course is only applicable to users with the Angstrong Nuwa-HP60C Depth Camera version.
2. Preparation and Running
This case requires opening 2 terminals to start the camera driver and distance measurement node respectively:
2.1 Start Camera Low-level Driver
Run in Terminal 1:
xxxxxxxxxxros2 launch dofbot_pro_driver A1pro_camera_arm.launch.py
2.2 Start Depth Distance Measurement Node
Run the distance measurement application node in Terminal 2:
xxxxxxxxxxros2 run yahboomcar_depth get_center_disClick on the image to select a point to get the corresponding distance. You can control the robotic arm yourself if you want other arm angles.

3. Operation Flow and Interaction Description
After the node starts, it will automatically pop up the
depth_imagepseudo-color visualization window;By default, measure the depth distance of the center point (x=320, y=240) of the screen, and display
dist: xxx.x mmin real-time in the upper left corner of the image;Mouse Click Distance Measurement: Left-click any object area in the pop-up window, the black circle marker will automatically move to the clicked position, and the distance value in the upper left corner will immediately update to the real physical distance corresponding to that target pixel;
The terminal window will synchronously print the current click coordinates and depth measurement logs
Note
The effective measurement range of the depth camera is $200\text{mm} \sim 2500\text{mm}$ (0.2m~2.5m). If the target distance is less than 200mm (entering the measurement blind zone) or exceeds 2.5m, the measured value may be 0 or NaN.
4. Core Source Code Analysis
Source Code Path:
xxxxxxxxxx$HOME/yahboomcar_ros2_ws/yahboomcar_ws/src/yahboomcar_depth/yahboomcar_depth/Basic/get_center_dis.py
xclass GetDepthInfo(Node): def __init__(self): super().__init__('get_depth_info') # 1. Subscribe to Nuwa depth image topic (16UC1 millimeter unit encoding) self.sub = self.create_subscription( Image, '/ascamera_hp60c/camera_publisher/depth0/image_raw', self.topic_callback, 10) self.window_name = 'depth_image' self.y = 240 self.x = 320 self.depth_bridge = CvBridge() def click_callback(self, event, x, y, flags, params): # 2. Mouse left button click event capture if event == 1: self.x = x self.y = y self.get_logger().info(f'Clicked coordinates: x={self.x}, y={self.y}')
def topic_callback(self, msg): # 3. Convert ROS Image message to 32-bit floating point matrix depth_image = self.depth_bridge.imgmsg_to_cv2(msg, '32FC1') frame = cv.resize(depth_image, (640, 480)) depth_image_info = frame.astype(np.float32) # 4. Read the physical depth value at the specified pixel coordinates (unit: millimeter) dist = depth_image_info[self.y, self.x] # 5. Pseudo-color rendering (JET color mapping, red for near, blue for far) depth_image_colored = cv.applyColorMap( cv.convertScaleAbs(depth_image, alpha=0.06), cv.COLORMAP_JET) # 6. Draw measurement info and sample point marker dist_text = f'dist: {round(dist, 3)} mm' cv.putText(depth_image_colored, dist_text, (10, 40), cv.FONT_HERSHEY_SIMPLEX, 1.0, (0, 0, 255), 2) cv.circle(depth_image_colored, (self.x, self.y), 1, (0, 0, 0), 10) cv.imshow(self.window_name, depth_image_colored) cv.setMouseCallback(self.window_name, self.click_callback) cv.waitKey(1)