The code used in this tutorial is available!
Code can be found at industrial_training repository in doc folder. Use kinetic-devel branch.
Workcell XACRO¶
In this exercise, we will create an XACRO file representing a simple robot workcell. This will demonstrate both URDF and XACRO elements.
Motivation¶
Writing URDFs that involve more than just a few elements can quickly become a pain. Your file gets huge and duplicate items in your workspace means copy-pasting a bunch of links and joints while having to change their names just slightly. It’s really easy to make a mistake that may (or may not) be caught at startup. It’d be nice if we could take some guidance from programming languages themselves: define a component once, then re-use it anywhere without excessive duplication. Functions and classes do that for programs, and XACRO macros do that for URDFs. XACRO has other cool features too, like a file include system (think #include), constant variables, math expression evaluation (e.g., say PI/2.0 instead of 1.57), and more.
Reference Example¶
Further Information and Resources¶
Scan-N-Plan Application: Problem Statement¶
In the previous exercise we created a workcell consisting of only static geometry. In this exercise, we'll add a UR5 robot assembly using XACRO tools.
Specifically, you will need to:
- Convert the
*.urdffile you created in the previous sample into a XACRO file with thexacroextension. - Include a file containing the xacro-macro definition of a
UR5 - Instantiate a
UR5in your workspace and connect it to the table link.
Scan-N-Plan Application: Guidance¶
Rename the
workcell.urdffile from the previous exercise toworkcell.xacroBring in the
ur_descriptionpackage into your ROS environment. You have a few options:You can install the debian packages:
sudo apt install ros-kinetic-universal-robotThis has not yet been released, but will work later...
You can clone it from GitHub to your catkin workspace:
cd ~/catkin_ws/src git clone https://github.com/ros-industrial/universal_robot.git catkin build source ~/catkin_ws/devel/setup.bash
It’s not uncommon for description packages to put each “module”, “part”, or “assembly” into its own file. In many cases, a package will also define extra files that define a complete cell with the given part so that we can easily visually inspect the result. The UR package defines such a file for the UR5 (ur5_robot.urdf.xacro): It’s a great example for this module.
Locate the xacro file that implements the UR5 macro and include it in your newly renamed
workcell.xacrofile. Add this include line near the top of yourworkcell.xacrofile, beneath the<robot>tag:<xacro:include filename="$(find ur_description)/urdf/ur5.urdf.xacro" />
If you explore the UR5 definition file, or just about any other file that defines a Xacro macro, you’ll find a lot of uses of
${prefix}in element names. Xacro evaluates anything inside a “${}” at run-time. It can do basic math, and it can look up variables that come to it via properties (ala-global variables) or macro parameters. Most macros will take a “prefix” parameter to allow a user to create multiple instances of said macro. It’s the mechanism by which we can make the eventual URDF element names unique, otherwise we’d get duplicate link names and URDF would complain.Including the
ur5.urdf.xacrofile does not actually create a UR5 robot in our URDF model. It defines a macro, but we still need to call the macro to create the robot links and joints. Note the use of theprefixtag, as discussed above.<xacro:ur5_robot prefix="" joint_limited="true"/>
Macros in Xacro are just fancy wrappers around copy-paste. You make a macro and it gets turned into a chunk of links and joints. You still have to connect the rest of your world to that macro’s results. This means you have to look at the macro and see what the base link is and what the end link is. Hopefully your macro follows a standard, like the ROS-Industrial one, that says that base links are named “base_link” and the last link is called “tool0”.
Connect the UR5
base_linkto your existing static geometry with a fixed link.<joint name="table_to_robot" type="fixed"> <parent link="table"/> <child link="base_link"/> <origin xyz="0 0 0" rpy="0 0 0"/> </joint>
Create a new
urdf.launchfile (in themyworkcell_supportpackage) to load the URDF model and (optionally) display it in rviz:<launch> <arg name="gui" default="true"/> <param name="robot_description" command="$(find xacro)/xacro --inorder '$(find myworkcell_support)/urdf/workcell.xacro'" /> <node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher"/> <node name="joint_state_publisher" pkg="joint_state_publisher" type="joint_state_publisher"> <param name="use_gui" value="$(arg gui)"/> </node> <node name="rviz" pkg="rviz" type="rviz" if="$(arg gui)"/> </launch>
Check the updated URDF in RViz, using the launch file you just created:
roslaunch myworkcell_support urdf.launch- Set the 'Fixed Frame' to 'world' and add the RobotModel and TF displays to the tree view on the left, to show the robot and some transforms.
- Try moving the joint sliders to see the UR5 robot move.
Open Source Feedback
See something that needs improvement? Please open a pull request on this GitHub page