在 MIT6.832 HW2 "Cart-Pole: Linearization and LQR Balncing" 中,carpole 定义为:
# instantiate the cart-pole and the scene graph
cartpole, scene_graph = AddMultibodyPlantSceneGraph(builder, time_step=0.0)
urdf_path = FindResource('models/undamped_cartpole.urdf')
Parser(cartpole).AddModelFromFile(urdf_path)
cartpole.Finalize()
稍后,carpole 的驱动输入端口设置为 0:
# fix the input port to zero and get its index for the lqr function
cartpole.get_actuation_input_port().FixValue(context, [0])
input_i = cartpole.get_actuation_input_port().get_index() # input_i = 3
但是,输入端口的索引是 3,而不是 0,这让我很困惑。
这里一个额外的相关问题是,当定义一个新系统时(例如,继承自 VectorSystem),我们可以在哪里定义输入和输出端口?
我一直在研究 HW1 的 Cartpole 模型,发现端口的使用非常混乱。有时它使用get_xxx_port()
,而在其他情况下它使用get_xxx_port(0)
,括号内有一个特定的端口号。