|Please ask about problems and questions regarding this tutorial on answers.ros.org. Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags.|
Writing a URDF parser with roslibjsDescription: This tutorial shows you how to fetch a URDF model of a robot and parse it with roslibjs.
Keywords: roslibjs, web interface, urdf, Robot Web Tools
Tutorial Level: BEGINNER
The complete code for this tutorial can be found in the roslibjs repo.
The HTML Code
Now that we have an example, let's look at each component.
We need to create a Ros node object to communicate with a rosbridge server. In this example, the script will connect to localhost on the default port of 9090.
When running the roslaunch instructions for pr2_description below, the URDF of the PR2 is stored as a param labeled "robot_description" in the Parameter Server.
The "robot_description" param is retrieved from the Parameter Server. The value, if it exists, is a string containing the URDF XML.
The ROSLIB.UrdfModel is responsible for parsing the string. It takes the XML in the constructor, parses it, and provides access to each link, mesh, etc. Check out the ROSLIB.UrdfModel docs for the options and functions available.
This adds a listener for a connection event to the ros object. The following two blocks do the same for error and close events. This way, we can monitor the connection to the rosbridge server.
If interested in visualizing the robot model from the URDF, there's a ros3djs tutorial, which extends this tutorial.
Running the Example
At this point we are ready to run the example. To do so, you will need to have installed the following packages:
- ros-groovy-ros-base (basic ROS installation)
- ros-groovy-pr2-common (Contains the PR2 model)
To begin, we will launch ROS. To do so, run the following in a terminal:
Next, we'll start the PR2 Description node, which sets the URDF model:
roslaunch pr2_description upload_pr2.launch
Once everything is running, we can launch the rosbridge v2.0 server with the following:
roslaunch rosbridge_server rosbridge_websocket.launch
Finally, you are now ready to bring up your HTML page in a web browser. You can open up the file directly in the browser without running a web server. The data is outputted to the browser's Web Console.