You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Direct Collocation报错:设置time_step=0仍提示系统无连续状态

解决DirectCollocation报“无连续状态”的问题

问题根源

  • 上下文获取错误:你通过scene_graph.GetMyContextFromRoot(diagram_context)拿到的是SceneGraph的上下文,并非MultibodyPlant的上下文,导致DirectCollocation无法识别plant的连续状态。
  • 系统对象传参错误:当Plant和SceneGraph组装成Diagram后,必须把完整的Diagram传给DirectCollocation,而非单独的Plant——单独的Plant已经是Diagram的子系统,无法提供完整的动力学状态信息。

修正代码

builder = DiagramBuilder()
plant, scene_graph = AddMultibodyPlantSceneGraph(builder=builder, time_step=0) 
parser = Parser(plant)
ConfigureParser(parser)
parser.AddModelsFromString(minigolf_urdf, 'urdf')
plant.Finalize()

diagram = builder.Build()
diagram_context = diagram.CreateDefaultContext()
# 修正:获取MultibodyPlant的上下文
plant_context = plant.GetMyContextFromRoot(diagram_context)
# 修正:传入组装后的Diagram作为系统对象
dircol = DirectCollocation(
    diagram,
    diagram_context,
    num_time_samples=41,
    minimum_timestep=0.1,
    maximum_timestep=1,
    input_port_index=plant.get_actuation_input_port().get_index(),
)

补充说明

  • time_step=0确实会将MultibodyPlant设置为连续动力学模式,但必须保证上下文和系统对象匹配,否则程序无法正确识别状态。
  • 用AddMultibodyPlantSceneGraph构建带可视化的系统时,Diagram才是完整的动力学系统入口,单独的Plant无法独立提供有效的动力学计算环境。

内容的提问来源于stack exchange,提问作者Lauren Chen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.24 00:13:24