Bird
Raised Fist0
ROSframework~20 mins

Depth camera integration in ROS - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Depth Camera Integration Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate
2:00remaining
What is the output of this ROS node subscribing to a depth camera topic?
Consider a ROS node subscribing to the topic /camera/depth/image_raw which publishes sensor_msgs/Image messages. The node prints the depth value at pixel (320, 240). What will the node output if the depth image encoding is 16UC1 and the pixel value at (320, 240) is 1000?
ROS
import rclpy
from rclpy.node import Node
from sensor_msgs.msg import Image
import numpy as np

class DepthListener(Node):
    def __init__(self):
        super().__init__('depth_listener')
        self.subscription = self.create_subscription(
            Image,
            '/camera/depth/image_raw',
            self.listener_callback,
            10)

    def listener_callback(self, msg):
        # Convert raw data to numpy array
        depth_array = np.frombuffer(msg.data, dtype=np.uint16).reshape(msg.height, msg.width)
        depth_value = depth_array[240, 320]
        self.get_logger().info(f'Depth at (320,240): {depth_value}')

rclpy.init()
node = DepthListener()
rclpy.spin(node)
node.destroy_node()
rclpy.shutdown()
ARuntime error due to wrong data type
BDepth at (320,240): 0.1
CDepth at (320,240): 1000.0
DDepth at (320,240): 1000
Attempts:
2 left
💡 Hint
Remember that 16UC1 encoding means unsigned 16-bit integers per pixel.
📝 Syntax
intermediate
1:30remaining
Which option correctly initializes a ROS2 publisher for depth images?
You want to create a ROS2 publisher node that publishes depth images on the topic /camera/depth/image_raw with message type sensor_msgs/msg/Image. Which code snippet correctly creates this publisher?
ROS
import rclpy
from rclpy.node import Node
from sensor_msgs.msg import Image

class DepthPublisher(Node):
    def __init__(self):
        super().__init__('depth_publisher')
        # Publisher initialization here

rclpy.init()
node = DepthPublisher()
rclpy.spin(node)
node.destroy_node()
rclpy.shutdown()
Aself.publisher_ = self.create_publisher('/camera/depth/image_raw', Image, 10)
Bself.publisher_ = self.create_publisher(Image, '/camera/depth/image_raw', 10)
Cself.publisher_ = self.create_publisher(Image, 10, '/camera/depth/image_raw')
Dself.publisher_ = self.create_publisher('/camera/depth/image_raw', 10, Image)
Attempts:
2 left
💡 Hint
The create_publisher method takes message type first, then topic name, then queue size.
🔧 Debug
advanced
2:30remaining
Why does this ROS node fail to convert depth image data correctly?
This ROS node subscribes to a depth image topic with encoding '32FC1' but prints incorrect depth values. What is the likely cause?
ROS
def listener_callback(self, msg):
    depth_array = np.frombuffer(msg.data, dtype=np.uint16).reshape(msg.height, msg.width)
    depth_value = depth_array[240, 320]
    self.get_logger().info(f'Depth: {depth_value}')
AUsing np.uint16 instead of np.float32 causes incorrect data interpretation
BThe topic name is incorrect, so no data is received
CThe reshape dimensions are reversed, causing wrong indexing
DThe callback is not registered properly, so it never runs
Attempts:
2 left
💡 Hint
Check the encoding type and matching numpy dtype.
❓ state_output
advanced
2:00remaining
What is the value of the variable 'distance' after processing this depth image message?
Given a depth image message with encoding '16UC1' and pixel value 2000 at (100, 150), what is the value of distance after this code runs?
ROS
depth_array = np.frombuffer(msg.data, dtype=np.uint16).reshape(msg.height, msg.width)
distance = depth_array[150, 100] / 1000.0  # convert mm to meters
A0.2
B2000
C2.0
DRaises IndexError
Attempts:
2 left
💡 Hint
Remember the pixel coordinates order in numpy arrays is [row, column].
🧠 Conceptual
expert
3:00remaining
Which ROS2 QoS profile is best suited for reliable depth camera data streaming in a noisy wireless environment?
You are integrating a depth camera in a ROS2 system over a wireless network prone to packet loss. Which QoS profile should you choose to ensure the most reliable data delivery?
AReliable reliability with volatile durability
BReliable reliability with transient local durability
CBest effort reliability with transient local durability
DBest effort reliability with volatile durability
Attempts:
2 left
💡 Hint
Reliable means guaranteed delivery; durability controls message persistence.

Practice

(1/5)
1. What is the main purpose of integrating a depth camera in a ROS robot system?
easy
A. To send commands to other robots
B. To measure distances and perceive 3D space around the robot
C. To control the robot's motors directly
D. To store large amounts of data on the robot

Solution

  1. Step 1: Understand depth camera function

    A depth camera captures distance information and 3D structure of the environment.
  2. Step 2: Identify its role in ROS

    In ROS, depth cameras help robots sense obstacles and navigate safely by providing spatial data.
  3. Final Answer:

    To measure distances and perceive 3D space around the robot -> Option B
  4. Quick Check:

    Depth camera = 3D sensing [OK]
Hint: Depth cameras help robots see distance and shapes [OK]
Common Mistakes:
  • Confusing depth camera with motor control
  • Thinking it stores data instead of sensing environment
  • Assuming it sends commands to other robots
2. Which ROS launch file command correctly starts a depth camera node named depth_camera_node?
easy
A.
B.
C.
D.

Solution

  1. Step 1: Recall ROS launch syntax for nodes

    ROS launch files use the <node> tag with attributes pkg, type, and name to start nodes.
  2. Step 2: Match correct syntax

    uses , which is correct syntax.
  3. Final Answer:

    <launch><node pkg="camera_pkg" type="depth_camera_node" name="depth_camera_node"/></launch> -> Option A
  4. Quick Check:

    Use <node> tag with pkg and type [OK]
Hint: Use <node> tag with pkg and type attributes [OK]
Common Mistakes:
  • Using incorrect tags like <start> or <run>
  • Missing the name attribute
  • Confusing node and type attributes
3. Given this ROS Python snippet subscribing to a depth image topic, what will be printed when a message arrives?
import rospy
from sensor_msgs.msg import Image

def callback(data):
    print(f"Received depth image with width: {data.width}")

rospy.init_node('depth_listener')
rospy.Subscriber('/camera/depth/image_raw', Image, callback)
rospy.spin()
medium
A. No output because callback is never called
B. Received depth image with width: data.width
C. Error: 'Image' object has no attribute 'width'
D. Received depth image with width: 640

Solution

  1. Step 1: Understand the callback function

    The callback prints the width attribute of the received Image message.
  2. Step 2: Recognize typical Image message fields

    sensor_msgs/Image messages include a width field with the image width, e.g., 640 pixels.
  3. Final Answer:

    Received depth image with width: 640 -> Option D
  4. Quick Check:

    Image.width prints actual width value [OK]
Hint: Image messages have width attribute with pixel count [OK]
Common Mistakes:
  • Thinking width is a string 'data.width'
  • Assuming Image message lacks width attribute
  • Believing callback never triggers
4. You wrote this ROS launch snippet to start a depth camera node but get an error:
<launch>
  <node pkg="camera_pkg" type="depth_camera" name="depth_camera"/>
</launch>

What is the likely cause of the error?
medium
A. Missing closing tag for <launch>
B. The package 'camera_pkg' is not installed
C. The node type 'depth_camera' does not match the executable name
D. The node name cannot be the same as the package name

Solution

  1. Step 1: Check node type and executable name

    The 'type' attribute must exactly match the executable file name in the package.
  2. Step 2: Identify mismatch causing error

    If the executable is named 'depth_camera_node' but 'depth_camera' is used, ROS cannot find it.
  3. Final Answer:

    The node type 'depth_camera' does not match the executable name -> Option C
  4. Quick Check:

    Node type must match executable name [OK]
Hint: Node type must exactly match executable filename [OK]
Common Mistakes:
  • Assuming missing closing tag causes error
  • Ignoring package installation issues
  • Thinking node name conflicts cause this error
5. You want to visualize depth data from a ROS topic /camera/depth/image_raw using OpenCV in Python. Which code snippet correctly converts the ROS Image message to an OpenCV image for display?
hard
A. from cv_bridge import CvBridge bridge = CvBridge() cv_image = bridge.imgmsg_to_cv2(data, desired_encoding='passthrough')
B. import cv2 cv_image = cv2.imread('/camera/depth/image_raw')
C. cv_image = data.data.decode('utf-8')
D. cv_image = numpy.array(data)

Solution

  1. Step 1: Use cv_bridge to convert ROS Image

    cv_bridge provides imgmsg_to_cv2 to convert ROS Image messages to OpenCV format.
  2. Step 2: Apply correct conversion call

    from cv_bridge import CvBridge bridge = CvBridge() cv_image = bridge.imgmsg_to_cv2(data, desired_encoding='passthrough') uses bridge.imgmsg_to_cv2 with 'passthrough' encoding, which preserves depth data correctly.
  3. Final Answer:

    from cv_bridge import CvBridge bridge = CvBridge() cv_image = bridge.imgmsg_to_cv2(data, desired_encoding='passthrough') -> Option A
  4. Quick Check:

    Use cv_bridge.imgmsg_to_cv2 for ROS to OpenCV [OK]
Hint: Use cv_bridge to convert ROS Image to OpenCV image [OK]
Common Mistakes:
  • Trying to read ROS topic as file with cv2.imread
  • Decoding raw data as UTF-8 string
  • Directly converting data to numpy array without bridge
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard