向德雷克的刚体植物添加扭转 spring

Adding a torsional spring to rigid body plant in drake

我刚开始使用 drake 并尝试通过 pydrake 添加扭转 spring 到从 urdf 导入的 acrobot 模型。代码的相关部分如下所示

builder = DiagramBuilder()
plant, scene_graph = AddMultibodyPlantSceneGraph(builder, 0.0)

parser = Parser(plant)
model_instance_acrobot = parser.AddModelFromFile("...acrobot.urdf")

RevoluteSpring(plant.GetJointByName("elbow", model_instance_acrobot), nominal_angle, stiffness)

plant.Finalize()

但是好像不能模拟spring的效果。我是否缺少任何命令来将 spring 的效果添加到多体工厂?

以下帮助。谢谢

plant.AddForceElement(RevoluteSpring(plant.GetJointByName("elbow", model_instance_acrobot), nominal_angle, stiffness))