Assembling the URDF
The ur_description package provides macro files to generate an instance of a Universal Robots arm. We’ll use this to create a custom workcell with two robots in it, both a UR3e (called Alice) and a UR5e (called Bob). In this section we will only go into detail about the URDF / xacro files, not the complete package structure. Please see the description package source code for all other files assembling the description package.
Workcell description
1<?xml version="1.0"?>
2<robot name="my_dual_robot_cell" xmlns:xacro="http://ros.org/wiki/xacro">
3
4 <xacro:include filename="$(find my_dual_robot_cell_description)/urdf/my_dual_robot_cell_macro.xacro"/>
5
6 <xacro:arg name="alice_ur_type" default="ur3e"/>
7 <xacro:arg name="alice_joint_limits_parameters_file" default="$(find ur_description)/config/$(arg alice_ur_type)/joint_limits.yaml"/>
8 <xacro:arg name="alice_kinematics_parameters_file" default="$(find ur_description)/config/$(arg alice_ur_type)/default_kinematics.yaml"/>
9 <xacro:arg name="alice_physical_parameters_file" default="$(find ur_description)/config/$(arg alice_ur_type)/physical_parameters.yaml"/>
10 <xacro:arg name="alice_visual_parameters_file" default="$(find ur_description)/config/$(arg alice_ur_type)/visual_parameters.yaml"/>
11
12 <xacro:arg name="bob_ur_type" default="ur5e"/>
13 <xacro:arg name="bob_joint_limits_parameters_file" default="$(find ur_description)/config/$(arg bob_ur_type)/joint_limits.yaml"/>
14 <xacro:arg name="bob_kinematics_parameters_file" default="$(find ur_description)/config/$(arg bob_ur_type)/default_kinematics.yaml"/>
15 <xacro:arg name="bob_physical_parameters_file" default="$(find ur_description)/config/$(arg bob_ur_type)/physical_parameters.yaml"/>
16 <xacro:arg name="bob_visual_parameters_file" default="$(find ur_description)/config/$(arg bob_ur_type)/visual_parameters.yaml"/>
17
18 <link name="world"/>
19 <!--This will create the scene where the robots are located in-->
20 <xacro:my_dual_robot_cell
21 parent="world"
22
23 alice_ur_type="$(arg alice_ur_type)"
24 alice_joint_limits_parameters_file="$(arg alice_joint_limits_parameters_file)"
25 alice_kinematics_parameters_file="$(arg alice_kinematics_parameters_file)"
26 alice_physical_parameters_file="$(arg alice_physical_parameters_file)"
27 alice_visual_parameters_file="$(arg alice_visual_parameters_file)"
28
29 bob_ur_type="$(arg bob_ur_type)"
30 bob_joint_limits_parameters_file="$(arg bob_joint_limits_parameters_file)"
31 bob_kinematics_parameters_file="$(arg bob_kinematics_parameters_file)"
32 bob_physical_parameters_file="$(arg bob_physical_parameters_file)"
33 bob_visual_parameters_file="$(arg bob_visual_parameters_file)"
34 >
35 <origin xyz="0 0 1" rpy="0 0 0" />
36 </xacro:my_dual_robot_cell>
37
38</robot>
Let’s break it down:
First, we’ll have to include the macro to generate our custom workcell:
<xacro:include filename="$(find my_dual_robot_cell_description)/urdf/my_dual_robot_cell_macro.xacro"/>
This line only loads the macro for generating the robot workcell.
We will need to provide some parameters to our workcell in order to parametrize the arms. Therefore, we need to declare certain arguments that must be passed to the macro.
<xacro:arg name="alice_ur_type" default="ur3e"/>
<xacro:arg name="alice_joint_limits_parameters_file" default="$(find ur_description)/config/$(arg alice_ur_type)/joint_limits.yaml"/>
<xacro:arg name="alice_kinematics_parameters_file" default="$(find ur_description)/config/$(arg alice_ur_type)/default_kinematics.yaml"/>
<xacro:arg name="alice_physical_parameters_file" default="$(find ur_description)/config/$(arg alice_ur_type)/physical_parameters.yaml"/>
<xacro:arg name="alice_visual_parameters_file" default="$(find ur_description)/config/$(arg alice_ur_type)/visual_parameters.yaml"/>
<xacro:arg name="bob_ur_type" default="ur5e"/>
<xacro:arg name="bob_joint_limits_parameters_file" default="$(find ur_description)/config/$(arg bob_ur_type)/joint_limits.yaml"/>
<xacro:arg name="bob_kinematics_parameters_file" default="$(find ur_description)/config/$(arg bob_ur_type)/default_kinematics.yaml"/>
<xacro:arg name="bob_physical_parameters_file" default="$(find ur_description)/config/$(arg bob_ur_type)/physical_parameters.yaml"/>
<xacro:arg name="bob_visual_parameters_file" default="$(find ur_description)/config/$(arg bob_ur_type)/visual_parameters.yaml"/>
The workspace macro contains all items within the workcell including the robot arm. If you are not experienced in writing URDFs, you may want to refer to this tutorial. The macro’s content is generated using
<link name="world"/>
<!--This will create the scene where the robots are located in-->
<xacro:my_dual_robot_cell
parent="world"
alice_ur_type="$(arg alice_ur_type)"
alice_joint_limits_parameters_file="$(arg alice_joint_limits_parameters_file)"
alice_kinematics_parameters_file="$(arg alice_kinematics_parameters_file)"
alice_physical_parameters_file="$(arg alice_physical_parameters_file)"
alice_visual_parameters_file="$(arg alice_visual_parameters_file)"
bob_ur_type="$(arg bob_ur_type)"
bob_joint_limits_parameters_file="$(arg bob_joint_limits_parameters_file)"
bob_kinematics_parameters_file="$(arg bob_kinematics_parameters_file)"
bob_physical_parameters_file="$(arg bob_physical_parameters_file)"
bob_visual_parameters_file="$(arg bob_visual_parameters_file)"
>
<origin xyz="0 0 1" rpy="0 0 0" />
</xacro:my_dual_robot_cell>
Here, a world link is created, and the robot workcell is created relative to the world link.
Workcell macro
The workcell macro is defined in the following manner:
1<?xml version="1.0"?>
2<robot xmlns:xacro="http://ros.org/wiki/xacro">
3 <xacro:include filename="$(find ur_description)/urdf/ur_macro.xacro"/>
4
5 <xacro:macro name="my_dual_robot_cell" params="
6 parent
7 *origin
8
9 alice_ur_type
10 alice_joint_limits_parameters_file
11 alice_kinematics_parameters_file
12 alice_physical_parameters_file
13 alice_visual_parameters_file
14
15 bob_ur_type
16 bob_joint_limits_parameters_file
17 bob_kinematics_parameters_file
18 bob_physical_parameters_file
19 bob_visual_parameters_file
20 ">
21
22 <joint name="table_base_joint" type="fixed">
23 <xacro:insert_block name="origin" />
24 <parent link="${parent}" />
25 <child link="table" />
26 </joint>
27
28 <link name="table">
29 <visual>
30 <geometry>
31 <mesh filename="package://my_robot_cell_description/meshes/fzi_table.dae"/>
32 </geometry>
33 <origin rpy="0 0 0" xyz="0.75 0.5 -1"/>
34 </visual>
35 <collision>
36 <geometry>
37 <mesh filename="package://my_robot_cell_description/meshes/fzi_table.dae"/>
38 </geometry>
39 <origin rpy="0 0 0" xyz="0.75 0.5 -1"/>
40 </collision>
41 </link>
42
43 <link name="monitor">
44 <visual>
45 <geometry>
46 <mesh filename="package://my_robot_cell_description/meshes/171005_Motek_Monitor_L.dae"/>
47 </geometry>
48 </visual>
49 <collision>
50 <geometry>
51 <mesh filename="package://my_robot_cell_description/meshes/171005_Motek_Monitor_L.dae"/>
52 </geometry>
53 </collision>
54 </link>
55 <joint name="base_to_monitor" type="fixed">
56 <parent link="table"/>
57 <child link="monitor"/>
58 <origin xyz="0.2 0.6 0"/>
59 </joint>
60
61 <material name="white">
62 <color rgba="1 1 1 1"/>
63 </material>
64
65 <link name="wall">
66 <visual>
67 <geometry>
68 <mesh filename="package://my_robot_cell_description/meshes/wall.dae"/>
69 </geometry>
70 </visual>
71 <collision>
72 <geometry>
73 <box size="4.44 0.1 2.5"/>
74 </geometry>
75 </collision>
76 </link>
77 <joint name="base_to_wall" type="fixed">
78 <parent link="table"/>
79 <child link="wall"/>
80 <origin xyz="1.25 1.5 0.5"/>
81 </joint>
82
83
84 <!--Creates the mounts to attach the robots to the table-->
85 <link name="alice_robot_mount"/>
86 <joint name="base_to_alice_robot_mount" type="fixed">
87 <parent link="table"/>
88 <child link="alice_robot_mount"/>
89 <origin xyz="0.2 0.3 0" rpy="0 0 ${pi}" />
90 </joint>
91
92 <link name="bob_robot_mount"/>
93 <joint name="base_to_bob_robot_mount" type="fixed">
94 <parent link="table"/>
95 <child link="bob_robot_mount"/>
96 <origin xyz="1.2 0.3 0" rpy="0 0 ${pi}" />
97 </joint>
98
99 <!--Creates the 1st Robot-->
100 <xacro:ur_robot
101 name="alice"
102 tf_prefix="alice_"
103 parent="alice_robot_mount"
104 joint_limits_parameters_file="${alice_joint_limits_parameters_file}"
105 kinematics_parameters_file="${alice_kinematics_parameters_file}"
106 physical_parameters_file="${alice_physical_parameters_file}"
107 visual_parameters_file="${alice_visual_parameters_file}"
108 >
109 <origin xyz="0 0 0" rpy="0 0 0" />
110 </xacro:ur_robot>
111
112 <!--Creates the 2nd Robot-->
113 <xacro:ur_robot
114 name="bob"
115 tf_prefix="bob_"
116 parent="bob_robot_mount"
117 joint_limits_parameters_file="${bob_joint_limits_parameters_file}"
118 kinematics_parameters_file="${bob_kinematics_parameters_file}"
119 physical_parameters_file="${bob_physical_parameters_file}"
120 visual_parameters_file="${bob_visual_parameters_file}"
121 >
122 <origin xyz="0 0 0" rpy="0 0 0" />
123 </xacro:ur_robot>
124
125 </xacro:macro>
126
127</robot>
This macro provides an example of what a custom workcell could resemble. Your workspace will likely vary from this one. Please feel free to modify this portion of the URDF to match your own setup. In this instance, our workspace comprises a table in front of a wall, featuring a monitor, and the two robot arms mounted on top.
Ensure that your custom workcell includes the parent link, which must be passed to the ur_robot macro. In this example, we chose to create two links, one named alice_robot_mount and one named bob_robot_mount.
1 <link name="alice_robot_mount"/>
2 <joint name="base_to_alice_robot_mount" type="fixed">
3 <parent link="table"/>
4 <child link="alice_robot_mount"/>
5 <origin xyz="0.2 0.3 0" rpy="0 0 ${pi}" />
6 </joint>
7
8 <link name="bob_robot_mount"/>
9 <joint name="base_to_bob_robot_mount" type="fixed">
10 <parent link="table"/>
11 <child link="bob_robot_mount"/>
12 <origin xyz="1.2 0.3 0" rpy="0 0 ${pi}" />
13 </joint>
After that we are finally able to actually create the robot arms by calling the macro.
1 <!--Creates the 1st Robot-->
2 <xacro:ur_robot
3 name="alice"
4 tf_prefix="alice_"
5 parent="alice_robot_mount"
6 joint_limits_parameters_file="${alice_joint_limits_parameters_file}"
7 kinematics_parameters_file="${alice_kinematics_parameters_file}"
8 physical_parameters_file="${alice_physical_parameters_file}"
9 visual_parameters_file="${alice_visual_parameters_file}"
10 >
11 <origin xyz="0 0 0" rpy="0 0 0" />
12 </xacro:ur_robot>
13
14 <!--Creates the 2nd Robot-->
15 <xacro:ur_robot
16 name="bob"
17 tf_prefix="bob_"
18 parent="bob_robot_mount"
19 joint_limits_parameters_file="${bob_joint_limits_parameters_file}"
20 kinematics_parameters_file="${bob_kinematics_parameters_file}"
21 physical_parameters_file="${bob_physical_parameters_file}"
22 visual_parameters_file="${bob_visual_parameters_file}"
23 >
24 <origin xyz="0 0 0" rpy="0 0 0" />
25 </xacro:ur_robot>
Note that the origin argument is transmitted in a different manner than the other arguments.
Before we can test our code, it’s essential to build and source our Colcon workspace:
#cd to your colcon workspace root
cd ~/colcon_ws
#source and build your workspace
colcon build
source install/setup.bash
We can view our custom workspace by running:
#launch rviz
ros2 launch my_dual_robot_cell_description view_robot.launch.py
Use the sliders of the joint_state_puplisher_gui to move the virtual robots around.
It should look something like this: