- Notifications
You must be signed in to change notification settings - Fork441
Can you split an input to an interconnected system?#1047
-
If I have an input that is external to an interconnected system, and I want this external input to connect into multiple systems contained within, the only way I can think to do this is by using Part of the motivation for this question is that it is difficult to understand how an external input is being used if you can only specify it in terms of the subsystem that it connects to. It might be intended for the input to connect to multiple subsystems. Here is an example of how I have implemented: importnumpyasnpimportcontrolasctdefdynamics(t,x,u,p):A=np.array([[0,1], [-p['spring_constant'],-p['damping_coefficient']]])B=np.array([[0], [1]])returnA @x+B @udefoutputs(t,x,u,p):C=np.array([[1,0]])D=np.array([[0]])returnC @x+D @usys1=ct.nlsys(updfcn=dynamics,outfcn=outputs,states=['pos','vel'],inputs=['u1'],outputs=['pos'],name='sys1')sys1.params= {'spring_constant':10,'damping_coefficient':0.5}sys2=ct.nlsys(updfcn=dynamics,outfcn=outputs,states=['pos','vel'],inputs=['u2'],outputs=['pos'],name='sys2')sys2.params= {'spring_constant':1,'damping_coefficient':1}sys=ct.interconnect( (sys1,sys2),# inplist=['u'], # only works if both subsystem inputs are named uoutlist=['sys1.pos','sys2.pos'],outputs=['pos1','pos2'])# /venv/lib/python3.12/site-packages/control/nlsys.py:1192: UserWarning: Unused input(s) in InterconnectedSystem: (1, 0)=sys2.u2; (0, 0)=sys1.u1sys.set_input_map(np.array([[1],[1]]))sys.set_inputs('external_input')t=np.linspace(0,10,1000)u0=lambdat:1U=np.array([ [u0(ti)fortiint]])results=ct.input_output_response(sys,T=t,U=U)p=results.plot()p.figure.show() |
BetaWas this translation helpful?Give feedback.
All reactions
You can accomplish this interconnection using the following:
sys = ct.interconnect( [sys1, sys2], connections=None, inplist=[ ['sys1.u1', 'sys2.u2'] # Input connects to multiple signals ], inputs='external_input', outlist=['sys1.pos', 'sys2.pos'], outputs=['pos1', 'pos2'], )
The reason this works is that if you specify a list as an entry forinplist
, it will connect that input (external_input
) here to all of the signals in that list.
I also like the alternative syntax you have proposed above, so I've added issue#1049 to track its implementation.
Replies: 3 comments 1 reply
-
Would be nice to be able to do something like this: sys=ct.interconnect( (sys1,sys2),connections=( ['sys1.u1','external_input'], ['sys2.u2','external_input'], ),inplist=['external_input'],outlist=['sys1.pos','sys2.pos'],outputs=['pos1','pos2'],) |
BetaWas this translation helpful?Give feedback.
All reactions
👍 1
-
Hi corbin, Or put in different words: I recomment using using the same name for the same signal and different names for different signals to keep things simple. Note: I am not an python-control expert, so please let me know if I am missing something. |
BetaWas this translation helpful?Give feedback.
All reactions
-
Your statements are all correct. In my case, though, I may be re-using simulation components where I don't have control over the naming, but I do know that I want to split the external input and connect it to multiple components. But maybe there's a simple way to modify my approach to align it with the current conventions. |
BetaWas this translation helpful?Give feedback.
All reactions
-
You can accomplish this interconnection using the following:
The reason this works is that if you specify a list as an entry for I also like the alternative syntax you have proposed above, so I've added issue#1049 to track its implementation. |
BetaWas this translation helpful?Give feedback.