如何防止对象围绕pybullet上的特定轴旋转或相对于特定轴移动?

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

有几个模糊的方法描述,如 "use the createMultiBody method" 或 "use maximal coordinates",但没有其他信息。

更具体地说,我正在加载我使用 loadURDF 方法在 SolidWorks 中创建的对象,但我希望它们仅绕其 z 轴旋转,并且仅绕其 x 和 y 轴移动。我怎样才能做到这一点?有没有办法为整个环境启用此功能?

编辑: 这是我基本上想要做的:

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()

我刚才找到了一个半满意的解决方案;如果有更好的,请分享。

虽然您不能从 Bullet 的 python 绑定中执行此操作,但可以通过引入 'world' link 来从 URDF(或 SDF)文件中引入这些约束,而无需碰撞形状,然后定义世界和对象之间的约束。例如,参考这个 example of a biped multibody constrained to moving in the y and z axes.