Unit 1: Creating The Visual Robot Model With URDF: Warning
Unit 1: Creating The Visual Robot Model With URDF: Warning
In this unit, you will learn how to go from a physical robot to a visual virtual model. By visual, we
understand that its not a physically working simulation model. It's only the barebones of what, at the
end, will be used for simulation.
But this URDF Visual model is already very useful.
If you have a real robot and you want to use the ROS infrastructure, you need a virtual description of
how the robot is connected and where each of the sensors is in some applications. For example, if
you have a camera mounted on the head of the robot, through the virtual robot description (the
URDF file ), you can use the TF ROS structure to know exactly where the camera is based by only
the joint sensor readings.
It also allows you to represent the robot model inside RVIZ.
Warning
Before starting, please check that you have terminated any of the scripts that you launched in the
previous unit.
Create your first URDF Model
So, you will start by creating the URDF of the robot Mira.
For this, you will follow these steps:
Learn how to use the URDF creation tools and the step-by-step procedure for creating a
robot model.
Learn about the morphology of the robot you want to work with.
Obtain the 3D models that you will need in the correct format.
Generate the link and joint structure.
Test the movement of the joints.
So, let's get started.
1. Learn how to use the URDF creation tools and the creation
procedure
Let's create the URDF file in the appropriate ROS structure.
Let's create a ROS package for each robot model that you create.
In this case, create a ROS package named "my_mira_description." It's a common practice to always
create a "my_robot_description" package where you store all of the files that describe the robot. You
will find this robotname_description package everywhere in ROS packages that have robot models
defined.
Execute in WebShell #1
In [ ]:
cd /home/user/catkin_ws/src
In [ ]:
In [ ]:
cd /home/user/catkin_ws/src;rospack profile
In [ ]:
roscd my_mira_description
In [ ]:
touch urdf/mira_simple.urdf
You can also create it through the IDE.
Now, create the simplest URDF:
mira_simple.urdf
In [ ]:
<?xml version="1.0"?>
<robot name="mira">
<link name="base_link">
<visual>
<origin rpy="0 0 0" xyz="0 0 0"/>
<geometry>
<cylinder radius="0.06" length="0.09"/>
</geometry>
</visual>
</link>
<link name="roll_M1_link">
<visual>
<origin rpy="0 0 0" xyz="0 0 0"/>
<geometry>
<cylinder radius="0.06" length="0.09"/>
</geometry>
</visual>
</link>
</robot>
END mira_simple.urdf
1. All of the measurements in URDF are in the International Unit System. Therefore, meters for
distance, radians for angles, and kilograms for weight.
2. There are three basic geometry shapes that can be used: box, cylinder, and sphere.
In [ ]:
In [ ]:
cd /home/user/catkin_ws/src
In [ ]:
roscd my_mira_description
In [ ]:
touch launch/urdf_visualize.launch
In [ ]:
<launch>
<!-- USE: roslaunch my_mira_description urdf_visualize.launch model:='$(find myrobot_package)/urdf/myrobot.urdf'
-->
<arg name="model" default=""/>
</launch>
In this launch file, you have:
In [ ]:
In [ ]:
roscd my_mira_description/urdf
In [ ]:
urdf_to_graphiz mira_simple.urdf
This tool generates the link and joint tree:
evince mira_simple.pdf
Great, you have your first URDF working!
Exercise U1-1
Play around to get used to the basics of URDF.
Change the Geometry Shapes
Change the sizes and investigate how you might be able to see the links inside other links.
Change the orientation and position of the different links.
Change the axis of rotation of the joint to make it revolve around Y or Z.
Change the type of joint to continuous. Bear in mind that you shouldn't have upper and lower
limits anymore. But you should leave the effort and speed limits because those are also
relevant in continuous joints.
Change the base_link colour to orange and the roll_M1_link to green.
To change position and orientation, you have to add the origin tag, like so:
In [ ]:
<?xml version="1.0"?>
<robot name="mira">
<link name="base_link">
<visual>
<origin rpy="0 0 0" xyz="0 0 0"/>
<geometry>
<cylinder radius="0.06" length="0.09"/>
</geometry>
</visual>
</link>
</robot>
It's based on the xyz axis of the parent frame; in this case, it's the absolute world frame because it's
the first link in the URDF file. X = RED color AXIS, Y = GREEN color AXIS, and Z = BLUE color
AXIS.
As for the rpy (Roll, Pitch, and Yaw ), it's also the parent's axis that corresponds to Roll = Rotation in
the X axis, Pitch = Rotation in the Y axis, and Yaw = Rotation in the Z axis.
To change color in URDF, you need to define a material and assign it to the geometry, like so:
In [ ]:
<?xml version="1.0"?>
<robot name="mira">
<material name="green">
<color rgba="0 0.8 0 1"/>
</material>
<link name="base_link">
<visual>
<geometry>
<cylinder radius="0.06" length="0.09"/>
</geometry>
<material name="green"/>
</visual>
</link>
</robot>
The color is defined by using the RGBA system, by using a scale of 0 to 1 instead of 0 to 255. Learn
more about RGBA at these example sites.
https://www.w3schools.com/css/css3_colors.asp
https://www.w3schools.com/css/tryit.asp?filename=trycss3_color_rgba
END Exercise U1-1
This system emulates the real system, giving Roll, Pitch, and Yaw Movements.
The Roll link connects to the base_link and rotates around the X axis.
The Pitch link connects to the base_link and rotates around the Y axis.
The Yaw link connects to the base_link and rotates around the Z axis.
Using the colors that match the axis helps a lot to keep the rotating axis clear. So bear that in mind
when you define these kind of links.
These joints will also be the ones that are actuated when we introduce the actuators and controls in
the simulation.
Note that we could have positioned the Yaw link in the center, but it's positioned in that way to be
easy to see, and to slightly emulate the real system.
Exercise U1-2
Seeing that you now have the structure of Mira clear, generate the whole URDF file, using only
geometric shapes to represent the links.
We recommend that you go step by step. Add one link and a joint, and test. Then, when it's okay,
continue to the next one. Otherwise, it can become overwhelming.
Data for Exercise U1-2
Joints To be defined:
roll_joint( base_link with roll_M1_link)
pitch_joint( roll_M1_link with pitch_M2_link)
yaw_joint( pitch_M2_link with yaw_M3_link)
base_head_joint( yaw_M3_link with head_link)
head_lefteye_joint( head_link with left_eye_link)
head_righteye_joint( head_link with right_eye_link)
head_camera_joint( head_link with camera_link)
To decide the Joint type, think about whether they have to move or not (fixed), and if they
have to be limited (revolute) or not (continuous).
Here you have the dimensions of the links:
base_link --> cylinder radius="0.06" length="0.09"
roll_M1_link --> cylinder length="0.005" radius="0.01"
pitch_M2_link --> cylinder length="0.005" radius="0.01"
yaw_M3_link --> cylinder length="0.005" radius="0.01"
head_link --> sphere radius="0.06"
left_eye_link --> cylinder radius="0.00525" length="0.00525"
right_eye_link --> cylinder radius="0.00525" length="0.00525"
camera_link --> box size="0.0005 0.0005 0.0005"
You will have to decide the origin of xyz and the RPY of each link. It doesn't have to be
perfect, but try your best to experience how difficult it can be to get a model right without a
blueprint. You will also get your bearings in the XYZ movement.
END Exercise U1-2
Solution Exercise U1-2
Please try to do it by yourself, unless you get stuck or need some inspiration. You will learn much
more if you fight for each exercise.
Here you have the whole URDF file for the Mira model:
In [ ]:
roscd my_mira_description
touch urdf/mira_geometric.urdf
mira_geometric.urdf
In [ ]:
<?xml version="1.0"?>
<robot name="mira">
<material name="blue">
<color rgba="0 0 0.8 1"/>
</material>
<material name="red">
<color rgba="0.8 0 0 1"/>
</material>
<material name="green">
<color rgba="0 0.8 0 1"/>
</material>
<material name="grey">
<color rgba="0.75 0.75 0.75 1"/>
</material>
<material name="white">
<color rgba="1.0 1.0 1.0 1"/>
</material>
<material name="black">
<color rgba="0 0 0 1"/>
</material>
<visual>
<origin rpy="0.0 0 0" xyz="0 0 0"/>
<geometry>
<cylinder radius="0.06" length="0.09"/>
</geometry>
<material name="grey"/>
</visual>
</link>
<link name="roll_M1_link">
<visual>
<origin rpy="0 0 0" xyz="0 0 0"/>
<geometry>
<cylinder length="0.005" radius="0.01"/>
</geometry>
<material name="red"/>
</visual>
</link>
<link name="pitch_M2_link">
<visual>
<origin rpy="0 0 0" xyz="0 0 0"/>
<geometry>
<cylinder length="0.005" radius="0.01"/>
</geometry>
<material name="green"/>
</visual>
</link>
<visual>
<origin rpy="0 0 0" xyz="0 0 0"/>
<geometry>
<cylinder length="0.005" radius="0.01"/>
</geometry>
<material name="blue"/>
</visual>
</link>
<link name="head_link">
<visual>
<origin rpy="0.0 0 0" xyz="0 0 0"/>
<geometry>
<sphere radius="0.06"/>
</geometry>
<material name="white"/>
</visual>
</link>
<link name="left_eye_link">
<visual>
<origin rpy="0.0 0 0" xyz="0 0 0"/>
<geometry>
<cylinder radius="0.00525" length="0.00525"/>
</geometry>
<material name="black"/>
</visual>
</link>
<link name="right_eye_link">
<visual>
<origin rpy="0.0 0 0" xyz="0 0 0"/>
<geometry>
<cylinder radius="0.00525" length="0.00525"/>
</geometry>
<material name="black"/>
</visual>
</link>
<link name="camera_link">
<visual>
<origin rpy="0.0 0 0" xyz="0 0 0"/>
<geometry>
<box size="0.0005 0.0005 0.0005"/>
</geometry>
<material name="green"/>
</visual>
</link>
</robot>
END mira_geometric.urdf
If we now execute the visualization launch for urdfs , you should have something similar to this:
[WARN] [1592297719.572633, 1233.241000]: The 'use_gui' parameter was specified, which is deprecated. We'll attempt
to find and run the GUI, but if this fails you should install the 'joint_state_publisher_gui' package instead and run that.
This backwards compatibility option will be removed in Noetic.
Remember to open the mira.rviz file you saved previously in the rviz_config folder.
In [ ]:
roscd mira_description
In [ ]:
cp ./models/mira/meshes/mira_body_v3.dae /home/user/catkin_ws/src/
In [ ]:
cp ./models/mira/meshes/mira_head_v5.dae /home/user/catkin_ws/src/
In [ ]:
cp ./models/mira/meshes/mira_eye_v4.dae /home/user/catkin_ws/src/
In [ ]:
roscd my_mira_description
In [ ]:
cd models;mkdir mira;cd mira;mkdir meshes
In [ ]:
<link name="base_link">
<visual>
<origin rpy="0.0 0 0" xyz="0 0 0"/>
<geometry>
<mesh filename="package://my_mira_description/models/mira/meshes/mira_body_v3.dae"/>
</geometry>
</visual>
</link>
Exercise U1-3
Replace the head, body, and eyes by their 3Dmeshes.
You will probably need to make some changes in the joint positions and orientations.
END Exercise U1-3
Solution Exercise U1-3
Please try to do it by yourself, unless you get stuck or need some inspiration. You will learn much
more if you fight for each exercise.
You should get the full model. Check that all of the limits are correct and that nothing is out of place.
A good practice is to put all of the joints in maximum and minimum positions, to see if everything is
okay.
roscd my_mira_description
touch urdf/mira_only_daes.urdf
mira_only_daes.urdf
In [ ]:
<?xml version="1.0"?>
<robot name="mira">
<material name="blue">
<color rgba="0 0 0.8 1"/>
</material>
<material name="red">
<color rgba="0.8 0 0 1"/>
</material>
<material name="green">
<color rgba="0 0.8 0 1"/>
</material>
<link name="roll_M1_link">
<visual>
<origin rpy="0 0 0" xyz="0 0 0"/>
<geometry>
<cylinder length="0.005" radius="0.01"/>
</geometry>
<material name="red"/>
</visual>
</link>
<!-- This is for color and physical properties in Gazebo, color won't work with the material tag in gazebo
only for URDF coloring -->
<gazebo reference="roll_M1_link">
<kp>1000.0</kp>
<kd>10.0</kd>
<mu1>10.0</mu1>
<mu2>10.0</mu2>
<material>Gazebo/Red</material>
</gazebo>
<link name="pitch_M2_link">
<visual>
<origin rpy="0 0 0" xyz="0 0 0"/>
<geometry>
<cylinder length="0.005" radius="0.01"/>
</geometry>
<material name="green"/>
</visual>
</link>
<!-- This is for color and physical properties in Gazebo, color won't work with the material tag in gazebo
only for URDF coloring -->
<gazebo reference="pitch_M2_link">
<kp>1000.0</kp>
<kd>10.0</kd>
<mu1>10.0</mu1>
<mu2>10.0</mu2>
<material>Gazebo/Green</material>
</gazebo>
<link name="yaw_M3_link">
<visual>
<origin rpy="0 0 0" xyz="0 0 0"/>
<geometry>
<cylinder length="0.005" radius="0.01"/>
</geometry>
<material name="blue"/>
</visual>
</link>
<!-- This is for color and physical properties in Gazebo, color won't work with the material tag in gazebo
only for URDF coloring -->
<gazebo reference="yaw_M3_link">
<kp>1000.0</kp>
<kd>10.0</kd>
<mu1>10.0</mu1>
<mu2>10.0</mu2>
<material>Gazebo/Blue</material>
</gazebo>
<link name="head_link">
<visual>
<origin rpy="0.0 0 0" xyz="0 0 0"/>
<geometry>
<mesh filename="package://my_mira_description/models/mira/meshes/mira_head_v5.dae"/>
</geometry>
</visual>
</link>
<link name="left_eye_link">
<visual>
<origin rpy="0.0 0 0" xyz="0 0 0"/>
<geometry>
<!--
<cylinder radius="0.00525" length="0.00525"/>
-->
<mesh filename="package://my_mira_description/models/mira/meshes/mira_eye_v4.dae"/>
</geometry>
</visual>
</link>
<link name="right_eye_link">
<visual>
<origin rpy="0.0 0 0" xyz="0 0 0"/>
<geometry>
<!--
<cylinder radius="0.00525" length="0.00525"/>
-->
<mesh filename="package://my_mira_description/models/mira/meshes/mira_eye_v4.dae"/>
</geometry>
</visual>
</link>
<link name="camera_link">
<visual>
<origin rpy="0.0 0 0" xyz="0 0 0"/>
<geometry>
<box size="0.0005 0.0005 0.0005"/>
</geometry>
<material name="green"/>
</visual>
</link>
<gazebo reference="camera_link">
<material>Gazebo/Green</material>
</gazebo>
</robot>
END mira_only_daes.urdf
If we now execute the visualization launch for urdfs , you should have something similar to this:
roslaunch my_mira_description urdf_visualize.launch model:='$(find my_mira_description)/urdf/mira_only_daes.urdf'
Remember to open the mira.rviz file you saved previously in the rviz_config folder.
You should have something like this:
For further details on all the options availabe in URDF, please refer to this
link: http://wiki.ros.org/urdf/XML/joint
Congratulations! You are now ready to learn how to spawn this URDF file into
Gazebo Simulator. Please proceed to Unit 2.