如何使用pydrake为Acrobot系统创建LinearQuadraticRegulator

问题描述 投票:0回答:1

我试图从头开始为acrobot系统创建LQR:

file_name = "acrobot.sdf"  # from drake/multibody/benchmarks/acrobot/acrobot.sdf
acrobot = MultibodyPlant()
parser = Parser(plant=acrobot)
parser.AddModelFromFile(file_name)
acrobot.AddForceElement(UniformGravityFieldElement([0, 0, -9.81]))
acrobot.Finalize()

acrobot_context = acrobot.CreateDefaultContext()

shoulder = acrobot.GetJointByName("ShoulderJoint")
elbow = acrobot.GetJointByName("ElbowJoint")

shoulder.set_angle(context=acrobot_context, angle=0.0)
elbow.set_angle(context=acrobot_context, angle=0.0)

Q = np.identity(4)
R = np.identity(1)
N = np.zeros([4, 4])
controller = LinearQuadraticRegulator(acrobot, acrobot_context, Q, R)

运行此脚本我在最后一个字符串收到错误:

RuntimeError: Vector-valued input port acrobot_actuation must be either fixed or connected to the output of another system.

我的修复/连接输入端口的方法最终都没有成功。

附:我知道存在AcrobotPlant,但想法是在运行时从sdf创建LQR。

P.P.S.为什么acrobot.get_num_input_ports()返回5而不是1?

drake
1个回答
1
投票

以下是我必须应用的增量至少传递该错误的增量:

https://github.com/EricCousineau-TRI/drake/commit/e7167fb8a

主要说明:

  • 您有(a)在相关端口上使用plant_context.FixInputPort,或(b)使用DiagramBuilder + AddSystem使用Connect(output_port, input_port组成系统。
  • 我建议命名MBP实例plant,这样你就可以直接引用模型实例。

这有帮助吗?

P.P.S.为什么acrobot.get_num_input_ports()返回5而不是1?

这是因为它是一个MultibodyPlant实例,它有几个端口。从plot_system_graphviz预览:

graphviz

© www.soinside.com 2019 - 2024. All rights reserved.