Complete the code to initialize a ROS node for sensor visualization.
import rospy def main(): rospy.[1]('sensor_visualizer') if __name__ == '__main__': main()
In ROS, rospy.init_node() initializes a node with a given name.
Complete the code to subscribe to a laser scan topic named '/scan'.
from sensor_msgs.msg import LaserScan rospy.Subscriber('/scan', [1], laser_callback)
The LaserScan message type is used for laser sensor data in ROS.
Fix the error in the callback function to correctly process IMU data.
from sensor_msgs.msg import Imu def imu_callback(msg): orientation = msg.[1].orientation rospy.loginfo(f"Orientation: {orientation}")
The Imu message has an orientation field directly accessible.
Fill both blanks to publish a processed camera image on topic '/camera_processed'.
from sensor_msgs.msg import Image publisher = rospy.Publisher('/camera_processed', [1], queue_size=[2])
Publishing images requires the Image message type and a queue size integer.
Fill all three blanks to create a dictionary comprehension that maps sensor names to their message types if the sensor is active.
sensors = {'laser': LaserScan, 'camera': Image, 'imu': Imu}
active_sensors = {'laser': True, 'camera': False, 'imu': True}
active_msgs = { [1]: [2] for [3] in sensors if active_sensors[[1]] }The comprehension iterates over sensor names, uses the name as key, and maps to the message type from the sensors dict.
