Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Can you split an input to an interconnected system?#1047

Answeredbymurrayrm
corbinklett asked this question inQ&A
Discussion options

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 usingset_input_map. Is there a more elegant way? Even when I useset_input_map, I still get the "unused input" warning.

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()
You must be logged in to vote

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

Comment options

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'],)
You must be logged in to vote
0 replies
Comment options

Hi corbin,
from your example:
# inplist=['u'], # only works if both subsystem inputs are named u
The signal used as input of sys1 and sys2 isu, so that is the correct input name for sys1 and sys2. No need to introduceu1 andu2, whenu ==u1 ==u2.
Also, it would make sense to me to use different names for the outputs of sys1 and sys2, e.g.pos1 andpos2 instead of the same namepos for different signals.

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.

You must be logged in to vote
1 reply
@corbinklett
Comment options

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.

Comment options

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.

You must be logged in to vote
0 replies
Answer selected bycorbinklett
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
3 participants
@corbinklett@murrayrm@bavcol

[8]ページ先頭

©2009-2025 Movatter.jp