When overlaying cloth-like objects with the following code in PyBullet, the top and bottom are not well represented. The code is as follows. If anyone knows a solution, please let me know.
I was expecting to position two soft bodies one on top of the other and accurately represent the upper and lower layers. However, in the images captured from PyBullet, the upper and lower cloths randomly switch places.I am currently unsure whether this issue is due to a limitation of PyBullet or a mistake in my coding. Therefore, I am seeking suggestions from everyone on possible solutions.
import pybullet as p
import pybullet_data
import imageio
physicsClient = p.connect(p.GUI)
p.setAdditionalSearchPath(pybullet_data.getDataPath())
p.resetSimulation(p.RESET_USE_DEFORMABLE_WORLD)
gravZ = -10
p.setGravity(0, 0, gravZ)
planeOrn = [0, 0, 0, 1]
planeId = p.loadURDF("plane.urdf", [0, 0, 0], planeOrn)
# Set orientation for the cloth
# orn = p.getQuaternionFromEuler([1.57, 0.0, 0.0])
orn = p.getQuaternionFromEuler([0.0, 3.14, 0.0])
def _load_softbody(basePos, baseOrn):
return p.loadSoftBody("cloth_z_up.obj", basePosition=basePos, baseOrientation=baseOrn, scale=1, mass=1.0,
useNeoHookean=0, useBendingSprings=1, useMassSpring=1, springElasticStiffness=40,
springDampingStiffness=0.1, springDampingAllDirections=1, useSelfCollision=0,
frictionCoeff=0.5, useFaceContact=1, collisionMargin=0.01)
p.setPhysicsEngineParameter(sparseSdfVoxelSize=0.1)
cloth1 = _load_softbody([0, 0, 1], orn)
cloth2 = _load_softbody([0, 0.2, 2], orn)
frames = []
num_steps = 1000
for step in range(num_steps):
p.stepSimulation()
# Capture frame
if step % 10 == 0: # Capture every 10th frame (adjust as needed)
width, height, rgbPixels, _, _ = p.getCameraImage(width=640, height=480)
frames.append(rgbPixels)
imageio.mimsave('simulation.gif', frames, fps=10)
p.disconnect()