Skip to content

Add the ability to split an input to an interconnected system #1049

Open
@murrayrm

Description

@murrayrm

Discussed in #1047

Originally posted by corbinklett 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 using set_input_map. Is there a more elegant way? Even when I use set_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:

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()

```</div>

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions