ros-simulation / gazebo_ros_pkgs

Wrappers, tools and additional API's for using ROS with Gazebo
http://wiki.ros.org/gazebo_ros_pkgs
771 stars 773 forks source link

gazebo crashes on zero value collision geometries #488

Closed pabloinigoblasco closed 6 years ago

pabloinigoblasco commented 8 years ago

I have written this issue on ros.answers.

I get one weird error trying to load some of the samples/models provided in gazebo_plugins on Ubuntu 16.04 with ROS kinetic installed via official repositories.

Particularly, for the multi_robot_scenario fails. On the other hand the tricycle demo or the pendulum demos work properly.

This is the error I get trying to load the multi_robot_scenario demo.

Error [Param.cc:451] Unable to set value [-nan -nan -nan] for key[size]
gzserver: /build/ogre-1.9-mqY1wq/ogre-1.9-1.9.0+dfsg1/OgreMain/src/OgreNode.cpp:630: virtual void Ogre::Node::setScale(const Ogre::Vector3&): Assertion `!inScale.isNaN() && "Invalid vector supplied as parameter"' failed.
[r1/urdf_spawner-4] process has finished cleanly
log file: /home/geus/.ros/log/37a5e414-7527-11e6-8e8a-d8cb8abfd844/r1-urdf_spawner-4*.log
Service call failed: transport error completing service call: unable to receive data from sender, check sender's logs for details
Aborted (core dumped)
[gazebo-2] process has died [pid 19670, exit code 134, cmd /media/geus/Storage/simulation_gazebo/src/gazebo_ros_pkgs/gazebo_ros/scripts/gzserver -e ode worlds/empty.world __name:=gazebo __log:=/home/geus/.ros/log/37a5e414-7527-11e6-8e8a-d8cb8abfd844/gazebo-2.log].
log file: /home/geus/.ros/log/37a5e414-7527-11e6-8e8a-d8cb8abfd844/gazebo-2*.log

In order to reproduce this issue you have to install the package ros-kinetic-gazebo-plugins and execute the launch file:

roslaunch $(roslaunch $(rospack find gazebo_plugins)/test/multi_robot_scenario/launch/multi_robot_scenario.launch

pabloinigoblasco commented 8 years ago

It looks like there is a bug in gazebo 7.0.0 contained in the kinetic debian package repository for ubuntu 16.04. The bug appears when the urdf descriptions contains collision geometry objects with zero value parameters.

For instance in "gazebo_plugins/test/multi_robot_scenario/xacro/p3dx/pioneer3dx_wheel.xacro": we find this chunk of urdf:

<collision>
  <origin xyz="0 0 0" rpy="0 0 0"/>
  <geometry>
    <box size="0 0 0"/>
  </geometry>
</collision>

The box size must not be zero. The error is solved if the above code chunk is replaced by the code chunk below:

<collision>
  <origin xyz="0 0 0" rpy="0 0 0"/>
  <geometry>
    <box size="0.1 0.1 0.1"/>
  </geometry>
</collision>

It is needed to apply this correction in several place in order to make work this demo:

roslaunch $(rospack find gazebo_plugins)/test/multi_robot_scenario/launch/multi_robot_scenario.launch

andre-nguyen commented 7 years ago

Can confirm, wasted a good 5 hours on this :cry:

Follow up: you can also fix the error by writing a value as 0.0 so looks like it's some kind of double parsing error.

Follow up to follow up: nope I was wrong, really need to put a non zero value.

j-rivero commented 7 years ago

Thanks Pablo, Andre for reporting.

Is this error happening in newer versions of gazebo, i.e: current Gazebo-7.4.0? @pabloinigoblasco would you mind to send the patches you made to get the thing fixed?

andre-nguyen commented 7 years ago

I'm running gazebo with whatever version was installed with ros kinetic

andre@desktop:~$ gazebo --version
Gazebo multi-robot simulator, version 7.0.0
Copyright (C) 2012-2016 Open Source Robotics Foundation.
Released under the Apache 2 License.
http://gazebosim.org
jonbinney commented 7 years ago

This isn't a bug in gazebo so much as a bug in pioneer3dx_wheel.xacro, right? I wouldn't expect zero size boxes to work, although there could probably be a better error message along the lines of "Collision objects cannot have zero size" .

andre-nguyen commented 7 years ago

I can't comment on whether it's right or not but it looks like it's something that used to work so people wrote it in their models.

In my case I hit the bug trying to load a mico arm model from https://github.com/Kinovarobotics/kinova-ros

jonbinney commented 7 years ago

Based on the usage in the kinova urdf, what do you think the behavior should be? Is a zero-size box a point for the purposes of collision? Or is it truly empty collision geometry which never collides with anything?

andre-nguyen commented 7 years ago

It's used in a virtual link https://github.com/Kinovarobotics/kinova-ros/blob/master/kinova_description/urdf/kinova_common.xacro#L52

    <xacro:macro name="kinova_virtual_link" params="link_name">
        <link name="${link_name}">
            <visual>
                <geometry>
                    <box size = "0 0 0"/>
                </geometry>
            </visual>
            <collision>
                <geometry>
                    <box size = "0 0 0"/>
                </geometry>
            </collision>
        </link>
    </xacro:macro>

So I suppose it's the latter and truly an empty collision geometry.

jonbinney commented 7 years ago

Since it's used that way in existing urdfs, it sounds like it would make sense to add a special cases that notices zero-size collision objects, treats them as no collision geometry, and outputs a warning such as "Warning: ignoring zero-size collision geometry for link ". I'm all for not breaking existing urdfs. Not sure where exactly this code needs to go though.

jonbinney commented 7 years ago

I suspect that the zero size collision boxes were added as a workaround to an old bug. There was a time a couple years ago when links without collision geometry would crash gazebo/gazebo_ros, and I remember adding zero size collision geometry to my own robots at the time. Those workarounds should (I think) be removed now, but giving a warning and having things work will give people time to update their URDFs.

j-rivero commented 7 years ago

The problem is not strictly related to ROS but to gazebo itself. I was able to reproduce it using the model.sdf[1] file at the end of this comment.

The gdb backtrace points to Visual.cc file. During my debugging I discovered that the current gazebo7 branch does not suffer from the Core dump so according with this, there should be something in the list of changes from gazebo7 branch to gazebo-7.4.0 that has modified the problem, I was not able to discover exactly which commit.

Given the number of modifications pending it is my intention to release a new 7.5.0. If anyone want to continue debugging previous versions or improving error messages, I was working with the following patch (although not sure if it fixes the problem or it is fully correct):

diff -r ced7f59587e3 gazebo/rendering/Visual.cc
--- a/gazebo/rendering/Visual.cc    Thu Dec 22 19:43:25 2016 +0100
+++ b/gazebo/rendering/Visual.cc    Sat Dec 24 00:56:09 2016 +0100
@@ -2583,7 +2583,15 @@
     else
       gzerr << "Unknown geometry type[" << _msg->geometry().type() << "]\n";

-    this->SetScale(geomScale * this->dataPtr->scale / this->DerivedScale());
+    // Set scale if the geometry is not zero
+    if (geomScale == ignition::math::Vector3d::Zero)
+    {
+      gzerr << "Geometry is 0,0,0. Skipping scaling"  << std::endl;
+    }
+    else
+    {
+      this->SetScale(geomScale * this->dataPtr->scale / this->DerivedScale());
+    }
   }

   if (_msg->has_material())

[1] model.sdf file (to use it, create a new model in ~/.gazebo/models/ and write a minimal .config file. Insert it from the gazebo GUI).

<sdf version='1.6'>
  <model name='r1'>
    <link name='base_link'>
      <pose frame=''>0 0 0 0 -0 0</pose>
      <inertial>
        <pose frame=''>-0.0045 0 0.0234 0 -0 0</pose>
        <mass>10</mass>
        <inertia>
          <ixx>0.136322</ixx>
          <ixy>0</ixy>
          <ixz>0.009477</ixz>
          <iyy>0.189113</iyy>
          <iyz>0</iyz>
          <izz>0.178258</izz>
        </inertia>
      </inertial>
      <collision name='base_link_fixed_joint_lump__chassis_collision'>
        <pose frame=''>-0.045 0 0.148 0 -0 0</pose>
        <geometry>
          <mesh>
            <scale>1 1 1</scale>
            <uri>/home/jrivero/code/ros/ws/gazebo_ros_pkgs/src/gazebo_ros_pkgs/gazebo_plugins/test/multi_robot_scenario/meshes/p3dx/chassis.stl</uri>
          </mesh>
        </geometry>
        <surface>
          <contact>
            <ode/>
          </contact>
          <friction>
            <ode/>
          </friction>
        </surface>
      </collision>
      <collision name='base_link_fixed_joint_lump__top_collision_1'>
        <pose frame=''>-0.045 0 0.234 0 -0 0</pose>
        <geometry>
          <mesh>
            <scale>1 1 1</scale>
            <uri>/home/jrivero/code/ros/ws/gazebo_ros_pkgs/src/gazebo_ros_pkgs/gazebo_plugins/test/multi_robot_scenario/meshes/p3dx/top.stl</uri>
          </mesh>
        </geometry>
        <surface>
          <contact>
            <ode/>
          </contact>
          <friction>
            <ode/>
          </friction>
        </surface>
      </collision>
      <visual name='base_link_fixed_joint_lump__chassis_visual_visual'>
        <pose frame=''>-0.045 0 0.148 0 -0 0</pose>
        <geometry>
          <mesh>
            <scale>1 1 1</scale>
            <uri>/home/jrivero/code/ros/ws/gazebo_ros_pkgs/src/gazebo_ros_pkgs/gazebo_plugins/test/multi_robot_scenario/meshes/p3dx/chassis.stl</uri>
          </mesh>
        </geometry>
        <material>
          <script>
            <name>Gazebo/Red</name>
            <uri>file://media/materials/scripts/gazebo.material</uri>
          </script>
        </material>
      </visual>
      <visual name='base_link_fixed_joint_lump__top_visual_1'>
        <pose frame=''>-0.045 0 0.234 0 -0 0</pose>
        <geometry>
          <mesh>
            <scale>1 1 1</scale>
            <uri>/home/jrivero/code/ros/ws/gazebo_ros_pkgs/src/gazebo_ros_pkgs/gazebo_plugins/test/multi_robot_scenario/meshes/p3dx/top.stl</uri>
          </mesh>
        </geometry>
        <material>
          <script>
            <name>Gazebo/Black</name>
            <uri>file://media/materials/scripts/gazebo.material</uri>
          </script>
        </material>
      </visual>
      <velocity_decay/>
      <gravity>1</gravity>
      <velocity_decay/>
    </link>
    <link name='right_hub'>
      <pose frame=''>0 0.15 0.09 0 -0 0</pose>
      <inertial>
        <pose frame=''>0 0 0 0 -0 0</pose>
        <mass>0.51</mass>
        <inertia>
          <ixx>0.0248235</ixx>
          <ixy>0</ixy>
          <ixz>0</ixz>
          <iyy>0.0304363</iyy>
          <iyz>0</iyz>
          <izz>0.023528</izz>
        </inertia>
      </inertial>
      <collision name='right_hub_collision'>
        <pose frame=''>0 0 0 0 -0 0</pose>
        <geometry>
          <box>
            <size>0 0 0</size>
          </box>
        </geometry>
        <surface>
          <contact>
            <ode/>
          </contact>
          <friction>
            <ode/>
          </friction>
        </surface>
      </collision>
      <collision name='right_hub_fixed_joint_lump__right_wheel_collision_1'>
        <pose frame=''>0 0 0 -1.5708 0 0</pose>
        <geometry>
          <cylinder>
            <length>0.01</length>
            <radius>0.09</radius>
          </cylinder>
        </geometry>
        <surface>
          <contact>
            <ode/>
          </contact>
          <friction>
            <ode/>
          </friction>
        </surface>
      </collision>
      <visual name='right_hub_fixed_joint_lump__base_visual_visual'>
        <pose frame=''>0 0 0 0 -0 0</pose>
        <geometry>
          <mesh>
            <scale>1 1 1</scale>
            <uri>/home/jrivero/code/ros/ws/gazebo_ros_pkgs/src/gazebo_ros_pkgs/gazebo_plugins/test/multi_robot_scenario/meshes/p3dx/right_hubcap.stl</uri>
          </mesh>
        </geometry>
      </visual>
      <visual name='right_hub_fixed_joint_lump__base_visual_visual_1'>
        <pose frame=''>0 0 0 0 -0 0</pose>
        <geometry>
          <mesh>
            <scale>1 1 1</scale>
            <uri>/home/jrivero/code/ros/ws/gazebo_ros_pkgs/src/gazebo_ros_pkgs/gazebo_plugins/test/multi_robot_scenario/meshes/p3dx/right_wheel.stl</uri>
          </mesh>
        </geometry>
      </visual>
      <velocity_decay/>
      <gravity>1</gravity>
      <velocity_decay/>
    </link>
    <joint name='right_hub_joint' type='revolute'>
      <child>right_hub</child>
      <parent>base_link</parent>
      <axis>
        <xyz>0 1 0</xyz>
        <limit>
          <lower>-1e+16</lower>
          <upper>1e+16</upper>
        </limit>
        <dynamics>
          <spring_reference>0</spring_reference>
          <spring_stiffness>0</spring_stiffness>
        </dynamics>
        <use_parent_model_frame>1</use_parent_model_frame>
      </axis>
    </joint>
    <pose frame=''>0 -0.5 0.01 0 -0 1.57</pose>
  </model>
</sdf>
j-rivero commented 7 years ago

The new gazebo7 version 7.5.0 does not crash the simulator in my system anymore.

MahdiehNejati commented 7 years ago

I'm having this problem in gazebo8 with ROS kinetic. Is there a way to fix this without reverting to an older version of gazebo? Thanks!

andre-nguyen commented 7 years ago

I ended up adding a very small non-zero collision size to my model to fix the problem:

https://github.com/MRASL/kinova-ros/commit/2400703eadddd1f5ce2b24ae9fa600130f9d4bf5

kev-the-dev commented 6 years ago

I have confirmed on fresh installs of kinetic with gazeo7 and gazebo8 that this is not an issue. Please update to newer versions of gazebo is this issue remains, as it was patched

mhwasil commented 6 years ago

Changing size values to non zero ones works for me