Complete the code to initialize a ROS 1 node.
ros::init(argc, argv, [1]);In ROS 1, ros::init requires the node name as a string.
Complete the code to create a ROS 2 node using rclcpp.
auto node = rclcpp::Node::make_shared([1]);In ROS 2, nodes are created with make_shared and the node name is a string.
Fix the error in the ROS 1 publisher creation code.
ros::Publisher pub = node.advertise<std_msgs::String>([1], 10);
The topic name must be a string, so it should be in quotes like "chatter".
Fill both blanks to create a ROS 2 subscription with a lambda callback.
auto sub = node->create_subscription<std_msgs::msg::String>([1], 10, [2]);
The first blank is the topic name as a string, the second is the lambda callback function.
Fill all three blanks to process callbacks in a non-blocking loop and clean up a ROS 1 node.
while (ros::[1]()) { ros::[2](); } ros::[3]();
ros::spin() which blocks indefinitely.while(ros::ok()) loop with spinOnce().Check ros::ok() in the while condition, use spinOnce() to process callbacks non-blockingly, and call shutdown() to clean up.
