0

Currently, I want to stack several capsule to simulate a elastic tube. It looks like:

enter image description here

Then, I want to apply a force to the top capsule. I expect these capsules to bend to an arc.

However, when I add the x-force/y-force to the top capsule, a twisty tube appear:

enter image description here

The red rectangle indicates the applied force. We can see the tube is twisty.

The complete code to reproduce the figure is:

import pybullet as p

physicsClient = p.connect(p.GUI)
p.setGravity(0,0,0)

plane_shape = p.createCollisionShape(p.GEOM_PLANE)
plane_body = p.createMultiBody(baseCollisionShapeIndex=plane_shape)

radius = 0.1
height = 0.1
d = height/2+radius
N = 10
cylinders = []
for i in range(N):
    cylinder = p.createCollisionShape(p.GEOM_CAPSULE, radius=radius, height=height)
    body = p.createMultiBody(baseMass=1, baseCollisionShapeIndex=cylinder,
                             # baseInertialFramePosition=[0, 0, 0],
                              basePosition=[0, 0, d*2*i])

    cylinders.append(cylinder)

for i in range(1, N):
    d = height/2+radius
    joint = p.createConstraint(
        cylinders[i-1],
        -1,
        cylinders[i],
        -1,
        p.JOINT_POINT2POINT,
        [0, 0, 1],
        [0, 0, d],
        [0, 0, -d]
    )

joint = p.createConstraint(
    plane_body, -1, cylinders[0], -1, p.JOINT_FIXED, [0, 0, 1], [0, 0, d], [0, 0, -d]
)

xId = p.addUserDebugParameter('x-force', -10, 10, 0)
yId = p.addUserDebugParameter('y-force', -10, 10, 0)

import time
p.setRealTimeSimulation(0)
while p.isConnected():
    xforce = p.readUserDebugParameter(xId)
    yforce = p.readUserDebugParameter(yId)
    p.applyExternalForce(cylinders[-1], -1, forceObj=[xforce, 0, 0], posObj=[0, 0, height], flags=p.LINK_FRAME)
    p.applyExternalForce(cylinders[-1], -1, forceObj=[0, yforce, 0], posObj=[0, 0, height], flags=p.LINK_FRAME)

    p.stepSimulation()
    time.sleep(1. / 240.)

p.disconnect()

How can I avoid this weird result? Any suggestion is appreciated~~~

Qiang Zhang
  • 820
  • 8
  • 32

0 Answers0