Remove Collision from an entire MultiBody

Official Python bindings with a focus on reinforcement learning and robotics.
Post Reply
Lewho
Posts: 3
Joined: Thu Feb 07, 2019 9:53 pm

Remove Collision from an entire MultiBody

Post by Lewho » Thu Feb 07, 2019 10:18 pm

Hi,

i have a certain number of random generated MultiBody with multiple links BUT i dont want them to collide beteen them and i also want them to keep colliding with my main plane floor.

I find a solution but it works only on the body of the multy body not on the links. Part of the problem is : i dont know what is the LinkIndex parameter in the setCollisionFilterGroupMask function.

My code at the moment :

Code: Select all

p.createCollisionShape(p.GEOM_PLANE)
basePlan = p.createMultiBody(0, 0)

nbobj = 5

body = p.createCollisionShape(p.GEOM_SPHERE, radius=1)
body2 = p.createCollisionShape(p.GEOM_SPHERE, radius=0.5)

aShape = s.Shape(body, pos1)
aShape2 = s.Shape(body2, pos1)

# intitialize multibody matrix for "nbobj" new link
aShape.createRandom(nbobj)
aShape2.createRandom(nbobj)

# do the createMultiBody and return the UniqueBodyid
shape = aShape.createBody()
shape2 = aShape2.createBody()


# Do shape to not collide
p.setCollisionFilterGroupMask(shape, -1, 0, 0)
p.setCollisionFilterGroupMask(shape2, -1, 0, 0)


# But enable the floor Collision
p.setCollisionFilterPair(basePlane, shape, -1, -1, 1)
p.setCollisionFilterPair(basePlane, shape2, -1, -1, 1)

Lewho
Posts: 3
Joined: Thu Feb 07, 2019 9:53 pm

Re: Remove Collision from an entire MultiBody

Post by Lewho » Tue Feb 12, 2019 2:10 pm

No one respond .. nice. The issue is in fact still open on github (https://github.com/bulletphysics/bullet3/issues/2020) and erwin coumans ignore the BUG still 1 month after. The only way i found is complexity O(n^4) which it's very very bad conpare to the real who is O(n^2)

Solution for intrested person who need to have a proof of concept :

Code: Select all

for i in range(-1, nbobj):
        for j in range(-1, nbobj):
            for elem1 in range(0, nbPop):
                for elem2 in range(elem1+1, nbPop):  
                    p.setCollisionFilterPair(pop[elem1].getId(), pop[elem2].getId(), i, j, 0)
        print((i+2)/(nbobj+1))


We need to remove the collision pair by pair so if you have 100 objects it's a 100*100 calculation. the fun doesn't end here.... if you have 10 piece in your multibody you need still to remove the collision pair by pair AGAIN. So it's actualy 100*100*10*10 calculation...

User avatar
Erwin Coumans
Site Admin
Posts: 4160
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

Re: Remove Collision from an entire MultiBody

Post by Erwin Coumans » Tue Feb 19, 2019 12:18 am

PyBullet. setCollisionFilterGroupMask should be fixed in latest repository. Thanks for the report.

Note that link index -1 refers to the base, and link index >=0 refers to child links.
https://github.com/bulletphysics/bullet3/pull/2116

Lewho
Posts: 3
Joined: Thu Feb 07, 2019 9:53 pm

Re: Remove Collision from an entire MultiBody

Post by Lewho » Tue Feb 19, 2019 11:34 am

Thanks a lot it works !!! and with the complexity of O(n²)

Here the final code for peoples who want it

Code: Select all

# pop => Array of multibody personal class where is stored the unique ID and number of links and all the links matrices
def removeAllColisions(pop):
    for elem in pop:
        # Get the numbre of sub-object/links in the multibody
        for i in range(-1, elem.nbobj):
            p.setCollisionFilterGroupMask(elem.getId(), i, 0, 0)
            p.setCollisionFilterPair(0, elem.getId(), -1, i, 1)

Post Reply