Complete the code to create a ROS publisher that sends messages on a topic.
pub = node.create_publisher(std_msgs.msg.String, '[1]', 10)
The topic name '/chatter' is used to publish messages. This enables decoupled communication by letting publishers and subscribers connect via this topic.
Complete the code to subscribe to a topic and receive messages.
sub = node.create_subscription(std_msgs.msg.String, '/chatter', [1], 10)
The subscriber needs a callback function to process incoming messages. 'listener_callback' is the function called when a message arrives.
Fix the error in the code to publish a message on the topic.
msg = std_msgs.msg.String() msg.data = 'Hello ROS' pub.[1](msg)
The correct method to send a message on a ROS topic is 'publish'. Other methods do not exist or cause errors.
Fill both blanks to create a topic subscriber with a callback that prints the message data.
def [1](msg): print(msg.[2]) sub = node.create_subscription(std_msgs.msg.String, '/chatter', [1], 10)
The callback function is named 'listener_callback'. The message data is accessed via 'msg.data'.
Fill all three blanks to create a publisher, a message, and publish it on the topic.
pub = node.create_publisher(std_msgs.msg.String, [1], 10) msg = std_msgs.msg.String() msg.[2] = 'Decoupled communication' pub.[3](msg)
The topic name is '/chatter'. The message content is set with 'data'. The method to send the message is 'publish'.
