Skip to content

Commit 3bf3052

Browse files
committed
Initialize estimation covariance in sim!
1 parent dd2e7a1 commit 3bf3052

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

src/plot_sim.jl

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ The manipulated inputs ``\mathbf{u}`` and measured disturbances ``\mathbf{d}`` a
2121
constant at `u` and `d` values, respectively. The plant initial state ``\mathbf{x}(0)`` is
2222
specified by `x0` keyword arguments. The function returns `SimResult` instances that can be
2323
visualized by calling `plot` from [`Plots.jl`](https://github.com/JuliaPlots/Plots.jl) on
24-
them (see Examples below).
24+
them (see Examples below). Note that the method mutates `plant` internal states.
2525
2626
# Examples
2727
```julia-repl
@@ -182,12 +182,8 @@ function sim_closedloop!(
182182
X̂_data = Matrix{Float64}(undef, estim.nx̂, N)
183183
setstate!(plant, x0)
184184
lastd, lasty = d, evaloutput(plant, d)
185-
if isnothing(x̂0)
186-
initstate!(est_mpc, lastu, lasty[estim.i_ym], lastd)
187-
188-
else
189-
setstate!(est_mpc, x̂0)
190-
end
185+
initstate!(est_mpc, lastu, lasty[estim.i_ym], lastd)
186+
isnothing(x̂0) || setstate!(est_mpc, x̂0)
191187
for i=1:N
192188
d = lastd + d_step + d_noise.*randn(plant.nd)
193189
y = evaloutput(plant, d) + y_step + y_noise.*randn(plant.ny)

0 commit comments

Comments
 (0)