Skip to content

Commit a7fd9f3

Browse files
committed
turn off existing defaults
1 parent ba9bd65 commit a7fd9f3

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

docs/src/batch_linearization.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ P = RobustAndOptimalControl.ss2particles(Ps) # convert to a single StateSpace sy
5656

5757
notice how some coefficients are plotted like uncertain numbers `-13.8 ± 4.3`. We can plot such models as well:
5858
```@example BATCHLIN
59-
bodeplot(P, w, legend=:bottomright) # Should look similar to the one above
59+
bodeplot(P, w, legend=:bottomright, adaptive=false) # Should look similar to the one above
6060
```
6161

6262
## Controller tuning
@@ -154,7 +154,7 @@ The generated code starts by defining the interpolation vector `xs`, this variab
154154
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`.
155155
```@example BATCHLIN
156156
timepoints = 0:0.01:8
157-
Ps2, ssys = trajectory_ss(closed_loop, closed_loop.r, closed_loop.y, sol; t=timepoints, initialize=true, verbose=true)
157+
Ps2, ssys = trajectory_ss(closed_loop, closed_loop.r, closed_loop.y, sol; t=timepoints, verbose=true)
158158
bodeplot(Ps2, w, legend=false)
159159
```
160160

src/ode_system.jl

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -425,24 +425,26 @@ Linearize `sys` around the trajectory `sol` at times `t`. Returns a vector of `S
425425
function trajectory_ss(sys, inputs, outputs, sol; t = _max_100(sol.t), allow_input_derivatives = false, fuzzer = nothing, verbose = true, kwargs...)
426426
maximum(t) > maximum(sol.t) && @warn("The maximum time in `t`: $(maximum(t)), is larger than the maximum time in `sol.t`: $(maximum(sol.t)).")
427427
minimum(t) < minimum(sol.t) && @warn("The minimum time in `t`: $(minimum(t)), is smaller than the minimum time in `sol.t`: $(minimum(sol.t)).")
428-
429428
# NOTE: we call linearization_funciton twice :( The first call is to get x=unknowns(ssys), the second call provides the operating points.
430429
# lin_fun, ssys = linearization_function(sys, inputs, outputs; warn_initialize_determined = false, kwargs...)
431-
lin_fun, ssys = linearization_function(sys, inputs, outputs; warn_initialize_determined = false, kwargs...)
430+
lin_fun, ssys = linearization_function(sys, inputs, outputs; warn_empty_op = false, warn_initialize_determined = false, kwargs...)
432431

433432
x = unknowns(ssys)
433+
op_nothing = Dict(unknowns(sys) .=> nothing) # Remove all defaults present in the original system
434434
defs = ModelingToolkit.defaults(sys)
435435
ops = map(t) do ti
436-
Dict(x => robust_sol_getindex(sol, ti, x, defs; verbose) for x in x)
436+
opsol = Dict(x => robust_sol_getindex(sol, ti, x, defs; verbose) for x in x)
437+
merge(op_nothing, opsol)
437438
end
439+
# @show ops[1]
438440
if fuzzer !== nothing
439441
opsv = map(ops) do op
440442
fuzzer(op)
441443
end
442444
ops = reduce(vcat, opsv)
443445
t = repeat(t, inner = length(ops) ÷ length(t))
444446
end
445-
# lin_fun, ssys = linearization_function(sys, inputs, outputs; op=ops[1], initialize, kwargs...)
447+
lin_fun, ssys = linearization_function(sys, inputs, outputs; op=ops[1], kwargs...) # initializealg=ModelingToolkit.SciMLBase.NoInit()
446448
lins = map(zip(ops, t)) do (op, t)
447449
linearize(ssys, lin_fun; op, t, allow_input_derivatives)
448450
# linearize(sys, inputs, outputs; op, t, allow_input_derivatives, initialize=false)[1]
@@ -584,10 +586,10 @@ function GainScheduledStateSpace(systems, vt; interpolator, x = zeros(systems[1]
584586
description = "Scheduling variable of gain-scheduled statespace system $name",
585587
]
586588

587-
@variables A(v)[1:nx, 1:nx] = systems[1].A
588-
@variables B(v)[1:nx, 1:nu] = systems[1].B
589-
@variables C(v)[1:ny, 1:nx] = systems[1].C
590-
@variables D(v)[1:ny, 1:nu] = systems[1].D
589+
@variables A(t)[1:nx, 1:nx] = systems[1].A
590+
@variables B(t)[1:nx, 1:nu] = systems[1].B
591+
@variables C(t)[1:ny, 1:nx] = systems[1].C
592+
@variables D(t)[1:ny, 1:nu] = systems[1].D
591593
A,B,C,D = collect.((A,B,C,D))
592594

593595
eqs = [

0 commit comments

Comments
 (0)