@@ -318,18 +318,22 @@ end
318318@doc raw """
319319 sim(
320320 mpc::PredictiveController,
321- N = mpc.Hp + 10 ,
321+ N::Int ,
322322 ry = mpc.estim.model.yop .+ 1,
323323 d = mpc.estim.model.dop;
324324 <keyword arguments>
325325 )
326326
327327Closed-loop simulation of `mpc` controller for `N` time steps, default to setpoint bumps.
328328
329+ See Arguments for the option list. The noise arguments are in standard deviations σ. The
330+ sensor and process noises of the simulated plant are specified by `y_noise` and `x_noise`
331+ arguments, respectively.
332+
329333# Arguments
330334
331335- `mpc::PredictiveController` : predictive controller to simulate
332- - `N = mpc.Hp + 10 ` : simulation length in time steps
336+ - `N::Int ` : simulation length in time steps
333337- `ry = mpc.estim.model.yop .+ 1` : plant output setpoint ``\m athbf{r_y}`` value
334338- `d = mpc.estim.model.dop` : plant measured disturbance ``\m athbf{d}`` value
335339- `plant::SimModel = mpc.estim.model` : simulated plant model
@@ -339,6 +343,7 @@ Closed-loop simulation of `mpc` controller for `N` time steps, default to setpoi
339343- `y_noise = zeros(plant.ny)` : additive gaussian noise on plant outputs ``\m athbf{y}``
340344- `d_step = zeros(plant.nd)` : step disturbance on measured dist. ``\m athbf{d}``
341345- `d_noise = zeros(plant.nd)` : additive gaussian noise on measured dist. ``\m athbf{d}``
346+ - `x_noise = zeros(plant.nx)` : additive gaussian noise on plant states ``\m athbf{x}``
342347- `x0 = zeros(plant.nx)` : plant initial state ``\m athbf{x}(0)``
343348- `x̂0 = nothing` : `mpc.estim` state estimator initial state ``\m athbf{x̂}(0)``, if `nothing`
344349 then ``\m athbf{x̂}`` is initialized with [`initstate!`](@ref)
@@ -347,7 +352,7 @@ Closed-loop simulation of `mpc` controller for `N` time steps, default to setpoi
347352"""
348353function sim (
349354 mpc:: PredictiveController ,
350- N :: Int = mpc . Hp + 10 ,
355+ N:: Int ,
351356 ry:: Vector{<:Real} = mpc. estim. model. yop .+ 1 ,
352357 d :: Vector{<:Real} = mpc. estim. model. dop;
353358 plant:: SimModel = mpc. estim. model,
@@ -357,6 +362,7 @@ function sim(
357362 y_noise:: Vector{<:Real} = zeros (plant. ny),
358363 d_step :: Vector{<:Real} = zeros (plant. nd),
359364 d_noise:: Vector{<:Real} = zeros (plant. nd),
365+ x_noise:: Vector{<:Real} = zeros (plant. nx),
360366 x0 = zeros (plant. nx),
361367 x̂0 = nothing ,
362368 lastu = plant. uop,
@@ -396,7 +402,8 @@ function sim(
396402 D_data[:, i] = d
397403 X_data[:, i] = plant. x
398404 X̂_data[:, i] = mpc. estim. x̂
399- updatestate! (plant, up, d)
405+ x = updatestate! (plant, up, d);
406+ x[:] += x_noise.* randn (plant. nx)
400407 updatestate! (mpc, u, ym, d)
401408 end
402409 res = SimResult (
0 commit comments