Challenge - 5 Problems
Sensor Data Visualization Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediateWhat does this ROS node output when visualizing laser scan data?
Consider a ROS node subscribing to a LaserScan topic and publishing a MarkerArray for visualization. What will be the visible output in RViz if the node publishes a MarkerArray with points corresponding to the laser scan ranges?
ROS
import rospy from sensor_msgs.msg import LaserScan from visualization_msgs.msg import Marker, MarkerArray from geometry_msgs.msg import Point from math import cos, sin class LaserVisualizer: def __init__(self): self.pub = rospy.Publisher('visualization_marker_array', MarkerArray, queue_size=1) self.sub = rospy.Subscriber('scan', LaserScan, self.callback) def callback(self, msg): markers = MarkerArray() marker = Marker() marker.header = msg.header marker.type = Marker.POINTS marker.action = Marker.ADD marker.scale.x = 0.05 marker.scale.y = 0.05 marker.color.a = 1.0 marker.color.r = 1.0 for i, r in enumerate(msg.ranges): if r < msg.range_max: angle = msg.angle_min + i * msg.angle_increment x = r * cos(angle) y = r * sin(angle) p = Point() p.x = x p.y = y p.z = 0 marker.points.append(p) markers.markers.append(marker) self.pub.publish(markers) rospy.init_node('laser_visualizer') vis = LaserVisualizer() rospy.spin()
Attempts:
2 left
💡 Hint
Think about how Marker type POINTS displays data in RViz.
✗ Incorrect
The Marker type POINTS displays individual points at specified coordinates. The code converts laser ranges to XY points and publishes them as red points. Lines or meshes require different Marker types.
📝 Syntax
intermediateWhich option correctly subscribes to a ROS camera image topic using cv_bridge?
You want to subscribe to the '/camera/image_raw' topic and convert the ROS Image message to an OpenCV image for processing. Which code snippet correctly does this?
ROS
import rospy from sensor_msgs.msg import Image from cv_bridge import CvBridge, CvBridgeError import cv2 class ImageProcessor: def __init__(self): self.bridge = CvBridge() self.sub = rospy.Subscriber('/camera/image_raw', Image, self.callback) def callback(self, msg): try: cv_image = self.bridge.imgmsg_to_cv2(msg, 'bgr8') # process cv_image here except CvBridgeError as e: rospy.logerr(e) rospy.init_node('image_processor') proc = ImageProcessor() rospy.spin()
Attempts:
2 left
💡 Hint
Remember to use the instance method of CvBridge to convert ROS Image to OpenCV image.
✗ Incorrect
The correct method to convert a ROS Image message to an OpenCV image is imgmsg_to_cv2 called on a CvBridge instance. Option B calls it on the class, which is invalid. Options A and D use wrong method names or call cv2 directly.
🔧 Debug
advancedWhy does this IMU visualization node fail to update orientation markers in RViz?
Given this ROS node snippet that subscribes to IMU data and publishes an Arrow marker to visualize orientation, why does the arrow not update in RViz?
ROS
def imu_callback(msg): marker = Marker() marker.header = msg.header marker.type = Marker.ARROW marker.action = Marker.ADD marker.scale.x = 0.5 marker.scale.y = 0.1 marker.scale.z = 0.1 marker.color.a = 1.0 marker.color.g = 1.0 marker.pose.orientation = msg.orientation pub.publish(marker) rospy.Subscriber('/imu/data', Imu, imu_callback) pub = rospy.Publisher('imu_marker', Marker, queue_size=1)
Attempts:
2 left
💡 Hint
Markers need an id to be updated properly in RViz.
✗ Incorrect
RViz requires each Marker to have a unique id within the namespace to update it. Without setting marker.id, RViz treats each message as a new marker and does not update the previous one, so the arrow appears static or missing.
🧠 Conceptual
advancedWhat is the main advantage of using ROS message filters when visualizing synchronized sensor data?
When visualizing data from multiple sensors like laser, camera, and IMU, why is it beneficial to use ROS message_filters ApproximateTimeSynchronizer or TimeSynchronizer?
Attempts:
2 left
💡 Hint
Think about how sensor data timestamps affect combined visualization.
✗ Incorrect
Message filters synchronize messages from multiple topics based on timestamps, allowing the node to process data that corresponds to the same time frame. This is crucial for accurate fused visualization of sensors like laser, camera, and IMU.
❓ state_output
expertWhat is the output of this ROS Python node publishing a PointCloud2 message from laser scan data?
This node converts LaserScan ranges to a PointCloud2 message and publishes it. What will be the number of points in the published PointCloud2 message if the laser scan has 360 range readings and 10 of them are out of range (greater than range_max)?
ROS
import rospy from sensor_msgs.msg import LaserScan, PointCloud2, PointField import sensor_msgs.point_cloud2 as pc2 from std_msgs.msg import Header from math import cos, sin class LaserToPointCloud: def __init__(self): self.pub = rospy.Publisher('cloud', PointCloud2, queue_size=1) self.sub = rospy.Subscriber('scan', LaserScan, self.callback) def callback(self, scan): points = [] for i, r in enumerate(scan.ranges): if r <= scan.range_max: angle = scan.angle_min + i * scan.angle_increment x = r * cos(angle) y = r * sin(angle) points.append([x, y, 0.0]) header = Header() header.stamp = rospy.Time.now() header.frame_id = scan.header.frame_id fields = [ PointField('x', 0, PointField.FLOAT32, 1), PointField('y', 4, PointField.FLOAT32, 1), PointField('z', 8, PointField.FLOAT32, 1) ] cloud = pc2.create_cloud(header, fields, points) self.pub.publish(cloud) rospy.init_node('laser_to_cloud') converter = LaserToPointCloud() rospy.spin()
Attempts:
2 left
💡 Hint
Points with ranges greater than range_max are excluded from the point list.
✗ Incorrect
The code only appends points where the range is less than or equal to range_max. Since 10 points exceed range_max, they are excluded. Therefore, the PointCloud2 message contains 360 - 10 = 350 points.
