Reputation: 41
I'm trying to automate the declaration of output ports in one system (System A) based on the input ports of another system (System B). My approach involves constructing System B first and then passing it into the __init__
function of System A.
For vector-valued ports, this process is straightforward since I can retrieve the size of the vector input ports of System B and declare corresponding vector output ports in System A accordingly. However, I'm struggling with abstract ports.
I attempted to create a default context for System B and then evaluate the abstract input ports using that context (absract_value = B.input_port.Eval(context)
), hoping to infer the abstract value. However, since the ports haven't been connected yet, I encountered a runtime error.
Is there a method or workaround to determine the type (or structure) of abstract input ports in a Drake system without connecting or evaluating them? Any insights or suggestions would be greatly appreciated.
Upvotes: 0
Views: 68
Reputation: 2449
Call pydrake.systems.framework.InputPort.Allocate as in system_b.get_input_port(i).Allocate()
to create a sample value using the input port's type.
Upvotes: 1