英文:
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("robot.urdf")
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_𝓣float𝓤, arg0: pydrake.systems.framework.Context_𝓣float𝓤) -> pydrake.systems.framework.Context_𝓣float𝓤
Invoked with: <pydrake.multibody.plant.MultibodyPlant_𝓣float𝓤 object at 0x7fbd2784e370>; kwargs: root_context=<pydrake.systems.framework.Context_𝓣float𝓤 object at 0x7fbd27862130>
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论