sdformat icon indicating copy to clipboard operation
sdformat copied to clipboard

URDF->SDF conversion: surface properties are only retained for nameless collisions and collisions named `$LINKNAME_collision`

Open peci1 opened this issue 3 years ago • 1 comments

test.urdf:

<robot name="test">
        <link name="root">
                <inertial>
                        <origin rpy="0 0 0" xyz="0 0 0"/>
                        <mass value="1e-5"/>
                        <inertia ixx="1e-3" ixy="1e-6" ixz="1e-6" iyy="1e-3" iyz="1e-6" izz="1e-3"/>
                </inertial>
                <collision name="root_collision">
                        <geometry><cylinder length="1.0" radius="1.0" /></geometry>
                </collision>
        </link>
        <gazebo reference="root">
                <collision>
                        <surface><contact><ode><kp>5.0</kp></ode></contact></surface>
                </collision>
        </gazebo>
</robot>

If I convert this URDF to SDF (using sdformat 8), I end up with:

<sdf version='1.6'>
  <model name='test'>
    <link name='root'>
      <pose>0 0 0 0 -0 0</pose>
      <inertial>
        <pose>0 0 0 0 -0 0</pose>
        <mass>1e-05</mass>
        <inertia>
          <ixx>0.001</ixx>
          <ixy>1e-06</ixy>
          <ixz>1e-06</ixz>
          <iyy>0.001</iyy>
          <iyz>1e-06</iyz>
          <izz>0.001</izz>
        </inertia>
      </inertial>
      <collision name='root_collision_collision'>
        <pose>0 0 0 0 -0 0</pose>
        <geometry>
          <cylinder>
            <length>1</length>
            <radius>1</radius>
          </cylinder>
        </geometry>
        <surface>
          <contact>
            <ode>
              <kp>5</kp>
            </ode>
          </contact>
          <friction>
            <ode/>
          </friction>
        </surface>
      </collision>
      <gravity>1</gravity>
      <velocity_decay/>
    </link>
  </model>
</sdf>

That is correct. The same result is achieved when the collision in URDF has no name. However, If I set the collision name to anything else, the surface tags are left out (even though there is only a single collision):

<sdf version='1.6'>
  <model name='test'>
    <link name='root'>
      <pose>0 0 0 0 -0 0</pose>
      <inertial>
        <pose>0 0 0 0 -0 0</pose>
        <mass>1e-05</mass>
        <inertia>
          <ixx>0.001</ixx>
          <ixy>1e-06</ixy>
          <ixz>1e-06</ixz>
          <iyy>0.001</iyy>
          <iyz>1e-06</iyz>
          <izz>0.001</izz>
        </inertia>
      </inertial>
      <collision name='root_fixed_joint_lump__asd_collision'>
        <pose>0 0 0 0 -0 0</pose>
        <geometry>
          <cylinder>
            <length>1</length>
            <radius>1</radius>
          </cylinder>
        </geometry>
      </collision>
      <gravity>1</gravity>
      <velocity_decay/>
    </link>
  </model>
</sdf>

I get it that if there are multiple collisions, the gazebo tag has to reference them exactly by their name. But when there is a single collision, It'd make sense to me if the conversion script applied the collision tag contents to it.

And what would be the correct name to reference in the gazebo tag? For collision named asd, I tried root_fixed_joint_lump__asd, root_fixed_joint_lump__asd_collision and root_fixed_joint_lump__asd_collision_collision, but none works.

peci1 avatar Aug 07 '20 13:08 peci1

This issue breaks using because the collision element is renamed.

For example, the following URDF does not work (although correct)

<?xml version="1.0"?>
<robot name="testbot">
  <link name="base">
    <visual>
      <geometry>
        <box size="1 1 1"/>
      </geometry>
      <origin xyz="0 0 0.5" rpy="0 0 0"/>
    </visual>
    <collision name='collision'>
      <geometry>
        <box size="1 1 1"/>
      </geometry>
      <origin xyz="0 0 0.5" rpy="0 0 0"/>
    </collision>
    <inertial>
      <origin xyz="0 0 0.5" rpy="0 0 0"/>
      <mass value="1"/>
      <inertia ixx="0.16"  ixy="0"  ixz="0" iyy="0.16" iyz="0" izz="0.16" />
    </inertial>
  </link>

  <gazebo reference="base">
    <sensor name='sensor_contact' type='contact'>
      <contact>
          <collision>collision</collision>
      </contact>
    </sensor>
  </gazebo>
</robot>

The issue becomes apparent when converting it to SDF, via ign sdf -p:

<sdf version='1.9'>
  <model name='testbot'>
    <link name='base'>
      <inertial>
        <pose>0 0 0.5 0 0 0</pose>
        <mass>1</mass>
        <inertia>
          <ixx>0.16</ixx>
          <ixy>0</ixy>
          <ixz>0</ixz>
          <iyy>0.16</iyy>
          <iyz>0</iyz>
          <izz>0.16</izz>
        </inertia>
      </inertial>
      <collision name='base_fixed_joint_lump__collision_collision'>
        <pose>0 0 0.5 0 0 0</pose>
        <geometry>
          <box>
            <size>1 1 1</size>
          </box>
        </geometry>
      </collision>
      <visual name='base_visual'>
        <pose>0 0 0.5 0 0 0</pose>
        <geometry>
          <box>
            <size>1 1 1</size>
          </box>
        </geometry>
      </visual>
      <sensor name='sensor_contact' type='contact'>
        <contact>
          <collision>collision</collision>
          <topic>__default_topic__</topic>
        </contact>
      </sensor>
    </link>
  </model>
</sdf>

The problem is <sensor type='contact'><contact><collision> still referring to collision, while the actual element has been renamed to base_fixed_joint_lump__collision_collision.

andreasBihlmaier avatar Aug 15 '23 21:08 andreasBihlmaier