pythonphysics-enginebulletphysicsbullet

How to prevent an object from rotating about or moving relative to particular axis on pybullet?


There are several vague descriptions of ways to do this, like "use the createMultiBody method" or "use maximal coordinates", but there is no other information.

To be more specific, I am loading objects I created with SolidWorks using the loadURDF method, but I want them to only rotate about their z axis, and only move about their x and y axes. How can I achieve this? Is there a way to enable this for the entire environment?

Edit: Here's what I basically want to do:

import pybullet as p

p.connect(p.DIRECT)

OBJECT_1 = p.loadURDF("/location/of/object1.urdf")
OBJECT_2 = p.loadURDF("/location/of/object2.urdf")
OBJECT_3 = p.loadURDF("/location/of/object3.urdf")
OBJECT_4 = p.loadURDF("/location/of/object4.urdf")

# code to prevent the motion of OBJECT_1, OBJECT_2, OBJECT_3, and OBJECT_4
# (or the entire simulation) along the z axis.

# code to prevent the rotation of OBJECT_1, OBJECT_2, OBJECT_3, and OBJECT_4
# (or the entire simulation) along the x and y axes.

while True:
    p.stepSimulation()

p.disconnect()

Solution

  • I found a semi-satisfying solution a while ago; if a better one exists, please do share.

    Whereas you cannot do this from the python bindings of Bullet, it is possible to introduce these constraints from the URDF (or SDF) file by introducing a 'world' link without a collision shape, then defining constraints between the world and the object. As an example, refer to this example of a biped multibody constrained to moving in the y and z axes.