从 rootContext 获取上下文时发生类型错误

huangapple go评论68阅读模式
英文:

Type error in getting context from rootContext

问题

我正在尝试包含具有激活接触标签的机器人的URDF文件,并打算使用DirectCollocation为我的机器人生成最优轨迹。

首先,我尝试使用MultibodyPlant()创建机器人模型,然后使用SceneGraph()创建场景图,并认为我使用RegisterAsSourceForSceneGraph()将机器人模型连接到场景图。当我将context=plant.CreateDefaultContext()传递给我的SNOPT求解器时,我收到一个错误,指出正在评估时间导数和残差,并被引导到https://drake.mit.edu/troubleshooting.html#system-framework

我修改了我的代码:

sim_time_step = 0.0
builder = DiagramBuilder()
plant, scene_graph = AddMultibodyPlantSceneGraph(
builder, time_step=sim_time_step)
parser = Parser(plant)
parser.AddModelFromFile("robot.urdf")
plant.Finalize()

diagram = builder.Build()
context = diagram.CreateDefaultContext()
plant_context = plant.GetMyContextFromRoot(root_context=context)

当我运行此代码时,现在我收到错误:

TypeError: GetMyContextFromRoot(): 不兼容的函数参数。支持以下参数类型:
1. (self: pydrake.systems.framework.System_ℜfloatℜ, arg0: pydrake.systems.framework.Context_ℜfloatℜ) -> pydrake.systems.framework.Context_ℜfloatℜ;

调用方式为: <pydrake.multibody.plant.MultibodyPlant_ℜfloatℜ object at 0x7fbd2784e370>; kwargs: root_context=<pydrake.systems.framework.Context_ℜfloatℜ object at 0x7fbd27862130>

如何解决这个错误?
英文:

I am trying to include my URDF file with a robot that has contact tags activated, and I intend to use DirectCollocation to generate an optimal trajectory for my robot.

First I tried creating the plant using MultibodyPlant(), then created the scene_graph using SceneGraph() and then thought I connected the plant to the scene_graph using RegisterAsSourceForSceneGraph(). When I passed the context=plant.CreateDefaultContext() to the my SNOPT solver, I got an error saying the time derivatives and residuals are being evaluated, and was directed to https://drake.mit.edu/troubleshooting.html#system-framework

I modified my code to:

sim_time_step = 0.0
builder = DiagramBuilder()
plant, scene_graph = AddMultibodyPlantSceneGraph(
builder, time_step=sim_time_step)
parser = Parser(plant)
parser.AddModelFromFile(&quot;robot.urdf&quot;)
plant.Finalize()

diagram = builder.Build()
context = diagram.CreateDefaultContext()
plant_context = plant.GetMyContextFromRoot(root_context=context)

When I run this code, now I receive the error:

TypeError: GetMyContextFromRoot(): incompatible function arguments. The following argument types are supported:
    1. (self: pydrake.systems.framework.System_&#120035;float&#120036;, arg0: pydrake.systems.framework.Context_&#120035;float&#120036;) -&gt; pydrake.systems.framework.Context_&#120035;float&#120036;

Invoked with: &lt;pydrake.multibody.plant.MultibodyPlant_&#120035;float&#120036; object at 0x7fbd2784e370&gt;; kwargs: root_context=&lt;pydrake.systems.framework.Context_&#120035;float&#120036; object at 0x7fbd27862130&gt;

How do I get past this error?

答案1

得分: 0

有绑定方面的缺陷。根上下文没有关键字参数

相反,只需调用

plant_context = plant.GetMyContextFromRoot(context)

(我们需要修复绑定并确保指南与实现匹配。 :") )


截至#19503,这不应再是一个障碍。导致混淆的缺陷已经得到解决。

英文:

It appears to be a defect in the binding. There is no keyword argument for the root context.

Instead, simply call

plant_context = plant.GetMyContextFromRoot(context)

(And we need to a) fix the bindings and b) make sure the guidance matches the implementation. :") )


As of #19503, this should no longer be a sticking point. The defect that caused the confusion has been resolved.

huangapple
  • 本文由 发表于 2023年3月15日 21:04:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/75745126.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定