This gist shows two scenarios where MBP ports are declared in different orders. Specifically:
RegisterSceneGraphPostFinalize calls Finalize() (which creates most MBP ports) prior to RegisterAsSourceForSceneGraph()(which subsequently calls DeclareSceneGraphPorts())
RegisterSceneGraphPreFinalize calls RegisterAsSourceForSceneGraph() before a call to Finalize()
Both tests then scalar convert a diagram containg a MBP and SceneGraph and try to verify that the index of the geometry_query_input_port is the same for the double and AutoDiffXd versions of the plant. RegisterSceneGraphPreFinalize succeeds while RegisterSceneGraphPostFinalizefails.
Diagram transmogrification assumes port indices remain the same between transmogrified systems, and copies the port connections by index. The result is an invalid Diagram in the case where the transmogrified MBP<AutoDiffXd> has its ports in a different order from the MBP<double> it was converted from.
Diagram of the MBP<double>:
Subsequent diagram of the converted MBP<AutoDiffXd>:
To resolve this, MultibodyPlant should declare all its ports in a consistent order. Possibly by declaring scene graph ports in its constructor?
Per drake slack discussion
This gist shows two scenarios where MBP ports are declared in different orders. Specifically:
RegisterSceneGraphPostFinalize
callsFinalize()
(which creates most MBP ports) prior toRegisterAsSourceForSceneGraph()
(which subsequently callsDeclareSceneGraphPorts()
)RegisterSceneGraphPreFinalize
callsRegisterAsSourceForSceneGraph()
before a call toFinalize()
Both tests then scalar convert a diagram containg a MBP and SceneGraph and try to verify that the index of the
geometry_query_input_port
is the same for thedouble
andAutoDiffXd
versions of the plant.RegisterSceneGraphPreFinalize
succeeds whileRegisterSceneGraphPostFinalize
fails.Diagram
transmogrification assumes port indices remain the same between transmogrified systems, and copies the port connections by index. The result is an invalid Diagram in the case where the transmogrifiedMBP<AutoDiffXd>
has its ports in a different order from theMBP<double>
it was converted from.Diagram of the
MBP<double>
: Subsequent diagram of the convertedMBP<AutoDiffXd>
:To resolve this, MultibodyPlant should declare all its ports in a consistent order. Possibly by declaring scene graph ports in its constructor?
/cc @amcastro-tri @jwnimmer-tri @sherm1