You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
add option to simplify causality in a different way (#73)
* add option to simplify causality in a different way
* provide some variables for operating points
* fixes in batchlin
* init fixes
* rm import
* more inits
To perform batch linearization, we create a vector of operating points, and then linearize the model around each of these points. The function [`batch_ss`](@ref) does this for us, and returns a vector of `StateSpace` models, one for each operating point. An operating point is a `Dict` that maps variables in the MTK model to numerical values. In the example below, we simply sample the variables uniformly within their bounds specified when we created the variables (normally, we might want to linearize on stationary points)
Just like [`ModelingToolkit.linearize`](@ref), [`batch_ss`](@ref) takes the set of inputs and the set of outputs to linearize between.
@@ -96,7 +95,7 @@ If you plot the Nyquist curve using the `plotly()` backend rather than the defau
96
95
Above, we tuned one controller for each operating point, wouldn't it be nice if we had some features to simulate a [gain-scheduled controller](https://en.wikipedia.org/wiki/Gain_scheduling) that interpolates between the different controllers depending on the operating pont? [`GainScheduledStateSpace`](@ref) is such a thing, we show how to use it below. For fun, we simulate some reference step responses for each individual controller in the array `Cs` and end with simulating the gain-scheduled controller.
97
96
98
97
```@example BATCHLIN
99
-
using OrdinaryDiffEq
98
+
using OrdinaryDiffEqNonlinearSolve, OrdinaryDiffEqRosenbrock
100
99
using DataInterpolations # Required to interpolate between the controllers
@@ -155,7 +154,7 @@ The generated code starts by defining the interpolation vector `xs`, this variab
155
154
We can linearize around a trajectory obtained from `solve` using the function [`trajectory_ss`](@ref). We provide it with a vector of time points along the trajectory at which to linearize, and in this case we specify the inputs and outputs to linearize between as analysis points `r` and `y`.
Convert an `ODESystem` 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`.
160
160
161
-
This method automatically converts systems that MTK has failed to produce a proper form for into a proper linear statespace system. Learn more about how that is done here:
161
+
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:
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.
164
+
163
165
164
166
See also [`ModelingToolkit.linearize`](@ref) which is the lower-level function called internally. The functions [`get_named_sensitivity`](@ref), [`get_named_comp_sensitivity`](@ref), [`get_named_looptransfer`](@ref) 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](https://docs.sciml.ai/ModelingToolkitStandardLibrary/stable/API/linear_analysis/).
165
167
"""
166
168
function RobustAndOptimalControl.named_ss(
167
169
sys::ModelingToolkit.AbstractTimeDependentSystem,
168
170
inputs,
169
171
outputs;
172
+
descriptor =true,
170
173
kwargs...,
171
174
)
172
175
@@ -206,7 +209,7 @@ function RobustAndOptimalControl.named_ss(
206
209
# This indicates that input derivatives are present
207
210
duinds =findall(any(!iszero, eachcol(matrices.B[:, nu+1:end]))) .+ nu
208
211
u2du = (1:nu) .=> duinds # This maps inputs to their derivatives
@@ -295,7 +298,7 @@ using ModelingToolkitStandardLibrary.Mechanical.TranslationalPosition
295
298
using Test
296
299
297
300
using ControlSystemsMTK
298
-
using ControlSystemsMTK.ControlSystemsBase: sminreal, minreal, poles
301
+
using ControlSystemsMTK.ControlSystemsBase: sminreal, minreal, poles, ss, tf
299
302
connect = ModelingToolkit.connect
300
303
301
304
@independent_variables t
@@ -348,3 +351,38 @@ op2[cart.f] = 0
348
351
@test G.nx ==4
349
352
@test G.nu ==length(lin_inputs)
350
353
@test G.ny ==length(lin_outputs)
354
+
355
+
## Test difficult `named_ss` simplification
356
+
using ControlSystemsMTK, ControlSystemsBase, RobustAndOptimalControl
357
+
lsys = (A = [0.02.778983834717109e81.4122312296634873e60.0; 0.00.00.00.037848975765016724; 0.024.8375411480749620.126220062308977120.0; -0.0-4.620724819774693-0.023481719514324866-0.6841991610512456], B = [-5.042589978197361e80.0; -0.00.0; -45.068824982602656-0.0; 8.38451104936908554.98555939873381], C = [0.00.00.9549296585513720.0], D = [0.00.0])
358
+
359
+
# lsys = (A = [-0.0075449237853825925 1.6716817118020731e-6 0.0; 1864.7356343162514 -0.4131578457122937 0.0; 0.011864343330426718 -2.6287085638214332e-6 0.0], B = [0.0 0.0; 0.0 52566.418015009294; 0.0 0.3284546792274811], C = [1.4683007399899215e8 0.0 0.0], D = [-9.157636303058283e7 0.0])
360
+
361
+
G = ControlSystemsMTK.causal_simplification(lsys, [1=>2])
0 commit comments