Closed RussTedrake closed 4 years ago
@sherm1 FYI I am still able to reproduce this.
Easy repro steps:
%tb
, and press Shift+Enter.Version info (from notebook):
In [3]: !cat /opt/drake/share/doc/drake/VERSION.TXT
Out [3]: 20200420074541 b02ff6e7b75d1a9a3ae7d4cf21fe76fa558cff74
(I will not apply component: pydrake
, as it's unclear if this is Python-specific.)
Investigated: the problem is that diagram_context.Clone() incorrectly copies the DiagramDiscreteValues object into a DiscreteValues object. There was no unit test checking the object types, just the values. Fixing now.
I see now that neither the original diagram.AllocateContext()
(CreateDefaultContext()
)nor diagram_context.Clone()
made any use of DiagramDiscreteValues -- both go through the same DiagramState code. Only diagram.AllocateDiscreteVariables()
is doing this correctly.
The following code
fails with
but if I pass in the result of
AllocateDiscreteVariables
instead (by uncommenting that line), then everything works as expected. I don't understand why. I dug into the call stack a bit, and it appears that the dynamic_cast toDiagramDiscreteValues<T>
is failing on the first case.EDIT(eric): Updated repro.