You are currently viewing ROS Tutorial: Visualize the UR5 robot in Rviz – URDF explained

ROS Tutorial: Visualize the UR5 robot in Rviz – URDF explained

Great news! You don’t need an actual robot to start with robotics. Rviz is a ROS tool for visualizing robots virtually on your computer. All you need for that is a virtual description of your robot model, a so called URDF. In this article we will visualize the UR5 robot from Universal Robots in Rviz and have a look at its URDF. We will also talk about robot kinematics which is one of the fundamental concepts and important to understand when doing robotics. Sounds good? Let’s start!

Note: If you just want to get the UR5 up and running in Rviz without reading more about URDFs and robot kinematics, you can jump directly to the Quickstart section where you find only the neccessary commands to get started in no time. Otherwise let’s get right into it!

Installing an launching Rviz with the UR5 robot

I’m assuming that you have the ROS distribution of your choice installed on your Linux operating system. If not, please do so as described here. If Rviz is not already installed (which it usually is, together with a ROS installation), simply run:

$ sudo apt-get install ros-$ROS_DISTRO-rviz

Additionally, install the following package which publishes the states (e.g. angles) of our robot joints:

$ sudo apt-get install ros-$ROS_DISTRO-joint-state-publisher-gui

In order to have a nice looking robot in our Visualization and not just a bunch of coordinate frames that are floating around in space we have to tell Rviz what our robot looks like. Therefore, we want to install the universal-robot package from the ROS industrial project. This package provides a lot of files and functionality needed in order to work with the different robots from Universal Robots. Amongst other things it contains the visual information we are searching for inside its ur_description package. So first go ahead and clone the universal-robot repository into the src directory of your workspace.

~/catkin_ws/src$ git clone -b $ROS_DISTRO-devel https://github.com/ros-industrial/universal_robot.git

If you don’t use git you can also just download the repository and extract it into your workspace. Next we have to make sure that all the dependencies are installed:

~/catkin_ws/src$ cd ..
$ rosdep update
$ rosdep install --rosdistro $ROS_DISTRO --ignore-src --from-paths src

Then build your workspace and activate the workspace if that’s not already done by default:

~/catkin_ws$ catkin_make
$ source $HOME/catkin_ws/devel/setup.bash

Now the best thing in order to follow along with this tutorial is to install the urdf_tutorial package from ROS.

$ sudo apt-get install urdf_tutorial

The URDF we will use for this tutorial is stored under this link. Copy the content of the URDF into a text document and save it as ‘ur5_rviz.urdf’ on your file system in a location of your choice. Then, to display the robot just run:

$ roslaunch urdf_tutorial display.launch model:='<path-to-the-urdf-file>/ur5_rviz.urdf'

Or you can directly use the launch files provided by the ur_description package and run the following two commands:

$ roslaunch ur_description ur5_upload.launch
$ roslaunch ur_description view_ur5.launch

This tutorial will explain the custom URDF and the display.launch file that is used by urdf_tutorial because the ur5_description package provides additional stuff in these files that we don’t need right now but both ways it will work the same way in Rviz.

After running the launch file you will see the UR5 robot displayed in Rviz. That was easy right? In addition to Rviz, the launch file also starts a small GUI that lets you move the robot joints separately. That’s fun but simply playing around unfortunately doesn’t teach us a lot so lets look at the URDF behind the scenes and understand how it works.

The URDF file

If you haven’t copied the URDF to your file system before you can view the complete file here to follow along while we go through the structure of the URDF. It uses the XML format which consists of different tags that are filled with information. The robot we want to describe consists of links and joints which provides the basic file structure:

<robot name=”ur5”>
  <link name = “...”>
    …
  </link>
  <joint name = “...”>
    …
  </joint>
  ...
</robot>

All we have to tell Rviz about the links for now is what they look like. It is possible to create your own custom robot by defining some geometries directly in your URDF (see this tutorial for details), but as our UR5 robot already exists and is well documented we simply use a file .dae that describes its appearance. This file is contained in the ur_description package and derived right from the CAD model of the robot. Note that this is only used for describing its visual appearance.

As an example, the .dea file for the Shoulder joint is included as follows :

<link name="shoulder_link">
    <visual>
      <geometry>
        <mesh filename="package://ur_description/meshes/ur5/visual/Shoulder.dae"/>
      </geometry>
    </visual>
  </link>

Regarding the joints we first need to define their type. The UR5 has rotating joints with certain limits, which fall under the category “revolute”. The purpose of the joints is to connect and move the links, so inside the <joint> tag we specify a parent and a child link. The <origin> and <axis> tags describe the robot kinematics.

<joint name="shoulder_lift_joint" type="revolute">
    <parent link="shoulder_link"/>
    <child link="upper_arm_link"/>
    <origin rpy="0.0 1.570796325 0.0" xyz="0.0 0.13585 0.0"/>
    <axis xyz="0 1 0"/>
    <limit effort="150.0" lower="-3.14159265" upper="3.14159265" velocity="3.15"/>
  </joint>

The joint description is worth looking into in more detail so lets dive in by taking Rviz as an aid to visualize what is going on.

Robot Kinematics

To visualize the robot kinematics we imagine one coordinate frame in the center of every joint. In order to describe the kinematic chain we simply start from the coordinate frame in the base frame and see how it propagates through the robot before reaching the last joint. Two changes can happen from one coordinate frame to the next. It can rotate around one of its own axes as we can see in the left picture by the x-, y-, and z-axes that are color coded. and its origin can be shifted from one joint to the next as the arrows indicate in the right picture (In this case, the arrows point in the opposite direction but you get the concept).

This propagation from one joint to the next is what is described in the URDF. As an example, let’s look at the shoulder pan and shoulder lift joint again and it’s corresponding parent and child links, respectively.

Coordinate frames in the base and shoulder joints

We start with the world frame that resides in the bottom of the robot’s base link. That is where the robot is connected to the world and there our kinematic chain starts. In order to get to the second coordinate frame in the center of the shoulder pan joint we must shift the frame along the z-axis. And this is exactly what is defined in the <origin> and <axis> tags.

<origin rpy="0.0 0.0 0.0" xyz="0.0 0.0 0.089159"/>
<axis xyz="0 0 1"/>

The xyz attribute refers to linear shifts of the coordinate frame between joints. The URDF shows that the first frame must be shifted 0.089159 (meters) along the z-axis to get to the second frame, while the other axes don’t change. The axis tag defines around which axis the joint is rotating during operation (in this example the z-axis). Note that this is after the frame was propagated.

Now in order to get to the third frame, there is a bit more going on. In addition to moving along the y-axis we also have to rotate the coordinate frame. This is contained in the description for the shoulder lift joint:

<origin rpy="0.0 1.570796325 0.0" xyz="0.0 0.13585 0.0"/>
<axis xyz="0 1 0"/>

The rpy attribute stands for roll, pitch and yaw. These are naming conventions that are defined as follows:

  • Roll: Rotation around the x-axis
  • Pitch: Rotation around the y-axis
  • Yaw: Rotation around the z-axis

The URDF tells us the rotation angle in radiants, so in order to get to the third coordinate frame we must rotate 1.570796325 rad (90 degrees) around the y-axis. This scheme is continued until we end up at the last frame at the last robot joint.

I hope this was helpful to clarify how the structure of the robot – its kinematics – is described in the URDF. For the UR5 this is the pose that universal robots defines as the zero configuration. You can comprehend this method for the complete robot by setting all the joint angles to zero position and going through the joints one by one as we did for the shoulder joints.

Now we know how to describe a robot in a simple file such that we can look at it and play with it virtually. This setup is great to develop things like motion planners for our robot. However, apart from visualizing our robot we want to also simulate how it would behave in the real world where the laws of physics come into play. That’s why in the next tutorial we will have a look at how to extend our URDF for use in the powerful simulation tool Gazebo! Also you can find an overview of all tutorials here!

Quickstart

With ROS being installed on your computer you already should have Rviz installed. If not, run:

$ sudo apt-get install ros-$ROS_DISTRO-rviz

Install the ur5_description package from the ROS-industrial project by building it from source and check the dependencies:

~/catkin_ws/src$ git clone -b $ROS_DISTRO-devel https://github.com/ros-industrial/universal_robot.git
~/catkin_ws/src$ cd ..
$ rosdep update
$ rosdep install --rosdistro $ROS_DISTRO --ignore-src --from-paths src

Then build your workspace:

~/catkin_ws$ catkin_make
$ source $HOME/catkin_ws/devel/setup.bash

To spawn your robot in Rviz simply run:

$ roslaunch ur_description ur5_upload.launch
$ roslaunch ur_description view_ur5.launch 

If you also want to simulate your robot in Gazebo check out this article. You can find an overview of all tutorials here.