@@ -106,13 +106,14 @@ end
106106
107107
108108@doc raw """
109- sim!(plant::SimModel, N::Int, u=plant.uop.+1, d=plant.dop; x_0=plant.xop) -> res
109+ sim!(plant::SimModel, N::Int, u=plant.uop.+1, d=plant.dop; x_0=plant.xop, progress=true ) -> res
110110
111111Open-loop simulation of `plant` for `N` time steps, default to unit bump test on all inputs.
112112
113113The manipulated inputs ``\m athbf{u}`` and measured disturbances ``\m athbf{d}`` are held
114114constant at `u` and `d` values, respectively. The plant initial state ``\m athbf{x}(0)`` is
115- specified by `x_0` keyword arguments. The function returns [`SimResult`](@ref) instances
115+ specified by `x_0` keyword arguments. If `progress` is `true`, VS Code will display a
116+ progress percentage of the simulation. The function returns [`SimResult`](@ref) instances
116117that can be visualized by calling `plot` on them. Note that the method mutates `plant`
117118internal states.
118119
@@ -129,15 +130,16 @@ function sim!(
129130 N:: Int ,
130131 u:: Vector = plant. uop.+ 1 ,
131132 d:: Vector = plant. dop;
132- x_0 = plant. xop
133+ x_0 = plant. xop,
134+ progress = true
133135) where {NT<: Real }
134136 T_data = collect (plant. Ts* (0 : (N- 1 )))
135137 Y_data = Matrix {NT} (undef, plant. ny, N)
136138 U_data = Matrix {NT} (undef, plant. nu, N)
137139 D_data = Matrix {NT} (undef, plant. nd, N)
138140 X_data = Matrix {NT} (undef, plant. nx, N)
139141 setstate! (plant, x_0)
140- @progress name= " $(nameof (typeof (plant))) simulation" for i= 1 : N
142+ @progressif progress name= " $(nameof (typeof (plant))) simulation" for i= 1 : N
141143 y = evaloutput (plant, d)
142144 Y_data[:, i] .= y
143145 U_data[:, i] .= u
@@ -187,6 +189,7 @@ vectors. The simulated sensor and process noises of `plant` are specified by `y_
187189- `x̂_0 = nothing` or *`xhat_0`* : initial estimate ``\m athbf{x̂}(0)``, [`initstate!`](@ref)
188190 is used if `nothing`
189191- `lastu = plant.uop` : last plant input ``\m athbf{u}`` for ``\m athbf{x̂}`` initialization
192+ - `progress = true` : display a progress percentage in VS Code if `true`
190193
191194# Examples
192195```jldoctest
@@ -263,6 +266,7 @@ function sim_closedloop!(
263266 x_0 = plant. xop,
264267 xhat_0 = nothing ,
265268 lastu = plant. uop,
269+ progress = true ,
266270 x̂_0 = xhat_0
267271) where {NT<: Real }
268272 model = estim. model
@@ -282,7 +286,7 @@ function sim_closedloop!(
282286 lastd, lasty = d, evaloutput (plant, d)
283287 initstate! (est_mpc, lastu, lasty[estim. i_ym], lastd)
284288 isnothing (x̂_0) || setstate! (est_mpc, x̂_0)
285- @progress name= " $(nameof (typeof (est_mpc))) simulation" for i= 1 : N
289+ @progressif progress name= " $(nameof (typeof (est_mpc))) simulation" for i= 1 : N
286290 d = lastd + d_step + d_noise.* randn (plant. nd)
287291 y = evaloutput (plant, d) + y_step + y_noise.* randn (plant. ny)
288292 ym = y[estim. i_ym]
0 commit comments