Basic URDF & RViz
In this video, we’re going to start from the scratch a robotic manipulator.
From the URDF model, we’re going to define the first two links and visualize it in RViz. Up to the end of the video, we’ll have a basic model, a launch file to visualize it and a RViz configuration file for this specific project.
- [irp posts=”9104″ name=”My Robotic Manipulator #02 – URDF + XACRO”]
- Repositories Robot description
- Course: Robot Creation with URDF ROS
Go to ROS Development Studio and create a new project. Provide a suitable project name and some useful description. Open the project (this will take few seconds)
Once the project is loaded run the IDE from the tools menu. Also verify that the initial directory structure should look like the following:
. ├────── ai_ws ├────── catkin_ws │ ├─── build │ ├─── devel │ └─── ├────── notebook_ws │ ├─── default.ipynb │ └─── images └────── simulation_ws ├─── build ├─── devel └─── src
Note that we use
simulation_ws to contain all the files related to simulations. Those files not related to simulations will go to
catkin_ws (like python scripts, launch files, etc)
We will now create a
catkin package with name mrm_description with URDF as a dependency.
Start a SHELL from
tools menu and navigate to ~simulation_ws/src directory as follows
$ cd simulation_ws/src
Now we create the
catkin package with the following command
$ catkin_create_pkg mrm_description urdf
After creating the
catkin package we will now create a directory URDF inside the mrm_description directory.
Select IDE from the
tools menu, it will open the IDE window. Here you can browse through folders by double-clicking on folders. To create a new folder right click on the parent folder and choose the option New Folder and type in the name you want to give to the folder.
Create a directory structure as shown:
Further we need to create two files mrm.xacro (inside urdf directory) and rviz.launch (inside launch directory). The
xacro file contains the description of manipulator. The
launch file will help us in starting the simulation or visualization. Inside the mrm.xacro file copy paste the following content:
<?xml version="1.0" ?> <robot name="mrm" xmlns:xacro="http://www.ros.org/wiki/xacro"> <link name="base_link"> <visual> <origin rpy="0 0 0" xyz="0 0 0"/> <geometry> <box size="1 1 1"/> </geometry> </visual> </link> <joint name="base_link__link_01" type="revolute"> <axis xyz="0 0 1" /> <limit effort="1000.0" lower="-3.14" upper="3.14" velocity="0.5" /> <origin rpy="0 0 0" xyz="0 0 0.5"/> <parent link="base_link"/> <child link="link1"/> </joint> <link name="link1"> <visual> <origin rpy="0 0 0" xyz="0 0 0.2"/> <geometry> <cylinder radius="0.35" length="0.4"/> </geometry> </visual> </link> </robot>
xacro file is a description of our robot in xml language. The robot is composed of various links and joints. In the above
xacro we have two links base_link and link1. The base_link is fixed to the ground. It is connected to the link1 with a revolute joint. The joint is such that it allows the link1 to rotate about z-axis. We are defining the visual properties in this file. The
geometry property controls the appearance and
origin property controls the positioning of the elements. The
joint element has an
axis property which defines the degree of freedom of the links connected with joint. In addition to
axis property the
joint element has
limit property to control the range of motion,
child property to control the relative motion (the child link moves with respect to the parent link)
Now we are ready to visualize the manipulator. Create a launch file by name rviz.launch inside the launch directory (see below).
Write the following contents to the mrm.launch file:
<launch> <param name="robot_description" command="$(find xacro)/xacro --inorder '$(find mrm_description)/urdf/mrm.xacro'"/> <node name="robot_state_publisher" pkg="robot_state_publisher" type="state_publisher"/> <node name="rviz" pkg="rviz" type="rviz"/> <node name="joint_state_publisher" pkg="joint_state_publisher" type="joint_state_publisher" > <param name="use_gui" value="True"/> </node> </launch>
This launch file helps in the task of launching different node together. Above file creates three nodes, the first node is for publishing the robot state, the second node starts rviz and the last node starts a gui tool that helps in manipulating joint angle of the robot. The first line (param) helps in locating and loading the xacro file that contains the robot description.
Now we can launch the project with the following command
$ roslaunch mrm_description rviz.launch
To see the visualization we need to start the GUI tool from the Tools menu
The GUI tool is like a remote desktop, when it starts you can see there are two tabs in the bottom. One is rviz tool and other is joint_state_publisher gui as shown
In the rviz window we need to do some modifications
- change Fixed Frame to
- add an Axis element
- add an RobotModel element
The images show the operations described above
Now you can move the slider in joint_state_publisher gui tool and see the movement of link1 about the base_line. Finally, we can save the
rviz configuration that will do all the steps we just did automatically on next invocation. Use the save as menu option to save the
rviz config, browse to launch directory and we are done. By modifying one line in our launch file we will load this rviz config and all settings will be loaded. The final launch code should look like the following:
<launch> <param name="robot_description" command="$(find xacro)/xacro --inorder '$(find mrm_description)/urdf/mrm.xacro'"/> <node name="robot_state_publisher" pkg="robot_state_publisher" type="state_publisher"/> <node name="rviz" pkg="rviz" type="rviz" args=" -d $(find mrm_description)/launch/config.rviz" /> <node name="joint_state_publisher" pkg="joint_state_publisher" type="joint_state_publisher" > <param name="use_gui" value="True"/> </node> </launch>
The next time you launch the project the rviz will load with settings we did above.