My Robotic Manipulator – Introduction
Hey ROS developers! In this post, we start working on our own robotic manipulator. Based on the YouTube video series, we’ll show in this format the steps to achieve the final result of the series!
In this post number #2, I’m gonna show how to use XACROs in order to simplify a URDF file. Up to the end of the post, we’ll have the complete model of the robot, which includes 6 links in total, and visualize it in RViz!
.
Step 1 – Create some MACROs to help
First things first! We have already created some links and a joint. We need now to create more of them, but let’s try to make it simplers, more clean in our XACRO file.
Let’s create a new file, ~/simulation_ws/src/mrm_description/urdf/links_joints.xacro
In this file we are gonna create MACROs. They will help us creating links and joints. Check below:
<?xml version="1.0" ?> <robot xmlns:xacro="http://www.ros.org/wiki/xacro"> <xacro:macro name="m_joint" params="name type axis_xyz origin_rpy origin_xyz parent child"> <joint name="${name}" type="${type}"> <axis xyz="${axis_xyz}" /> <limit effort="1000.0" lower="-3.14" upper="3.14" velocity="0.5" /> <origin rpy="${origin_rpy}" xyz="${origin_xyz}" /> <parent link="${parent}" /> <child link="${child}" /> </joint> </xacro:macro> <xacro:macro name="m_link_cylinder" params="name origin_xyz origin_rpy radius length"> <link name="${name}"> <visual> <origin rpy="${origin_rpy}" xyz="${origin_xyz}" /> <geometry> <cylinder radius="${radius}" length="${length}" /> </geometry> </visual> </link> </xacro:macro> <xacro:macro name="m_link_box" params="name origin_xyz origin_rpy size"> <link name="${name}"> <visual> <origin rpy="${origin_rpy}" xyz="${origin_xyz}" /> <geometry> <box size="${size}" /> </geometry> </visual> </link> </xacro:macro> </robot>
What do we have there?
We have 3 MACROs created. Each one with a name defined in the attribute name of the tags xacro:macro. The next attribute is used to defined the parameters we want to make available in a MACRO.
These parameters are used in the following format: ${param_name}
Let’s check how to use them!
Step 2 – Using our XML MACROs
In our main file, ~/simulation_ws/src/mrm_description/urdf/mrm.xacro, we have to include this new XACRO file. Let’s rewrite it!
<?xml version="1.0" ?> <robot name="mrm" xmlns:xacro="http://www.ros.org/wiki/xacro"> <!-- BGN - Include --> <xacro:include filename="$(find mrm_description)/urdf/links_joints.xacro" /> <!-- END - Include --> <!-- BGN - Robot description --> <m_link_box name="base_link" origin_rpy="0 0 0" origin_xyz="0 0 0" size="1 1 1" /> <m_joint name="base_link_01" type="revolute" axis_xyz="0 0 1" origin_rpy="0 0 0" origin_xyz="0 0 0.5" parent="base_link" child="link_01" /> <m_link_cylinder name="link_01" origin_rpy="0 0 0" origin_xyz="0 0 0.2" length="0.4" radius="0.35" /> <!-- END - Robot description --> </robot>
At this point we have used the MACROs we have just defined and must have the very same model as before. Check it on RViz:
roslaunch mrm_description rviz.launch
Step 3 – Using multiple MACRO files
In order to get used working with MACRO files, let’s create another one. This new file will only define the name of the links and joints we are gonna have! (Let’s play around)
Create a new file ~/simulation_ws/src/mrm_description/urdf/robot_parameters.xacro
The content must be:
<?xml version="1.0" ?> <robot xmlns:xacro="http://www.ros.org/wiki/xacro"> <xacro:property name="link_00_name" value="base_link" /> <xacro:property name="link_01_name" value="link_01" /> <xacro:property name="link_02_name" value="link_02" /> <xacro:property name="link_03_name" value="link_03" /> <xacro:property name="link_04_name" value="link_04" /> <xacro:property name="link_05_name" value="link_05" /> </robot>
And include it in the main file mrm.xacro (just appending a new include to the INCLUDE section):
<!-- BGN - Include --> <xacro:include filename="$(find mrm_description)/urdf/links_joints.xacro" /> <xacro:include filename="$(find mrm_description)/urdf/robot_parameters.xacro" /> <!-- END - Include -->
Finally, replace the names in the links and joints by the values we imported from the parameters file. You must have the description part like below:
<!-- BGN - Robot description --> <m_link_box name="${link_00_name}" origin_rpy="0 0 0" origin_xyz="0 0 0" size="1 1 1" /> <m_joint name="${link_00_name}__${link_01_name}" type="revolute" axis_xyz="0 0 1" origin_rpy="0 0 0" origin_xyz="0 0 0.5" parent="${link_00_name}" child="${link_01_name}" /> <m_link_cylinder name="${link_01_name}" origin_rpy="0 0 0" origin_xyz="0 0 0.2" length="0.4" radius="0.35" /> <!-- END - Robot description -->
We are using the parameters not only to fill the name of the links, but also to compose the joint name!
Step 4 – Finishing the robot
Let’s create the rest of the robot! We have no big deal from now on, after all we have already defined the MACROs and link names. We only need to reuse them passing some arguments!
Let’s check how it will be:
<!-- BGN - Robot description --> <m_link_box name="${link_00_name}" origin_rpy="0 0 0" origin_xyz="0 0 0" size="1 1 1" /> <m_joint name="${link_00_name}__${link_01_name}" type="revolute" axis_xyz="0 0 1" origin_rpy="0 0 0" origin_xyz="0 0 0.5" parent="${link_00_name}" child="${link_01_name}" /> <m_link_cylinder name="${link_01_name}" origin_rpy="0 0 0" origin_xyz="0 0 0.2" length="0.4" radius="0.35" /> <m_joint name="${link_01_name}__${link_02_name}" type="revolute" axis_xyz="0 1 0" origin_rpy="0 0 0" origin_xyz="0 0 0.4" parent="${link_01_name}" child="${link_02_name}" /> <m_link_cylinder name="${link_02_name}" origin_rpy="0 0 0" origin_xyz="0 0 0.4" radius="0.15" length="0.8" /> <m_joint name="${link_02_name}__${link_03_name}" type="revolute" axis_xyz="0 1 0" origin_rpy="0 0 0" origin_xyz="0 0 0.8" parent="${link_02_name}" child="${link_03_name}" /> <m_link_cylinder name="${link_03_name}" origin_rpy="0 0 0" origin_xyz="0 0 0.4" radius="0.15" length="0.8" /> <m_joint name="${link_03_name}__${link_04_name}" type="revolute" axis_xyz="0 1 0" origin_rpy="0 0 0" origin_xyz="0 0 0.8" parent="${link_03_name}" child="${link_04_name}" /> <m_link_cylinder name="${link_04_name}" origin_rpy="0 0 0" origin_xyz="0 0 0.4" radius="0.15" length="0.8" /> <m_joint name="${link_04_name}__${link_05_name}" type="revolute" axis_xyz="0 0 1" origin_rpy="0 0 0" origin_xyz="0 0 0.8" parent="${link_04_name}" child="${link_05_name}" /> <m_link_cylinder name="${link_05_name}" origin_rpy="0 0 0" origin_xyz="0 0 0.125" radius="0.15" length="0.25" /> <!-- END - Robot description -->
You can explore and play with the parameters (radius and lenth, for example) in order to customize your own model.
Let’s check it on RViz:
roslaunch mrm_description rviz.launch
Related courses
Conclusion
We have created the rest of the visual part of the robot using XACROs! Much easier!
In the next post, we’ll create the inertiaof the robot. A very important step to have it working in Gazebo!
If you lost any part of the tutorial, you can get a copy of the ROSject I’ve done clicking here!
See you!
0 Comments