Unity-Technologies / URDF-Importer

URDF importer
Apache License 2.0
214 stars 71 forks source link

Loading non-fixed joint without inertial child throws "MissingComponentException" #217

Open joaomacp opened 1 year ago

joaomacp commented 1 year ago

Describe the bug When loading a Revolute or Prismatic joint where the child link is missing <inertial> tags, a MissingComponentException exception is thrown.

To Reproduce Steps to reproduce the behavior:

  1. Load the example URDF below using URDF-Importer
  2. The program crashes and a MissingComponentException is thrown: There is no 'ArticulationBody' attached to the "linkB" game object, but a script is trying to access it.
  3. Uncommenting the <inertial> block loads the URDF correctly.

Console logs / stack traces

UnityEngine.MissingComponentException: There is no 'ArticulationBody' attached to the "linkB" game object, but a script is trying to access it.
You probably need to add a ArticulationBody to the game object "linkB". Or your script needs to check if the component is attached before using it.
  at (wrapper managed-to-native) UnityEngine.ArticulationBody.set_jointType(UnityEngine.ArticulationBody,UnityEngine.ArticulationJointType)
  at Unity.Robotics.UrdfImporter.UrdfJointRevolute.Create (UnityEngine.GameObject linkObject) [0x00012] in Library/PackageCache/com.unity.robotics.urdf-importer@9956ce5368/Runtime/UrdfComponents/UrdfJoints/UrdfJointRevolute.cs:28 
  at Unity.Robotics.UrdfImporter.UrdfJoint.AddCorrectJointType (UnityEngine.GameObject linkObject, Unity.Robotics.UrdfImporter.UrdfJoint+JointTypes jointType) [0x00034] in /Library/PackageCache/com.unity.robotics.urdf-importer@9956ce5368/Runtime/UrdfComponents/UrdfJoints/UrdfJoint.cs:113 
  at Unity.Robotics.UrdfImporter.UrdfJoint.Create (UnityEngine.GameObject linkObject, Unity.Robotics.UrdfImporter.UrdfJoint+JointTypes jointType, Unity.Robotics.UrdfImporter.Joint joint) [0x00000] in /Library/PackageCache/com.unity.robotics.urdf-importer@9956ce5368/Runtime/UrdfComponents/UrdfJoints/UrdfJoint.cs:89 
  at Unity.Robotics.UrdfImporter.UrdfLinkExtensions.ImportLinkData (Unity.Robotics.UrdfImporter.UrdfLink urdfLink, Unity.Robotics.UrdfImporter.Link link, Unity.Robotics.UrdfImporter.Joint joint) [0x0007a] in /Library/PackageCache/com.unity.robotics.urdf-importer@9956ce5368/Runtime/Extensions/UrdfLinkExtensions.cs:62 
  at Unity.Robotics.UrdfImporter.UrdfLinkExtensions.Create (UnityEngine.Transform parent, Unity.Robotics.UrdfImporter.Link link, Unity.Robotics.UrdfImporter.Joint joint) [0x00051] in Library/PackageCache/com.unity.robotics.urdf-importer@9956ce5368/Runtime/Extensions/UrdfLinkExtensions.cs:31 
  at Unity.Robotics.UrdfImporter.UrdfRobotExtensions.ProcessJointStack (Unity.Robotics.UrdfImporter.UrdfRobotExtensions+ImportPipelineData im) [0x00056] in Library/PackageCache/com.unity.robotics.urdf-importer@9956ce5368/Runtime/Extensions/UrdfRobotExtensions.cs:132 
  at Unity.Robotics.UrdfImporter.UrdfRobotExtensions.CreateRuntime (System.String filename, Unity.Robotics.UrdfImporter.ImportSettings settings) [0x00015] in Library/PackageCache/com.unity.robotics.urdf-importer@9956ce5368/Runtime/Extensions/UrdfRobotExtensions.cs:215

Expected behavior IMO the program shouldn't crash. The joint could be ignored and not added to the structure, and thus not controllable, since it misses <inertial> info for correct simulation. A warning about this should be logged.

The reason to not crash is that there are URDFs with joints that don't need to be controlled directly: some parallel grippers contain joints whose purpose is to be mimicked by other, physical joints. The controlling joint doesn't need <inertial> info, only the mimic one.

This behaviour is similar to Gazebo, which also ignores links without inertial info.

Environment:

Example URDF

<robot name = "example">
        <link name = "base_link">
        <inertial>
            <origin xyz = "0 0 0" />
            <mass value = "0.5" />
            <inertia ixx = "0.5" iyy = "0.5" izz = "0.5" ixy = "0" ixz = "0" iyz = "0" />
        </inertial>
        <visual>
            <origin xyz = "0 0 0" />
            <geometry>
                <box size = "0.5 0.5 0.1" />
            </geometry>
            <material name = "gray A">
                <color rgba = "0.1 0.1 0.1 1" />
            </material>
        </visual>
    </link>
    <link name = "linkA">
        <inertial>
            <origin xyz = "0 0 0" />
            <mass value = "0.5" />
            <inertia ixx = "0.5" iyy = "0.5" izz = "0.5" ixy = "0" ixz = "0" iyz = "0" />
        </inertial>
        <visual>
            <origin xyz = "0 0 0" />
            <geometry>
                <box size = "0.5 0.5 0.1" />
            </geometry>
            <material name = "gray A">
                <color rgba = "0.1 0.1 0.1 1" />
            </material>
        </visual>
    </link>
    <link name = "linkB">
        <!-- Uncomment to add inertial info: this fixes the URDF-Importer exception -->
        <!--
        <inertial>
            <origin xyz = "0 0 -0.5" />
            <mass value = "0.5" />
            <inertia ixx = "0.5" iyy = "0.5" izz = "0.5" ixy = "0" ixz = "0" iyz = "0" />
        </inertial>
        -->
        <visual>
            <origin xyz = "0 0 -0.5" />
            <geometry>
                <cylinder radius = "0.05" length = "1"  />
            </geometry>
            <material name = "gray B">
                <color rgba = "0.3 0.3 0.3 1" />
            </material>
        </visual>
    </link>
       <joint name = "base_joint" type = "fixed">
        <parent link = "base_link" />
        <child link = "linkA" />
        <origin xyz = "0 0 -0.05" />
    </joint>
    <joint name = "joint AB" type = "revolute">
        <parent link = "linkA" />
        <child link = "linkB" />
        <origin xyz = "0 0 -0.05" />
        <axis xyz = "0 1 0" />
    </joint>
</robot>