gazebosim / gazebo-classic

Gazebo classic. For the latest version, see https://github.com/gazebosim/gz-sim
http://classic.gazebosim.org/
Other
1.19k stars 481 forks source link

Gazebo misuses collision collide bits as category bits. #1855

Open osrf-migration opened 8 years ago

osrf-migration commented 8 years ago

Original report (archived issue) by Martin Pecka (Bitbucket: peci1).


My feeling is that Gazebo misuses the category bits.

Compare:

gazebo/physics/ode/ODEPhysics.cc, Collide() method:

#!c++
if ((_collision1->GetSurface()->collideBitmask &_collision2->GetSurface()->collideBitmask) == 0)
    return;

and

deps/opende/src/collision_space_internal.h

#!c++

// test if the category and collide bitfields match
  if ( ((g1->category_bits & g2->collide_bits) ||
    (g2->category_bits & g1->collide_bits)) == 0) {
    return;
  }

It seems that ODEPhysics' Collide() method completely ignores the category bits and incorrectly matches two collide masks against each other. Fortunately, dSpaceCollide() still applies the collision vs. category test, but with the superfluous Collide() constraint, the result is different from what sole ODE would do.

Let's make a thinking experiment. I have a BOX and a CYLINDER. I want boxes to collide with cylinders, but not other boxes, and vice versa.

So I set (reading in binary)

BOX:       category 01 collide 10
CYLINDER:  category 10 collide 01

In pure ODE, the result would be as desired: each object's category is checked aginst the other object's collide mask. In Gazebo, the above test is performed, but additionally another if (10 & 01 == 0) return is performed, which causes that nothing ever collides.

Please, try to tell if I understand all the stuff correctly and haven't done a mistake somewhere in my deliberation. If someone agrees with my ideas, I might try to write a failing test for this.

Another problem is that we can't probably fix this without breaking BC (refer e.g. to Issue #1581 and the tutorial linked from there).

osrf-migration commented 7 years ago

Original comment by Matej Hoffmann (Bitbucket: matejhof).


This seems like an important issue. Has this been fixed yet?

osrf-migration commented 7 years ago

Original comment by Shane Loretz (Bitbucket: Shane Loretz, GitHub: sloretz).


@peci1 Thanks for the bug report. You're correct that category and collide bits logic in ODE does not work in gazebo. The collideBitmask behavior appears to have been intentional, and is documented in this tutorial.

I don't see a way to make category bits work in the released versions of gazebo 7 or 8 without breaking other APIs or ABI.

osrf-migration commented 7 years ago

Original comment by Martin Pecka (Bitbucket: peci1).


@sloretz Now the question is what to do with this state?

Does anybody know about support of this feature in other physics engines? It might probably be a good idea to make collideBitmask work in a way that's compatible with most of the engines. Nevertheless, it seems important to me to mention it in the tutorial that the collideBitmask behaves differently than in pure ODE (so far).