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
by calling
ctrl, clsys = ct.create_statefbk_iosystem(sys, K)
where
sys
is the process dynamics andK
is the state (+ integral) feedback gain (e.g., from LQR). The function returns the controllerctrl
and the closed loop systemsclsys
, 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
where
represents the scheduling variable.
Alternatively, a controller of the form
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
- sys
NonlinearIOSystem
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. Ifintegral_action
is None, then the dimensions of this array should be (sys.ninputs, sys.nstates). Ifintegral 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 gainsK_j
and points is a list of valuesmu_j
at which the gains are computed. Thegainsched_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 ifsys
is aStateSpace
(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.- estimator
NonlinearIOSystem
, 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 inputu_d
, and the system statex
(or state estimatexhat
, if an estimator is given). If value is an integerq
, the firstq
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 statex_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 gainK
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.
- sys
- Returns
- ctrl
NonlinearIOSystem
Input/output system representing the controller. For the ‘trajgen’ design pattern (default), this system takes as inputs the desired state
x_d
, the desired inputu_d
, and either the system statex
or the estimated statexhat
. It outputs the controller actionu
according to the formula u = u_d - K(x - x_d). For the ‘refgain’ design pattern, the system takes as inputs the reference inputr
and the system or estimated state. If the keywordintegral_action
is specified, then an additional set of integrators is included in the control system (with the gain matrixK
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 bygainsched_indices
.- clsys
NonlinearIOSystem
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 inputu
(vertically stacked).
- ctrl
- 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 firstm
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 firstn
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 theinputs
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
andctrl
, 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)