How to use the control.statesp._convertToStateSpace function in control

To help you get started, we’ve selected a few control examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kdavies4 / ModelicaRes / external / control / src / timeresp.py View on Github external
Response of the system. 
    xout: array
        Time evolution of the state vector. 
    
    See Also
    --------
    step_response, initial_response, impulse_response
    
    Examples
    --------
    >>> T, yout, xout = forced_response(sys, T, u, X0)
    """
    if not isinstance(sys, Lti):
        raise TypeError('Parameter ``sys``: must be a ``Lti`` object. '
                        '(For example ``StateSpace`` or ``TransferFunction``)')
    sys = _convertToStateSpace(sys) 
    A, B, C, D = np.asarray(sys.A), np.asarray(sys.B), np.asarray(sys.C), \
                 np.asarray(sys.D)
#    d_type = A.dtype
    n_states = A.shape[0]
    n_inputs = B.shape[1]

    # Set and/or check time vector in discrete time case
    if isdtime(sys, strict=True):
        if T == None:
            if U == None:
                raise ValueError('Parameters ``T`` and ``U`` can\'t both be'
                                 'zero for discrete-time simulation')
            # Set T to integers with same length as U
            T = range(len(U))
        else:
            # Make sure the input vector and time vector have same length
github kdavies4 / ModelicaRes / external / control / src / bdalg.py View on Github external
if not isinstance(sys1, (int, float, complex, tf.TransferFunction,
        ss.StateSpace)):
        raise TypeError("sys1 must be a TransferFunction or StateSpace object, \
or a scalar.")
    if not isinstance(sys2, (int, float, complex, tf.TransferFunction,
        ss.StateSpace)):
        raise TypeError("sys2 must be a TransferFunction or StateSpace object, \
or a scalar.")

    # If sys1 is a scalar, convert it to the appropriate LTI type so that we can
    # its feedback member function.
    if isinstance(sys1, (int, float, complex)):
        if isinstance(sys2, tf.TransferFunction):
            sys1 = tf._convertToTransferFunction(sys1)
        elif isinstance(sys2, ss.StateSpace):
            sys1 = ss._convertToStateSpace(sys1)
        else: # sys2 is a scalar.
            sys1 = tf._convertToTransferFunction(sys1)
            sys2 = tf._convertToTransferFunction(sys2)

    return sys1.feedback(sys2, sign)
github python-control / python-control / control / dtime.py View on Github external
Sample time for the conversion

    method: string, optional
        Method to be applied,
        'zoh'        Zero-order hold on the inputs (default)
        'foh'        First-order hold, currently not implemented
        'impulse'    Impulse-invariant discretization, currently not implemented
        'tustin'     Bilinear (Tustin) approximation, only SISO
        'matched'    Matched pole-zero method, only SISO
    '''
    #  Call the sample_system() function to do the work
    sysd = sample_system(sysc, Ts, method)

    # TODO: is this check needed?  If sysc is  StateSpace, sysd is too?
    if isinstance(sysc, StateSpace) and not isinstance(sysd, StateSpace):
        return _convertToStateSpace(sysd)       # pragma: no cover

    return sysd
github kdavies4 / ModelicaRes / external / control / src / matlab.py View on Github external
ss2tf

    Examples
    --------
    >>> num = [[[1., 2.], [3., 4.]], [[5., 6.], [7., 8.]]]
    >>> den = [[[9., 8., 7.], [6., 5., 4.]], [[3., 2., 1.], [-1., -2., -3.]]]
    >>> sys1 = tf2ss(num, den)
    
    >>> sys_tf = tf(num, den)
    >>> sys2 = tf2ss(sys_tf) 

    """

    if len(args) == 2 or len(args) == 3:
        # Assume we were given the num, den
        return _convertToStateSpace(TransferFunction(*args))

    elif len(args) == 1:
        sys = args[0]
        if not isinstance(sys, TransferFunction):
            raise TypeError("tf2ss(sys): sys must be a TransferFunction \
object.")
        return _convertToStateSpace(sys)
    else:
        raise ValueError("Needs 1 or 2 arguments; received %i." % len(args))
github kdavies4 / ModelicaRes / external / control / src / matlab.py View on Github external
>>> sys_tf = tf(num, den)
    >>> sys2 = tf2ss(sys_tf) 

    """

    if len(args) == 2 or len(args) == 3:
        # Assume we were given the num, den
        return _convertToStateSpace(TransferFunction(*args))

    elif len(args) == 1:
        sys = args[0]
        if not isinstance(sys, TransferFunction):
            raise TypeError("tf2ss(sys): sys must be a TransferFunction \
object.")
        return _convertToStateSpace(sys)
    else:
        raise ValueError("Needs 1 or 2 arguments; received %i." % len(args))
github python-control / python-control / control / timeresp.py View on Github external
See Also
    --------
    step_response, initial_response, impulse_response

    Examples
    --------
    >>> T, yout, xout = forced_response(sys, T, u, X0)

    See :ref:`time-series-convention`.

    """
    if not isinstance(sys, LTI):
        raise TypeError('Parameter ``sys``: must be a ``LTI`` object. '
                        '(For example ``StateSpace`` or ``TransferFunction``)')
    sys = _convertToStateSpace(sys)
    A, B, C, D = np.asarray(sys.A), np.asarray(sys.B), np.asarray(sys.C), \
        np.asarray(sys.D)
#    d_type = A.dtype
    n_states = A.shape[0]
    n_inputs = B.shape[1]
    n_outputs = C.shape[0]

    # Convert inputs to numpy arrays for easier shape checking
    if U is not None:
        U = np.asarray(U)
    if T is not None:
        T = np.asarray(T)

    # Set and/or check time vector in discrete time case
    if isdtime(sys, strict=True):
        if T is None:
github python-control / python-control / control / bdalg.py View on Github external
if not isinstance(sys1, (int, float, complex, np.number,
                             tf.TransferFunction, ss.StateSpace, frd.FRD)):
        raise TypeError("sys1 must be a TransferFunction, StateSpace " +
                        "or FRD object, or a scalar.")
    if not isinstance(sys2, (int, float, complex, np.number,
                             tf.TransferFunction, ss.StateSpace, frd.FRD)):
        raise TypeError("sys2 must be a TransferFunction, StateSpace " +
                        "or FRD object, or a scalar.")

    # If sys1 is a scalar, convert it to the appropriate LTI type so that we can
    # its feedback member function.
    if isinstance(sys1, (int, float, complex, np.number)):
        if isinstance(sys2, tf.TransferFunction):
            sys1 = tf._convert_to_transfer_function(sys1)
        elif isinstance(sys2, ss.StateSpace):
            sys1 = ss._convertToStateSpace(sys1)
        elif isinstance(sys2, frd.FRD):
            sys1 = frd._convertToFRD(sys1, sys2.omega)
        else: # sys2 is a scalar.
            sys1 = tf._convert_to_transfer_function(sys1)
            sys2 = tf._convert_to_transfer_function(sys2)

    return sys1.feedback(sys2, sign)
github python-control / python-control / control / timeresp.py View on Github external
def _get_ss_simo(sys, input=None, output=None):
    """Return a SISO or SIMO state-space version of sys

    If input is not specified, select first input and issue warning
    """
    sys_ss = _convertToStateSpace(sys)
    if sys_ss.issiso():
        return sys_ss
    warn = False
    if input is None:
        # issue warning if input is not given
        warn = True
        input = 0
    if output is None:
        return _mimo2simo(sys_ss, input, warn_conversion=warn)
    else:
        return _mimo2siso(sys_ss, input, output, warn_conversion=warn)