How to debug `InputPort::Eval(): required InputPort[0] is not connected`

半腔热情 提交于 2020-06-29 08:48:41

问题


Background

I am trying to simulate a double pendulum mounted on a cart. I used the examples/multibody/cart_pole/cart_pole_simulation.cc as a starting point.

I created a new .sdf based on cart_pole.sdf and added for my double pendulum cart. I've verified (visually, through drake-visualizer) that the sdf file appears correct (changing the joint values moves the model as expected)

Due to the addition of a new joint, I added the following line to my source file (where mid_joint is the name of the joint between the first link of the pendulum and the second link of the pendulum.

  const RevoluteJoint<double>& mid_joint = tribot.GetJointByName<RevoluteJoint>("mid_joint");

  mid_joint.set_angle(&tribot_context, 0.0);

Problem

My program compiles correctly, but I get the following error when I try to run my system.

terminate called after throwing an instance of 'std::logic_error'
  what():  InputPort::Eval(): required InputPort[0] (geometry_query) of System ::_::drake/multibody/MultibodyPlant@0000560ea69178f0 (MultibodyPlant<double>) is not connected

Any pointers on what this error is pointing to would be greatly appreciated.

Thanks in advance

(PS:: If anyone could tell me how to more formally verify an sdf file, that would be helpful)

Solution (thanks to Russ's answer)

Below are the changes required to fix the error

-    SceneGraph<double>& scene_graph = *builder.AddSystem<SceneGraph>();
+    auto pair = AddMultibodyPlantSceneGraph(&builder, std::make_unique<MultibodyPlant<double>>(FLAGS_time_step));
+    MultibodyPlant<double>& plant = pair.plant;
+
+    SceneGraph<double>& scene_graph = pair.scene_graph;
-    MultibodyPlant<double>& plant =
-        *builder.AddSystem<MultibodyPlant>(FLAGS_time_step);
-    builder.Connect(
-            plant.get_geometry_poses_output_port(),
-            scene_graph.get_source_pose_port(plant.get_source_id().value()));

回答1:


I think that you're close. The reason that your code has departed from the examples/multibody/cart_pole/cart_pole_simulation.cc starting point is that your cartpole.sdf almost certainly added some collision geometry, which was not present in the original example. As such, your MultibodyPlant system needs to be connected to your SceneGraph object in the other direction, too... so that MultibodyPlant can ask geometry questions about collisions.

The simple solution is to change the few lines that create your MultibodyPlant/SceneGraph to look more like the example in e.g. examples/multibody/inclined_plant/inclined_plane_run_dynamics.cc.

I think we want to improve the experience of people that might use your workflow, and have opened https://github.com/RobotLocomotion/drake/issues/10874 .



来源:https://stackoverflow.com/questions/55075161/how-to-debug-inputporteval-required-inputport0-is-not-connected

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!