- Notifications
You must be signed in to change notification settings - Fork441
Open
Labels
Description
Discussed in#1047
Originally posted bycorbinklett October 9, 2024
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()```</div>