control.create_statefbk_iosystem

control.create_statefbk_iosystem(sys, gain, feedfwd_gain=None, integral_action=None, estimator=None, controller_type=None, xd_labels=None, ud_labels=None, ref_labels=None, feedfwd_pattern='trajgen', gainsched_indices=None, gainsched_method='linear', control_indices=None, state_indices=None, name=None, inputs=None, outputs=None, states=None, params=None, **kwargs)[source]

Create an I/O system using a (full) state feedback controller.

This function creates an input/output system that implements a state feedback controller of the form

u = u_d - K_p (x - x_d) - K_i \int(C x - C x_d)

by calling

ctrl, clsys = ct.create_statefbk_iosystem(sys, K)

where sys is the process dynamics and K is the state (+ integral) feedback gain (e.g., from LQR). The function returns the controller ctrl and the closed loop systems clsys, both as I/O systems.

A gain scheduled controller can also be created, by passing a list of gains and a corresponding list of values of a set of scheduling variables. In this case, the controller has the form

u = u_d - K_p(\mu) (x - x_d) - K_i(\mu) \int(C x - C x_d)

where \mu represents the scheduling variable.

Alternatively, a controller of the form

u = k_f r - K_p x - K_i \int(C x - r)

can be created by calling

ctrl, clsys = ct.create_statefbk_iosystem(

sys, K, kf, feedfwd_pattern=’refgain’)

In either form, an estimator can also be used to compute the estimated state from the input and output measurements.

Parameters
sysNonlinearIOSystem

The I/O system that represents the process dynamics. If no estimator is given, the output of this system should represent the full state.

gainndarray, tuple, or I/O system

If an array is given, it represents the state feedback gain (K). This matrix defines the gains to be applied to the system. If integral_action is None, then the dimensions of this array should be (sys.ninputs, sys.nstates). If integral action is set to a matrix or a function, then additional columns represent the gains of the integral states of the controller.

If a tuple is given, then it specifies a gain schedule. The tuple should be of the form (gains, points) where gains is a list of gains K_j and points is a list of values mu_j at which the gains are computed. The gainsched_indices parameter should be used to specify the scheduling variables.

If an I/O system is given, the error e = x - xd is passed to the system and the output is used as the feedback compensation term.

feedfwd_gainarray_like, optional

Specify the feedforward gain, k_f. Used only for the reference gain design pattern. If not given and if sys is a StateSpace (linear) system, will be computed as -1/(C (A-BK)^{-1}) B.

feedfwd_patternstr, optional

If set to ‘refgain’, the reference gain design pattern is used to create the controller instead of the trajectory generation (‘trajgen’) pattern.

integral_actionndarray, optional

If this keyword is specified, the controller can include integral action in addition to state feedback. The value of the integral_action keyword should be an ndarray that will be multiplied by the current and desired state to generate the error for the internal integrator states of the control law.

estimatorNonlinearIOSystem, optional

If an estimator is provided, use the states of the estimator as the system inputs for the controller.

gainsched_indicesint, slice, or list of int or str, optional

If a gain scheduled controller is specified, specify the indices of the controller input to use for scheduling the gain. The input to the controller is the desired state x_d, the desired input u_d, and the system state x (or state estimate xhat, if an estimator is given). If value is an integer q, the first q values of the [x_d, u_d, x] vector are used. Otherwise, the value should be a slice or a list of indices. The list of indices can be specified as either integer offsets or as signal names. The default is to use the desired state x_d.

gainsched_methodstr, optional

The method to use for gain scheduling. Possible values are ‘linear’ (default), ‘nearest’, and ‘cubic’. More information is available in scipy.interpolate.griddata. For points outside of the convex hull of the scheduling points, the gain at the nearest point is used.

controller_type‘linear’ or ‘nonlinear’, optional

Set the type of controller to create. The default for a linear gain is a linear controller implementing the LQR regulator. If the type is ‘nonlinear’, a NonlinearIOSystem is created instead, with the gain K as a parameter (allowing modifications of the gain at runtime). If the gain parameter is a tuple, then a nonlinear, gain-scheduled controller is created.

Returns
ctrlNonlinearIOSystem

Input/output system representing the controller. For the ‘trajgen’ design pattern (default), this system takes as inputs the desired state x_d, the desired input u_d, and either the system state x or the estimated state xhat. It outputs the controller action u according to the formula u = u_d - K(x - x_d). For the ‘refgain’ design pattern, the system takes as inputs the reference input r and the system or estimated state. If the keyword integral_action is specified, then an additional set of integrators is included in the control system (with the gain matrix K having the integral gains appended after the state gains). If a gain scheduled controller is specified, the gain (proportional and integral) are evaluated using the scheduling variables specified by gainsched_indices.

clsysNonlinearIOSystem

Input/output system representing the closed loop system. This system takes as inputs the desired trajectory (x_d, u_d) and outputs the system state x and the applied input u (vertically stacked).

Other Parameters
control_indicesint, slice, or list of int or str, optional

Specify the indices of the system inputs that should be determined by the state feedback controller. If value is an integer m, the first m system inputs are used. Otherwise, the value should be a slice or a list of indices. The list of indices can be specified as either integer offsets or as system input signal names. If not specified, defaults to the system inputs.

state_indicesint, slice, or list of int or str, optional

Specify the indices of the system (or estimator) outputs that should be used by the state feedback controller. If value is an integer n, the first n system states are used. Otherwise, the value should be a slice or a list of indices. The list of indices can be specified as either integer offsets or as estimator/system output signal names. If not specified, defaults to the system states.

xd_labels, ud_labels, ref_labelsstr or list of str, optional

Set the name of the signals to use for the desired state and inputs or the reference inputs (for the ‘refgain’ design pattern). If a single string is specified, it should be a format string using the variable i as an index. Otherwise, a list of strings matching the size of x_d and u_d, respectively, should be used. Default is “xd[{i}]” for xd_labels and “ud[{i}]” for ud_labels. These settings can also be overridden using the inputs keyword.

inputs, outputs, statesstr, or list of str, optional

List of strings that name the individual signals of the transformed system. If not given, the inputs, outputs, and states are the same as the original system.

namestring, optional

System name. If unspecified, a generic name ‘sys[id]’ is generated with a unique integer id.

paramsdict, optional

System parameter values. By default, these will be copied from sys and ctrl, but can be overridden with this keyword.

Examples

>>> import control as ct
>>> import numpy as np
>>>
>>> A = [[0, 1], [-0.5, -0.1]]
>>> B = [[0], [1]]
>>> C = np.eye(2)
>>> D = np.zeros((2, 1))
>>> sys = ct.ss(A, B, C, D)
>>>
>>> Q = np.eye(2)
>>> R = np.eye(1)
>>>
>>> K, _, _ = ct.lqr(sys,Q,R)
>>> ctrl, clsys = ct.create_statefbk_iosystem(sys, K)