Complete the code to initialize a ROS node named 'listener'.
ros::init(argc, argv, [1]);The ros::init function initializes the ROS node with the given name. Here, the node is named 'listener'.
Complete the code to create a NodeHandle object named 'nh'.
ros::[1] nh;The ros::NodeHandle object is used to interact with the ROS system, including creating subscribers.
Fix the error in the subscriber creation line by filling the blank with the correct message type.
ros::Subscriber sub = nh.subscribe("chatter", 1000, chatterCallback); // Message type: [1]
The subscriber listens to the 'chatter' topic which uses the std_msgs::String message type.
Fill both blanks to complete the subscriber callback function signature correctly.
void [1](const [2]::ConstPtr& msg) { ROS_INFO("I heard: %s", msg->data.c_str()); }
The callback function is named chatterCallback and it receives a constant pointer to a std_msgs message.
Fill all three blanks to complete the main function that initializes ROS, creates a NodeHandle, subscribes to 'chatter', and spins.
int main(int argc, char **argv) {
ros::[1](argc, argv, "listener");
ros::[2] nh;
ros::Subscriber sub = nh.subscribe("chatter", 1000, [3]);
ros::spin();
return 0;
}The main function initializes ROS with init, creates a NodeHandle, subscribes to 'chatter' with the callback chatterCallback, and calls ros::spin() to process callbacks.
