0

我正在尝试从头开始为 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.

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

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

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

4

1 回答 1

1

以下是我必须应用的增量,以使其至少通过该错误:

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

主要说明:

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

这有帮助吗?

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

这是因为它是一个MultibodyPlant实例,它有多个端口。预览来自plot_system_graphviz

图形可视化

于 2019-03-19T15:47:09.263 回答