在尝试求解我的数学程序时,德雷克生成RuntimeError:PyFunctionConstraint: Output must be of scalar type AutoDiffXd, but unable to infer scalar type.
对错误负责的约束如下:
def non_penetration_constraint(q):
plant_ad.SetPositions(context_ad, q)
Distances = np.zeros(6, dtype=q.dtype)
i = 0
for name in Claw_name:
g_ids = body_geometries[name]
assert(len(g_ids) == 1)
Distances[i] = query_object.ComputeSignedDistancePairClosestPoints(
Worldbody_id, g_ids[0]).distance
i += 1
return Distances呼叫:
for n in range(N-1):
# Non penetration constraint
prog.AddConstraint(non_penetration_constraint,
lb = [0] * nf,
ub = [0] * nf,
vars = (q[:, n]))以前有没有人遇到过类似的问题?
发布于 2022-09-07 01:50:24
我怀疑您的query_object (可能还有其他值)不是来自于工厂/场景图的自动关闭版本。
像这样实现的约束可以用Q(类型浮点或AutoDiffXd类型)调用。请参阅德雷克教程的“编写自定义计算程序”一节。在您的示例中,来自约束的返回值来自query_object,它不会受到plant_ad.SetPositions调用的直接影响(这似乎是可疑的)。您需要确保query_object是从scene_graph自动生成的,大概是在您将位置设置为约束值之后。
https://stackoverflow.com/questions/73626843
复制相似问题