python - "The following environment does not have an entry for the variable"在 FiniteHorizo​​nLinearQuadraticRegulator 的上下文中意味着什么

标签 python drake

背景

我正在运行直接协同定位并将结果输入 FiniteHorizo​​nLinearQuadraticRegulator 以稳定轨迹,但我在构建 FHLQR 时遇到了错误。

我正在尝试理解以下内容的含义:

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-40-0a8e3d5cdef4> in <module>
     10 Q = np.diag([10.,10.,1.,1.])
     11 options.Qf = Q
---> 12 tvlqr = MakeFiniteHorizonLinearQuadraticRegulator(
     13                                       plant, context, t0=options.u0.start_time(),
     14                                       tf=options.u0.end_time(), Q=Q, R=np.eye(1),

RuntimeError: The following environment does not have an entry for the variable u(0)
t -> 4.46101
z2 -> 3.18212e-06
z3 -> 0.001
z1 -> 3
z4 -> 2.82268e-05
u1 -> 0

我尝试过的

起初我想我可能需要将我的输入变量命名为 u 但这没有帮助。我在想 u(0) 意味着它找不到在第一个时间步放置输入的地方,但我不确定如何解决这个问题。

我尝试使用以下命令将工厂的输入端口在时间为零时固定为值 0:plant.get_input_port(0).FixValue(context, [0]) 但它仍然会产生结果同样的问题。

我也试过像这样设置 input_port_index 选项:options.input_port_index = plant.get_input_port(0).get_index() 但我得到了同样的错误。

我认为这不是我如何设置 FiniteHorizo​​nLinearQuadraticRegulator 的问题,因为我用 LinearQuadraticRegulator 替换了 MakeFiniteHorizo​​nLinearQuadraticRegulator 并且有同样的错误.

如果能深入了解此错误的含义以及解决方法,我将不胜感激。

代码骨架

t = Variable("t") # time

# state of the robot (in cartesian coordinates)
z1 = Variable("z1") # ball angle (phi)
z2 = Variable("z2") # body angle 
z3 = Variable("z3") # ball angular velocity (nu)
z4 = Variable("z4") # body angular velocity
cartesian_state = [z1, z2, z3, z4]

# control input of the robot
u1 = Variable("u1") # wheel torque
ctrl_input = [u1]

# nonlinear dynamics, the whole state is measured (output = state)
## dynamics equations here ##
qddot = ((B*u-C-G)/M).T[0]

dynamics = np.concatenate(([z3, z4], qddot))

# dynamics = [u1*cos(z3), u1*sin(z3), u2]
robot = SymbolicVectorSystem(
    time=t,
    state=cartesian_state,
    input=ctrl_input,
    output=cartesian_state,
    dynamics=dynamics,
)
options = FiniteHorizonLinearQuadraticRegulatorOptions()
options.x0 = dircol.ReconstructStateTrajectory(result)
options.u0 = dircol.ReconstructInputTrajectory(result)

builder = DiagramBuilder()
plant = builder.AddSystem(robot)
context = plant.CreateDefaultContext()
Q = np.diag([10.,10.,1.,1.])
options.Qf = Q
tvlqr = MakeFiniteHorizonLinearQuadraticRegulator(
                                      plant, context, t0=options.u0.start_time(), 
                                      tf=options.u0.end_time(), Q=Q, R=np.eye(1),
                                      options=options)
regulator = builder.AddSystem(tvlqr)

最佳答案

我意识到我在我的 qddot 计算中使用了 u,而我打算使用 u1。在我的笔记本中,我进一步定义了 u = dircol.input(),这是错误的来源。

关于python - "The following environment does not have an entry for the variable"在 FiniteHorizo​​nLinearQuadraticRegulator 的上下文中意味着什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61692130/

相关文章:

python - 多个指标的相关性

python - 在文件顶部用 gi 导入

python - pip不会安装mysql-python

php - Python Imports 不提供 PHP 中的输出

pickle - 如何保存一个包含 Drake 植物对象的类对象?

drake - PyDrake ComputePointPairPenetration() 杀死内核

drake - 何时使用 drake-visualizer 与 meshcat 可视化器

linux - 为什么通过 `bazel test` 执行的 drake 中基于 OpenGL 的 VTK 目标有时会在 Linux 上失败?

此python3代码的Python2版本用于编码

drake - 在 Pydrake 中找到与给定模型的关节相关的框架的雅可比行列式