URDF xacro-defined links not appearing in RViz2 (ROS2)

asked 2020-06-22 09:41:26 -0500

anthares gravatar image

Hello everyone,

I am building a very simple URDF model. I am using Rviz2 to test it and display it in this phase, but I can see only the main body.

I have the main model body defined in one file:

<?xml version="1.0" ?>
<robot xmlns:xacro="http://ros.org/wiki/xacro" name="mymodel">
    <xacro:include filename="$(find mymodel_descriptions)/urdf/library.xacro'" />

    <link name="body_link">
        <visual>
            <origin xyz="0 0 0" rpy="1.5707963267949 0 3.14" />
            <geometry>
                <mesh filename="package://mymodel_descriptions/meshes/body.stl" />
            </geometry>
            <material name="">
                <color rgba="0.79216 0.81961 0.93333 1" />
            </material>
        </visual>
    </link>

    <xacro:robot_wheel prefix="front_left" />
    <xacro:robot_wheel prefix="front_right" />
    <xacro:robot_wheel prefix="rear_left" />
    <xacro:robot_wheel prefix="rear_right" />

    <xacro:wheel_joint prefix="front_left" origin="0.220 0.250 0"/>
    <xacro:wheel_joint prefix="front_right" origin="0.220 -0.250 0"/>
    <xacro:wheel_joint prefix="rear_left" origin="-0.220 0.250 0"/>
    <xacro:wheel_joint prefix="rear_right" origin="-0.220 -0.250 0"/>
</robot>

and I have a very simple xacro - the one included at the top of the first file - that looks as it follows:

<?xml version="1.0" ?>
<robot xmlns:xacro="http://ros.org/wiki/xacro" name="library">
    <xacro:macro name="robot_wheel" params="prefix">
        <link name="${prefix}_wheel">
            <visual>
                <origin xyz="0 0 0" rpy="1.5707963267949 0 0" />
                <geometry>
                    <mesh filename="package://mymodel_descriptions/meshes/wheel.stl" />
                </geometry>
                <material name="">
                    <color rgba="0.79216 0.81961 0.93333 1" />
                </material>
            </visual>
        </link>
    </xacro:macro>

    <xacro:macro name="wheel_joint" params="prefix origin">
        <joint name="${prefix}_wheel_joint" type="continuous">
            <axis xyz="0 1 0" />
            <parent link ="body_link" />
            <child link ="${prefix}_wheel" />
            <origin rpy ="0 0 0" xyz= "${origin}"/>
        </joint>
    </xacro:macro>
</robot>

Any idea on what's wrong here?

Thanks in advance, Cheers, Anthares

edit retag flag offensive close merge delete

Comments

Did you actually run xacro to generate the complete urdf file?

Edit: asking since xacro is not in the main repositories yet for foxy.

Mbuijs gravatar image Mbuijs  ( 2020-06-23 07:34:58 -0500 )edit

You were right, I got now the code from git and added it to my packages. It works great for the generation bit. I was surprised still not to see the wheels: I guess it is because I didnt have launch file that loads the robot_state_publisher and the joint_state_publisher. Am I right? As for xacro, I dont have those two packages in foxy. I assume that I will have to do the same (install them manually?). thanks!

anthares gravatar image anthares  ( 2020-06-23 14:09:26 -0500 )edit

Xacro should be available in foxy now: https://discourse.ros.org/t/new-packa...

Mbuijs gravatar image Mbuijs  ( 2020-06-26 02:15:07 -0500 )edit