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: import numpy as np
import control as ct
def dynamics(t, x, u, p):
A = np.array([[0, 1], [-p['spring_constant'], -p['damping_coefficient']]])
B = np.array([[0], [1]])
return A @ x + B @ u
def outputs(t, x, u, p):
C = np.array([[1, 0]])
D = np.array([[0]])
return C @ x + D @ u
sys1 = 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 u
outlist=['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.u1
sys.set_input_map(np.array([[1],[1]]))
sys.set_inputs('external_input')
t = np.linspace(0, 10, 1000)
u0 = lambda t: 1
U = np.array([
[u0(ti) for ti in t]
])
results = ct.input_output_response(sys, T=t, U=U)
p = results.plot()
p.figure.show() |
Beta Was this translation helpful? Give feedback.
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'],
) |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
You can accomplish this interconnection using the following:
The reason this works is that if you specify a list as an entry for
inplist
, 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.