Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to initialize the ROS node for displaying the robot model.
ROS
ros::init(argc, argv, [1]);Attempts:
3 left
💡 Hint
Common Mistakes
Using variable names instead of a string literal.
Omitting the quotes around the node name.
✗ Incorrect
The ROS node name is set by the string argument in ros::init. Here, "robot_display" is the chosen node name.
2fill in blank
mediumComplete the code to load the URDF file into a string variable.
ROS
std::string urdf_string; if (!ros::param::get("[1]", urdf_string)) { ROS_ERROR("Failed to get URDF from parameter server"); }
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect parameter names like "urdf_file".
Forgetting the quotes around the parameter name.
✗ Incorrect
The standard ROS parameter name for the URDF is "robot_description".
3fill in blank
hardFix the error in the code to correctly initialize the URDF model from the string.
ROS
urdf::Model model; if (!model.[1](urdf_string)) { ROS_ERROR("Failed to parse URDF model"); }
Attempts:
3 left
💡 Hint
Common Mistakes
Using initFile which expects a file path, not a string.
Using incorrect method names like loadModel or parseURDF.
✗ Incorrect
The correct method to initialize a URDF model from a string is initString.
4fill in blank
hardFill both blanks to create a ROS publisher for the robot state and advertise it.
ROS
ros::Publisher robot_pub = nh.[1]<sensor_msgs::JointState>("[2]", 10);
Attempts:
3 left
💡 Hint
Common Mistakes
Using publish instead of advertise to create the publisher.
Using subscribe which is for subscribers, not publishers.
✗ Incorrect
To create a publisher, use advertise with the topic name, here "robot_state".
5fill in blank
hardFill all three blanks to create a loop that publishes the robot state at 10 Hz.
ROS
ros::Rate loop_rate([1]); while (ros::ok()) { sensor_msgs::JointState msg; // Fill msg fields here [2].publish(msg); ros::spinOnce(); [3].sleep(); }
Attempts:
3 left
💡 Hint
Common Mistakes
Using nh instead of the publisher to publish messages.
Calling sleep on nh instead of loop_rate.
✗ Incorrect
The loop rate is set to 10 Hz, the publisher is robot_pub, and sleep is called on loop_rate.
