How to get multiple contact points between one object and multiple static object?

Official Python bindings with a focus on reinforcement learning and robotics.
AisyJeff
Posts: 4
Joined: Sat Apr 02, 2022 1:13 pm

How to get multiple contact points between one object and multiple static object?

Post by AisyJeff »

This code has worked before for one-to-one object. But I wanted to make one to multiple object contact. Multiple objects were created using the coordinates as in the code. this is my code, and I get some error because mis-use of probably the coordinates as a list, and I'm trying to put it as an argument in the contact points:

Code: Select all

import pybullet as p
import pybullet_data
import time

obstacles_coor=[[-5,10,2.5],[2,10,2.5],[10,10,2.5],[0,5,2.5],[-10,-5,2.5]] 

physicsClient = p.connect(p.GUI)
p.setAdditionalSearchPath(pybullet_data.getDataPath())
p.loadURDF('plane.urdf', [0,0,0])

p.setGravity(0,0,-10)

for obs in obstacles_coor:
    p.loadURDF("cube.urdf",obs,globalScaling=0.5)
    p.setAdditionalSearchPath(pybullet_data.getDataPath())
obstacles_coor.pop()

cube=p.loadURDF("cube.urdf", [0,0,1])

def contactPoints():
      contacts = p.getContactPoints(bodyA=cube, bodyB=obs)
      for contact in contacts:
          link_index = contact[5]
          if link_index >= 0:
                #p.removeBody(obstacles_coor[0])
                #del(obstacles_coor.pop(0))
                p.removeBody(obstacles_coor.pop(0))

for i in range(10000):
    p.stepSimulation()
    contactPoints()
    time.sleep(1./240.)
The error jumps in line:

Code: Select all

contacts = p.getContactPoints(bodyA=cube, bodyB=obs)
with the error log:

Code: Select all

Exception has occurred: TypeError
an integer is required (got type list)
  File "C:\Users\AisyahJeff\niche_evo_single_species\old_model\test.py", line 60, in contactPoints
    contacts = p.getContactPoints(bodyA=cube, bodyB=obs)
  File "C:\Users\AisyahJeff\niche_evo_single_species\old_model\test.py", line 72, in <module>
    contactPoints()