Unable to import xacro elements in urdf
Hello
I am trying to import the xacro file of the robotiq 2f85 gripper in my main urdf file. I would like to connect the base of the gripper robotiqarg2fbaselink to the end effector of my manipulator. When launching in Rviz, I do not get any warnings or errors and the gripper is not part of the link tree when checking tf.
As suggested on other questions, the most common method is to create another xacro file where I would link the main urdf and the gripper. But is this really necessary? I think I just have some trouble importing the xacro file the right way and I would like to maintain the main urdf file at the top level.
All help would me much appreciated!
This is the main urdf robot file acromobilemanipulator.xacro:
<?xml version="1.0"?>
<robot name = "acro_mobile_manipulator" xmlns:xacro="http://ros.org/wiki/xacro">
<!-- Rest of URDF (not xacro) -->
<!-- Gripper -->
<xacro:include filename="$(find robotiq_2finger_grippers)/robotiq_2f_85_gripper_visualization/urdf/robotiq_arg2f_85_model_macro.xacro" />
<xacro:robotiq_arg2f_85 prefix=""/>
<xacro:macro name="end_eff_gripper">
<joint name="end_eff_gripper" type="fixed">
<origin xyz="0 0 0" rpy="3.1415 0 0" />
<parent link="end_effector" />
<child link="robotiq_arg2f_base_link" />
<axis xyz="1 0 0" />
</joint>
</xacro:macro>
</robot>
Asked by student_Ros_melodic_mobile_manipulator on 2020-03-21 01:53:17 UTC
Answers
Your problem is most likely caused by this:
...
<xacro:robotiq_arg2f_85 prefix=""/>
<xacro:macro name="end_eff_gripper">
<joint name="end_eff_gripper" type="fixed">
<origin xyz="0 0 0" rpy="3.1415 0 0" />
<parent link="end_effector" />
<child link="robotiq_arg2f_base_link" />
<axis xyz="1 0 0" />
</joint>
</xacro:macro>
Before this snippet, you've xacro:include
d the file which defines the robotiq_arg2f_85
macro.
With <xacro:robotiq_arg2f_85 prefix=""/>
you "call" the macro, which causes the model it describes to be instantiated (ie: added to your scene).
With the <xacro:macro name="end_eff_gripper">
element (and its child elements), you create a new macro, called end_eff_gripper
. In that macro, you define a joint
, which will connect the end_effector
link with the robotiq_arg2f_base_link
one.
So far so good.
However -- and I'm going to assume this is everything you added -- your new macro is never actually called. You only define the macro, but don't instantiate it, leading to the end_eff_gripper
joint to never be added to the model which is defined in the file.
When launching in Rviz, I do not get any warnings or errors and the gripper is not part of the link tree when checking tf.
If by this, you mean "I see the links but they're not connected to the main tree", then I hope you now understand why that is.
As the end_eff_gripper
joint is never added to the model, there is no connection between the gripper and the robot.
You don't show us the TF tree, but I'm guessing you see two disconnected trees.
The solution would be to either:
- not wrap the
end_eff_gripper
joint in a macro, or if you really want to use the macro - call the macro after defining it (ie: add a
<xacro:end_eff_gripper />
)
Asked by gvdhoorn on 2020-03-21 06:13:44 UTC
Comments
Thank you for your answer! This helped me to better understand the xacro language.
*When launching in Rviz, I do not get any warnings or errors and the gripper is not part of the link tree when checking tf. *
By this I mean the gripper is not at all present in either Rviz or the tf tree. My apology for not giving more information about the code:
- The
end_effector
link is defined in the URDF above. - The
robotiq_arg2f_base_link
link is defined in the xacro file which I included. If I don't wrap the
end_eff_gripper
joint in a macro I get the following error:Failed to build tree: child link [robotiq_arg2f_base_link] of joint [end_eff_gripper] not found
If I call the macro after defining it as
<xacro:end_eff_gripper />
, nothing seems to change: the gripper is still not part of the tf tree and Rviz can start without any errors and the gripper is nowhere to be found.I will edit my question to include the tf tree (same for original and not using macro)
Asked by student_Ros_melodic_mobile_manipulator on 2020-03-21 10:56:34 UTC
I will edit my question to include the tf tree (same for original and not using macro)
--> I need 5 points to upload a file -_-
All I can say is that there is no single link of the gripper to be found in the tf tree. There are also not two separate trees, only the main one.
Thank you in advance for any help.
Asked by student_Ros_melodic_mobile_manipulator on 2020-03-21 10:59:18 UTC
Sollution:
forgot to add $(find xacro)/xacro --inorder
in front of the urdf/xacro load:
$(find xacro)/xacro --inorder $(find location)/urdf/name.urdf.xacro"
Asked by student_Ros_melodic_mobile_manipulator on 2020-05-05 11:19:43 UTC
Comments
of course not.
Neither is using
xacro
. We could just put everything in a single file and duplicate blocks of URDF wherever we need them and then manually update all references to make sure we don't have any name clashes. Whenever you want to change something structurally in one of those blocks, make sure to copy-paste those changes to all the other locations you use that same block, and then don't forget to update all the references/names again.Whether something is "really necessary" is not always the best question to ask when trying to determine whether something should be done.
I've exaggerated somewhat in my comment above of course, but using tools like
xacro
allows us to cleanly separate parts that don't absolutely need to be stored in the same file.This modularity then makes it much easier ..
Asked by gvdhoorn on 2020-03-21 06:05:26 UTC
.. to reuse parts, to make changes to parts that automatically get included in the larger composite, facilitating maintenance, etc, etc.
That's the reason we split up programs (ie:
.cpp
,.py
, etc) instead of merging everything into a single file -- which would certainly be possible. That's the reason we create libraries and ROS packages.Not because it's absolutely necessary, but because it offers us a lot of advantages, and we'd like to benefit from those advantages.
Asked by gvdhoorn on 2020-03-21 06:07:25 UTC