Exported functions and types

Index

Docstrings

ModelingToolkitBase.System — Method
ModelingToolkit.System(sys::AbstractStateSpace; name::Symbol, x0 = zeros(sys.nx), x_names, u_names, y_names)

Create an System from sys::StateSpace.

Arguments:

  • sys: An instance of StateSpace or NamedStateSpace.
  • name: A symbol giving the system a unique name.
  • x0: Initial state

The arguments below are automatically set if the system is a NamedStateSpace.

  • x_names: A vector of symbols with state names.
  • u_names: A vector of symbols with input names.
  • y_names: A vector of symbols with output names.
source
ControlSystemsMTK.GainScheduledStateSpace — Method
GainScheduledStateSpace(systems, vt; interpolator, x = zeros((systems[1]).nx), name, u0 = zeros((systems[1]).nu), y0 = zeros((systems[1]).ny))

A linear parameter-varying (LPV) version of Blocks.StateSpace, implementing the following equations:

\[\begin{aligned} \dot{x} &= A(v) x + B(v) u \\ y &= C(v) x + D(v) u \end{aligned}\]

where v is a scalar scheduling variable.

See example usage in the gain-scheduling example.

Arguments:

  • systems: A vector of ControlSystemsBase.StateSpace objects
  • vt: A vector of breakpoint values for the scheduling variable v, this has the same length as systems.
  • interpolator: A constructor i = interpolator(values, breakpoints) and returns an interpolator object that can be called like i(v) to get the interpolated value at v. LinearInterpolation from DataInterpolations.jl is a good choice, but a lookup table can also be used.

Connectors

  • input of type RealInput connects to $u$.
  • output of type RealOutput connects to $y$.
  • scheduling_input of type RealInput connects to $v$.
source
ControlSystemsMTK.batch_ss — Method
batch_ss(sys, inputs, outputs, ops::AbstractVector{<:AbstractDict};
            t = 0.0,
            allow_input_derivatives = false,
            kwargs...)

Linearize sys in multiple operating points ops::Vector{Dict}. Returns a vector of StateSpace objects and the simplified system.

Example:

using ControlSystemsMTK, ModelingToolkit, RobustAndOptimalControl
using ModelingToolkit: getdefault
unsafe_comparisons(true)

# Create a model
@parameters t k=10 k3=2 c=1
@variables x(t)=0 [bounds = (-2, 2)]
@variables v(t)=0
@variables u(t)=0
@variables y(t)

D = Differential(t)

eqs = [D(x) ~ v
       D(v) ~ -k * x - k3 * x^3 - c * v + 10u
       y ~ x]


@named duffing = System(eqs, t)

bounds = getbounds(duffing, unknowns(duffing))
sample_within_bounds((l, u)) = (u - l) * rand() + l
# Create a vector of operating points
N = 10
ops = map(1:N) do i
    op = Dict(x => sample_within_bounds(bounds[x]) for x in keys(bounds) if isfinite(bounds[x][1]))
end

Ps, ssys = batch_ss(duffing, [u], [y], ops)
w = exp10.(LinRange(-2, 2, 200))
bodeplot(Ps, w)
P = RobustAndOptimalControl.ss2particles(Ps) # convert to a single StateSpace system with `Particles` as coefficients.
bodeplot(P, w) # Should look similar to the one above

Let's also do some tuning for the linearized models above

function batch_tune(f, Ps)
    f.(Ps)
end

Cs = batch_tune(Ps) do P
    # C, kp, ki, fig, CF = loopshapingPI(P, 6; phasemargin=45)
    C, kp, ki, kd, fig, CF = loopshapingPID(P, 6; Mt=1.3, Tf = 1/100)
    ss(CF)
end

P = RobustAndOptimalControl.ss2particles(Ps)
C = RobustAndOptimalControl.ss2particles(Cs)

nyquistplot(P * C,
            w,
            ylims = (-10, 3),
            xlims = (-5, 10),
            points = true,
            Ms_circles = [1.5, 2],
            Mt_circles = [1.5, 2])

# Fit circles that encircle the Nyquist curve for each frequency
centers, radii = fit_complex_perturbations(P * C, w; relative = false, nominal = :center)
nyquistcircles!(w, centers, radii, ylims = (-4, 1), xlims = (-3, 4))

See also trajectory_ss.

source
ControlSystemsMTK.build_quadratic_cost_matrix — Method
build_quadratic_cost_matrix(linear_sys, ssys::System, costs::Vector{Pair})

For a system that has been linearized, assemble a quadratic cost matrix (for LQR or Kalman filtering) that penalizes states or outputs of simplified system ssys according to the vector of pairs costs.

The motivation for this function is that ModelingToolkit does not guarantee

  • Which states are selected as states after simplification.
  • The order of the states.

The second problem above, the ordering of the states, can be worked around using reorder_unknowns, but the first problem cannot be solved by trivial reordering. This function thus accepts an array of costs for a user-selected state realization, and assembles the correct cost matrix for the state realization selected by MTK. To do this, the funciton needs the linearization (linear_sys) as well as the simplified system, both of which are outputs of linearize.

Arguments:

source
ControlSystemsMTK.build_quadratic_cost_matrix — Method
build_quadratic_cost_matrix(sys::System, inputs::Vector, costs::Vector{Pair}; kwargs...)

Assemble a quadratic cost matrix (for LQR or Kalman filtering) that penalizes states or outputs of system sys according to the vector of pairs costs.

The motivation for this function is that ModelingToolkit does not guarantee

  • Which states are selected as states after simplification.
  • The order of the states.

The second problem above, the ordering of the states, can be worked around using reorder_unknowns, but the first problem cannot be solved by trivial reordering. This function thus accepts an array of costs for a user-selected state realization, and assembles the correct cost matrix for the state realization selected by MTK. To do this, the funciton performs a linearization between inputs and the cost outputs. The linearization is used to determine the matrix entries belonging to states that are not part of the realization chosen by MTK.

Arguments:

  • sys: The system to be linearized (not simplified).
  • inputs: A vector of variables that are to be considered controlled inputs for the LQR controller.
  • costs: A vector of pairs.
source
ControlSystemsMTK.trajectory_ss — Method
linsystems, ssys = trajectory_ss(sys, inputs, outputs, sol; t = _max_100(sol.t), kwargs...)

Linearize sys around the trajectory sol at times t. Returns a vector of StateSpace objects and the simplified system.

Operating points are extracted from the solution automatically using ModelingToolkit.LinearizationOpPoint.

Arguments:

  • inputs: A vector of variables or analysis points.
  • outputs: A vector of variables or analysis points.
  • sol: An ODE solution object.
  • t: Time points along the solution trajectory at which to linearize. The returned array of StateSpace objects will be of the same length as t.
  • loop_openings: A list of analysis points whose connections are broken during the linearization. Each opened signal becomes a parameter that ModelingToolkit holds at the value it has in the loop-closed solution sol at each time point, such that the linearization is performed around the trajectory also for the opened signals. To linearize around some other value for an opened signal, supply it through op.
  • op: A Dict of operating-point values overriding those obtained from sol, e.g. op = Dict(sys.opened_signal => 0). Symbolic values are resolved from sol at every time point. The values are merged into the solution-derived operating point at every time point.
  • kwargs: Are sent to the linearization functions.
  • named: If true, the returned systems will be of type NamedStateSpace, otherwise they will be of type StateSpace.
source
RobustAndOptimalControl.named_ss — Method
RobustAndOptimalControl.named_ss(sys::ModelingToolkit.AbstractSystem, inputs, outputs; descriptor=true, simple_infeigs=true, balance=false, kwargs...)

Convert an System to a NamedStateSpace using linearization. inputs, outputs are vectors of variables determining the inputs and outputs respectively. See docstring of ModelingToolkit.linearize for more info on kwargs.

If descriptor = true (default), this method automatically converts systems that MTK has failed to produce a proper form for into a proper linear statespace system using the method described here: https://juliacontrol.github.io/ControlSystemsMTK.jl/dev/#Internals:-Transformation-of-non-proper-models-to-proper-statespace-form If descriptor = false, the system is instead converted to a statespace realization using sys[:,uinds] + sys[:,duinds]*tf('s'), which tends to result in a larger realization on which the user may want to call minreal(sys, tol) with a carefully selected tolerance.

See also ModelingToolkit.linearize which is the lower-level function called internally. The functions get_named_sensitivity, get_named_comp_sensitivity, get_named_looptransfer similarily provide convenient ways to compute sensitivity functions while retaining signal names in the same way as named_ss. The corresponding lower-level functions get_sensitivity, get_comp_sensitivity and get_looptransfer are available in ModelingToolkitStandardLibrary.Blocks and are documented in MTKstdlib: Linear analysis.

source
ControlSystemsBase.bodeplot — Function
fig = bodeplot(sys, args...)
bodeplot(LTISystem[sys1, sys2...], args...; plotphase=true, balance = true, kwargs...)

Create a Bode plot of the LTISystem(s). A frequency vector w can be optionally provided. To change the Magnitude scale see setPlotScale. The default magnitude scale is "log10" (absolute scale).

  • If hz=true, the plot x-axis will be displayed in Hertz, the input frequency vector is still treated as rad/s.
  • balance: Call balance_statespace on the system before plotting.
  • adjust_phase_start: If true, the phase will be adjusted so that it starts at -90*intexcess degrees, where intexcess is the integrator excess of the system.
  • adaptive: If true, an adaptive frequency grid is used in order to keep the number of plotted points low, while resolving features in the frequency response well. If a manually provided frequency vector is used, this may be downsampled before plotting.

kwargs is sent as argument to RecipesBase.plot.

source
ModelingToolkit.linearize — Function
(; A, B, C, D), simplified_sys, extras = linearize(sys, inputs, outputs;    t=0.0, op = Dict(), allow_input_derivatives = false, zero_dummy_der=false, kwargs...)
(; A, B, C, D), extras                 = linearize(simplified_sys, lin_fun; t=0.0, op = Dict(), allow_input_derivatives = false, zero_dummy_der=false)

Linearize sys between inputs and outputs, both vectors of variables. Return a NamedTuple with the matrices of a linear statespace representation on the form

\[\begin{aligned} ẋ &= Ax + Bu\\ y &= Cx + Du \end{aligned}\]

The first signature automatically calls linearization_function internally, while the second signature expects the outputs of linearization_function as input.

op denotes the operating point around which to linearize. If none is provided, the default values of sys are used.

If allow_input_derivatives = false, an error will be thrown if input derivatives ($u̇$) appear as inputs in the linearized equations. If input derivatives are allowed, the returned B matrix will be of double width, corresponding to the input [u; u̇].

zero_dummy_der can be set to automatically set the operating point to zero for all dummy derivatives.

The return value extras is a NamedTuple (; x, p, t) containing the result of the initialization problem that was solved to determine the operating point.

See also linearization_function which provides a lower-level interface, linearize_symbolic and ModelingToolkit.reorder_unknowns.

See extended help for an example.

The implementation and notation follows that of "Linear Analysis Approach for Modelica Models", Allain et al. 2009

Extended help

This example builds the following feedback interconnection and linearizes it from the input of F to the output of P.


  r ┌─────┐       ┌─────┐     ┌─────┐
───►│     ├──────►│     │  u  │     │
    │  F  │       │  C  ├────►│  P  │ y
    └─────┘     ┌►│     │     │     ├─┬─►
                │ └─────┘     └─────┘ │
                │                     │
                └─────────────────────┘
using ModelingToolkit
using ModelingToolkit: t_nounits as t, D_nounits as D
function plant(; name)
    @variables x(t) = 1
    @variables u(t)=0 y(t)=0
    eqs = [D(x) ~ -x + u
           y ~ x]
    System(eqs, t; name = name)
end

function ref_filt(; name)
    @variables x(t)=0 y(t)=0
    @variables u(t)=0 [input = true]
    eqs = [D(x) ~ -2 * x + u
           y ~ x]
    System(eqs, t, name = name)
end

function controller(kp; name)
    @variables y(t)=0 r(t)=0 u(t)=0
    @parameters kp = kp
    eqs = [
        u ~ kp * (r - y),
    ]
    System(eqs, t; name = name)
end

@named f = ref_filt()
@named c = controller(1)
@named p = plant()

connections = [f.y ~ c.r # filtered reference to controller reference
               c.u ~ p.u # controller output to plant input
               p.y ~ c.y]

@named cl = System(connections, t, systems = [f, c, p])

lsys0, ssys = linearize(cl, [f.u], [p.x])
desired_order = [f.x, p.x]
lsys = ModelingToolkit.reorder_unknowns(lsys0, unknowns(ssys), desired_order)

@assert lsys.A == [-2 0; 1 -2]
@assert lsys.B == [1; 0;;]
@assert lsys.C == [0 1]
@assert lsys.D[] == 0

## Symbolic linearization
lsys_sym, _ = ModelingToolkit.linearize_symbolic(cl, [f.u], [p.x])

@assert substitute(lsys_sym.A, ModelingToolkit.defaults(cl)) == lsys.A
source
ModelingToolkit.linearization_function — Function
lin_fun, simplified_sys = linearization_function(sys::AbstractSystem, inputs, outputs; simplify = false, initialize = true, initialization_solver_alg = nothing, kwargs...)

Return a function that linearizes the system sys. The function linearize provides a higher-level and easier to use interface.

lin_fun is a function (variables, p, t) -> (; f_x, f_z, g_x, g_z, f_u, g_u, h_x, h_z, h_u), i.e., it returns a NamedTuple with the Jacobians of f,g,h for the nonlinear sys (technically for simplified_sys) on the form

\[\begin{aligned} ẋ &= f(x, z, u) \\ 0 &= g(x, z, u) \\ y &= h(x, z, u) \end{aligned}\]

where x are differential unknown variables, z algebraic variables, u inputs and y outputs. To obtain a linear statespace representation, see linearize. The input argument variables is a vector defining the operating point, corresponding to unknowns(simplified_sys) and p is a vector corresponding to the parameters of simplified_sys. Note: all variables in inputs have been converted to parameters in simplified_sys.

The simplified_sys has undergone ModelingToolkitBase.mtkcompile and had any occurring input or output variables replaced with the variables provided in arguments inputs and outputs. The unknowns of this system also indicate the order of the unknowns that holds for the linearized matrices.

Arguments:

  • sys: A System of ODEs. This function will automatically apply simplification passes on sys and return the resulting simplified_sys.
  • inputs: A vector of variables that indicate the inputs of the linearized input-output model.
  • outputs: A vector of variables that indicate the outputs of the linearized input-output model.
  • simplify: Apply simplification in tearing.
  • initialize: If true, a check is performed to ensure that the operating point is consistent (satisfies algebraic equations). If the op is not consistent, initialization is performed.
  • initialization_solver_alg: A NonlinearSolve algorithm to use for solving for a feasible set of state and algebraic variables that satisfies the specified operating point.
  • autodiff: An ADType supported by DifferentiationInterface.jl to use for calculating the necessary jacobians. Defaults to using AutoForwardDiff()
  • op: The operating point, a dictionary or a LinearizationOpPoint. A LinearizationOpPoint determines the operating point and t from its solution at its first time point, and implies ignore_system_initial_conditions = true, as in linearize. This allows passing a LinearizationOpPoint to the functions that build on linearization_function, such as get_sensitivity.
  • ignore_system_initial_conditions: Whether to ignore initial_conditions(sys) and only use op.
  • kwargs: Are passed on to find_solvables!

See also linearize which provides a higher-level interface.

source
ControlSystemsBase.loopshapingPID — Function
C, kp, ki, kd, fig, CF = loopshapingPID(P, ω; Mt = 1.3, ϕt=75, form=:standard, doplot=false, lb=-10, ub=10, Tf = 1/1000ω, F = nothing)

Selects the parameters of a PID-controller such that the Nyquist curve of the loop-transfer function $L = PC$ at the frequency ω is tangent to the circle where the magnitude of $T = PC / (1+PC)$ equals Mt. ϕt denotes the positive angle in degrees between the real axis and the tangent point.

The default values for Mt and ϕt are chosen to give a good design for processes with inertia, and may need tuning for simpler processes.

The gain of the resulting controller is generally increasing with increasing ω and Mt.

Arguments:

  • P: A SISO plant.
  • ω: The specification frequency.
  • Mt: The magnitude of the complementary sensitivity function at the specification frequency, $|T(iω)|$.
  • ϕt: The positive angle in degrees between the real axis and the tangent point.
  • doplot: If true, gang of four and Nyquist plots will be returned in fig.
  • lb: log10 of lower bound for kd.
  • ub: log10 of upper bound for kd.
  • Tf: Time constant for second-order measurement noise filter on the form tf(1, [Tf^2, 2*Tf/sqrt(2), 1]) to make the controller strictly proper. A practical controller typically sets this time constant slower than the default, e.g., Tf = 1/100ω or Tf = 1/10ω
  • F: A pre-designed filter to use instead of the default second-order filter.

The parameters can be returned as one of several common representations chosen by form, the options are

  • :standard - $K_p(1 + 1/(T_i s) + T_ds)$
  • :series - $K_c(1 + 1/(τ_i s))(τ_d s + 1)$
  • :parallel - $K_p + K_i/s + K_d s$

See also loopshapingPI, pidplots, stabregionPID and placePI.

Example:

P  = tf(1, [1,0,0]) # A double integrator
Mt = 1.3  # Maximum magnitude of complementary sensitivity
ω  = 1    # Frequency at which the specification holds
C, kp, ki, kd, fig, CF = loopshapingPID(P, ω; Mt, ϕt = 75, doplot=true)
source
RobustAndOptimalControl.named_ss — Function
RobustAndOptimalControl.named_ss(sys::ModelingToolkit.AbstractSystem, inputs, outputs; descriptor=true, simple_infeigs=true, balance=false, kwargs...)

Convert an System to a NamedStateSpace using linearization. inputs, outputs are vectors of variables determining the inputs and outputs respectively. See docstring of ModelingToolkit.linearize for more info on kwargs.

If descriptor = true (default), this method automatically converts systems that MTK has failed to produce a proper form for into a proper linear statespace system using the method described here: https://juliacontrol.github.io/ControlSystemsMTK.jl/dev/#Internals:-Transformation-of-non-proper-models-to-proper-statespace-form If descriptor = false, the system is instead converted to a statespace realization using sys[:,uinds] + sys[:,duinds]*tf('s'), which tends to result in a larger realization on which the user may want to call minreal(sys, tol) with a carefully selected tolerance.

See also ModelingToolkit.linearize which is the lower-level function called internally. The functions get_named_sensitivity, get_named_comp_sensitivity, get_named_looptransfer similarily provide convenient ways to compute sensitivity functions while retaining signal names in the same way as named_ss. The corresponding lower-level functions get_sensitivity, get_comp_sensitivity and get_looptransfer are available in ModelingToolkitStandardLibrary.Blocks and are documented in MTKstdlib: Linear analysis.

source
named_ss(sys::AbstractStateSpace{T}; x, u, y)

Create a NamedStateSpace system. This kind of system uses names rather than integer indices to refer to states, inputs and outputs.

  • If a single name is provided but a vector of names is expected, this name will be used as prefix followed by a numerical index.
  • If no name is provided, default names (x,y,u) will be used.

Arguments:

  • sys: A system to add names to.
  • x: A list of symbols with names of the states.
  • u: A list of symbols with names of the inputs.
  • y: A list of symbols with names of the outputs.

Example

G1 = ss(1,1,1,0)
G2 = ss(1,1,1,0)
s1 = named_ss(G1, x = :x, u = :u1, y=:y1)
s2 = named_ss(G2, x = :z, u = :u2, y=:y2)

s1[:y1, :u1] # Index using symbols. Uses prefix matching if no exact match is found.

fb = feedback(s1, s2, r = :r) # 
source
named_ss(sys::AbstractStateSpace, name; x, y, u)

If a single name of the system is provided, the outputs, inputs and states will be automatically named y,u,x with name as prefix.

source
named_ss(sys::ExtendedStateSpace;       kwargs...)
named_ss(sys::ExtendedStateSpace, name; kwargs...)

Assign names to an ExtendedStateSpace. If no specific names are provided for signals z,y,w,u and statesx, names will be generated automatically.

Arguments:

  • name: Prefix to add to all automatically generated names.
  • x
  • u
  • y
  • w
  • z
source
Missing docstring.

Missing docstring for get_named_sensitivity. Check Documenter's build log for details.

Missing docstring.

Missing docstring for get_named_comp_sensitivity. Check Documenter's build log for details.

Missing docstring.

Missing docstring for get_named_looptransfer. Check Documenter's build log for details.

ModelingToolkit.linearize_symbolic — Function
matrices, simplified_sys = linearize_symbolic(sys::AbstractSystem, inputs, outputs;
    simplify = false,
    allow_input_derivatives = false,
    eval_expression = false,
    eval_module = @__MODULE__,
    split = true,
    kwargs...)

Symbolically linearize sys between inputs and outputs.

Unlike linearize, this uses Symbolics.jacobian and returns symbolic matrices instead of numerical matrices evaluated at an operating point.

Arguments

  • sys: the system to linearize. This function calls ModelingToolkitBase.mtkcompile internally.
  • inputs: input variables used as the columns of the B and D matrices.
  • outputs: output variables used as the rows of the C and D matrices.

Keyword Arguments

  • simplify: whether to run additional symbolic simplification during compilation.
  • allow_input_derivatives: whether differentiated inputs may appear in the linearized equations. If true, B and D include extra columns for those derivatives.
  • eval_expression: whether generated expressions are evaluated directly instead of using runtime-generated functions.
  • eval_module: the module used when eval_expression = true.
  • split: whether generated functions use a tuple of parameters or splatted parameters.
  • kwargs...: additional keyword arguments forwarded to ModelingToolkitBase.mtkcompile.

Returns

A pair (matrices, simplified_sys). matrices is a NamedTuple containing A, B, C, and D, plus the symbolic Jacobian blocks f_x, f_z, g_x, g_z, f_u, g_u, h_x, h_z, and h_u of

\[\begin{aligned} ẋ &= f(x, z, u) \\ 0 &= g(x, z, u) \\ y &= h(x, z, u) \end{aligned}\]

Here x are differential unknowns, z are algebraic unknowns, u are inputs, and y are outputs.

Examples

using ModelingToolkit
using ModelingToolkit: t_nounits as t, D_nounits as D

@variables x(t) = 1.0 u(t) = 0.0 y(t) = 0.0
eqs = [D(x) ~ -x + u,
       y ~ x]
@named sys = System(eqs, t)

matrices, simplified_sys = ModelingToolkit.linearize_symbolic(sys, [u], [y])
matrices.A

See also linearize, linearization_function, and reorder_unknowns.

source
ModelingToolkit.get_sensitivity — Function
get_sensitivity(sys, ap; loop_openings = [], system_modifier = identity, op = Dict(), kwargs...)

Compute the sensitivity transfer matrices at analysis point ap and return (matrices, simplified_system, extras). This introduces an infinitesimal perturbation at the input of ap, linearizes the system, and computes the transfer function from the perturbation to the output of ap.

Arguments

  • sys: The unsimplified, uncompleted system containing the analysis point. Both mtkcompile and complete remove the analysis points, so neither may have been applied to sys.
  • ap: An AnalysisPoint, obtained by property access on sys, as in get_sensitivity(sys, sys.plant_input). A point belonging to a subsystem is reached through the hierarchy, sys.inner.plant_input. Passing the Symbol name of the point, get_sensitivity(sys, :plant_input), is the old style and will be deprecated.

Keyword Arguments

  • loop_openings: connections to open before linearization.
  • system_modifier: transformation applied before linearization.
  • op: operating-point values passed to linearize, a dictionary or a LinearizationOpPoint.
  • allow_input_derivatives: allow derivatives of input variables in the linearization.
  • t: time at which to evaluate the linearization.
  • kwargs...: forwarded to get_sensitivity_function.

See also get_comp_sensitivity and get_looptransfer.

source
ModelingToolkit.get_comp_sensitivity — Function
get_comp_sensitivity(sys, ap; loop_openings = [], system_modifier = identity, op = Dict(), kwargs...)

Compute the complementary-sensitivity transfer matrices at analysis point ap and return (matrices, simplified_system, extras). This introduces an infinitesimal perturbation at the output of ap, linearizes the system, and computes the transfer function from the perturbation to the input of ap.

Arguments and keyword arguments match get_sensitivity, with kwargs... forwarded to get_comp_sensitivity_function.

See also get_sensitivity and get_looptransfer.

source
ModelingToolkit.get_looptransfer — Function
get_looptransfer(sys, ap; loop_openings = [], system_modifier = identity, op = Dict(), kwargs...)

Compute the loop-transfer matrices at analysis point ap and return (matrices, simplified_system, extras). The transfer is from ap.out to ap.in.

Arguments and keyword arguments match get_sensitivity, with kwargs... forwarded to get_looptransfer_function.

Negative feedback

The computed loop transfer includes negative feedback. Negate the result when using an analysis tool that expects a loop-transfer function without the negative gain.

See also get_sensitivity, get_comp_sensitivity, and open_loop.

source
ModelingToolkitStandardLibrary.Blocks.StateSpace — Function
StateSpace(A, B, C, D = 0; x = zeros(size(A,1)), u0 = zeros(size(B,2)), y0 = zeros(size(C,1)), name)

A linear, time-invariant state-space system on the form.

\[\begin{aligned} ẋ &= Ax + Bu \\ y &= Cx + Du \end{aligned}\]

Transfer functions can also be simulated by converting them to a StateSpace form.

y0 and u0 can be used to set an operating point, providing them changes the dynamics from an LTI system to the affine system

\[\begin{aligned} ẋ &= Ax + B(u - u0) \\ y &= Cx + D(u - u0) + y0 \end{aligned}\]

For a nonlinear system

\[\begin{aligned} ẋ &= f(x, u) \\ y &= h(x, u) \end{aligned}\]

linearized around the operating point x₀, u₀, we have y0, u0 = h(x₀, u₀), u₀.

source
ControlSystemsBase.StateSpace — Type
StateSpace{TE, T} <: AbstractStateSpace{TE}

An object representing a standard state space system.

See the function ss for a user facing constructor as well as the documentation page creating systems.

Fields:

  • A::Matrix{T}
  • B::Matrix{T}
  • C::Matrix{T}
  • D::Matrix{T}
  • timeevol::TE
source
SymbolicControlSystems.ccode — Function
ccode(G; simplify = identity, cse = true, static = true, double = true)

Return a string with C-code for filtering a signal u through G.

If G is a transfer function, the system must be SISO, for MIMO systems, use a StateSpace model instead.

With a transfer function as input, the code will return a double corresponding to the single output. With a StateSpace model as input, the code will produce a function that takes a double pointer double *y as the first input argument. Make sure that y points to an array of length G.ny before calling the function.

The state is internally handled by C static variables, so the generated code is thus stateful.

Arguments:

  • G: A linear system
  • simplify: A function for symbolic simplification. You may try Sympy.simplify, but for large systems, this will take a long time to compute.
  • cse: Perform common subexpression elimination. This generally improves the performance of the generated code.
  • static: If true, the generated code will use static variables to store the state of the system. If false, the function will take pointers to the state variables as input arguments.
  • double: If true, the generated code will use double as the numeric type. If false, it will use float.
source
SymbolicControlSystems.print_c_array — Function
print_c_array(io, a::Vector{<:AbstractArray}, t::AbstractVector, name = "mat"; cse = false, s = "", print_vector = true, print_logic = true, struct_name::Union{Nothing, String} = nothing, struct_type = nothing, ivecname = name * "_interp_vect")

Write C-code for interpolating between arrays a. The array t contains the interpolation points.

source
print_c_array(io, sys::Vector{<:AbstractStateSpace}, t::AbstractVector, name = "sys"; cse = false, s = "", en = "", struct_name::Union{Nothing, String} = nothing, struct_type = nothing)

Write C-code for an interpolated linear system. The interpolation vector t defines the interpolation points, this vector is expected to be of the same length as the vector of linear systems sys.

  • s, en: are strings that are appended at the start and end of variables names in the C-code.
  • struct_name: If provided, the interpolation matrices will be placed inside a struct with this name.
  • struct_type: If the struct name is used, provide also the C type of the struct.
source
ModelingToolkit.reorder_unknowns — Function
reorder_unknowns(sys::NamedTuple, old, new)

Permute the state ordering of a linearized system.

Arguments

  • sys: a NamedTuple with matrices A, B, C, and D, as returned by linearize or linearize_symbolic.
  • old: the current state order, typically unknowns(simplified_sys).
  • new: the desired state order. It must contain the same entries as old.

Returns

A NamedTuple (; A, B, C, D) whose state-space matrices use the order new.

Examples

lsys, ssys = linearize(pid, [reference.u, measurement.u], [ctr_output.u])
desired_order = [int.x, der.x] # Unknowns that are present in unknowns(ssys)
lsys = ModelingToolkit.reorder_unknowns(lsys, unknowns(ssys), desired_order)

See also similarity_transform.

source