我正在研究 Russ Tedrake 机器人操作课程中的练习 3.9(虚拟墙),并且在尝试添加末端执行器位置约束时收到上述运行时错误。我几乎整天都被困在这个问题上,所以我屈服并决定发帖。另一个 post 也有类似的错误,但我还不足以看出哪里出了问题。我会尽量提供尽可能少的信息,以避免展示我对问题的解决方案。
这是缺少几行的代码。
prog = MathematicalProgram()
v = prog.NewContinuousVariables(7,'joint_velocities')
v_max = 3.0 # do not modify
h = 4e-3 # do not modify
lower_bound = np.array([-0.3,-1.0,-1.0]) # do not modify
upper_bound = np.array([0.3,1.0,1.0]) # do not modify
在下文中,'p' 是依赖于 'v' 元素的符号表达式数组。
for i in range(p.shape[0]):
prog.AddConstraint(le(lower_bound[i],p[i]))
prog.AddConstraint(ge(upper_bound[i],p[i]))
solver = snoptsolver()
result = solver.Solve(prog)
if not (result.is_success()):
raise ValueError("Could not find the optimal solution.")
v_solution = result.Getsolution(v)
return v_solution
这是错误信息。 for 循环中的第一行是发生错误的地方。
RuntimeError Traceback (most recent call last)
<ipython-input-108-b73c5373ad6c> in <module>()
1 V_d = np.array([0.0,0.,0.1,0.05,0])
----> 2 simulator = BuildAndSimulate(DiffIKQP_Wall,V_d)
5 frames
/usr/local/lib/python3.7/dist-packages/numpy/lib/function_base.py in _get_ufunc_and_otypes(self,func,args)
2144
2145 inputs = [arg.flat[0] for arg in args]
-> 2146 outputs = func(*inputs)
2147
2148 # Performance note: profiling indicates that -- for simple
RuntimeError: You should not call `__bool__` / `__nonzero__` on `Formula`. If you are trying to make a map with `Variable`,`Expression`,or `Polynomial` as keys (and then access the map in Python),please use pydrake.common.containers.EqualToDict`.
如果有任何建议或需要更多信息,请告诉我。
谢谢!
编辑:
我认为这些信息可能会有所帮助。运行
print(type(lower_bound[i]))
print(type(p[i]))
返回
<class 'numpy.float64'>
<class 'pydrake.symbolic.Expression'>