@@ -318,18 +318,22 @@ end
318
318
@doc raw """
319
319
sim(
320
320
mpc::PredictiveController,
321
- N = mpc.Hp + 10 ,
321
+ N::Int ,
322
322
ry = mpc.estim.model.yop .+ 1,
323
323
d = mpc.estim.model.dop;
324
324
<keyword arguments>
325
325
)
326
326
327
327
Closed-loop simulation of `mpc` controller for `N` time steps, default to setpoint bumps.
328
328
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
+
329
333
# Arguments
330
334
331
335
- `mpc::PredictiveController` : predictive controller to simulate
332
- - `N = mpc.Hp + 10 ` : simulation length in time steps
336
+ - `N::Int ` : simulation length in time steps
333
337
- `ry = mpc.estim.model.yop .+ 1` : plant output setpoint ``\m athbf{r_y}`` value
334
338
- `d = mpc.estim.model.dop` : plant measured disturbance ``\m athbf{d}`` value
335
339
- `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
339
343
- `y_noise = zeros(plant.ny)` : additive gaussian noise on plant outputs ``\m athbf{y}``
340
344
- `d_step = zeros(plant.nd)` : step disturbance on measured dist. ``\m athbf{d}``
341
345
- `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}``
342
347
- `x0 = zeros(plant.nx)` : plant initial state ``\m athbf{x}(0)``
343
348
- `x̂0 = nothing` : `mpc.estim` state estimator initial state ``\m athbf{x̂}(0)``, if `nothing`
344
349
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
347
352
"""
348
353
function sim (
349
354
mpc:: PredictiveController ,
350
- N :: Int = mpc . Hp + 10 ,
355
+ N:: Int ,
351
356
ry:: Vector{<:Real} = mpc. estim. model. yop .+ 1 ,
352
357
d :: Vector{<:Real} = mpc. estim. model. dop;
353
358
plant:: SimModel = mpc. estim. model,
@@ -357,6 +362,7 @@ function sim(
357
362
y_noise:: Vector{<:Real} = zeros (plant. ny),
358
363
d_step :: Vector{<:Real} = zeros (plant. nd),
359
364
d_noise:: Vector{<:Real} = zeros (plant. nd),
365
+ x_noise:: Vector{<:Real} = zeros (plant. nx),
360
366
x0 = zeros (plant. nx),
361
367
x̂0 = nothing ,
362
368
lastu = plant. uop,
@@ -396,7 +402,8 @@ function sim(
396
402
D_data[:, i] = d
397
403
X_data[:, i] = plant. x
398
404
X̂_data[:, i] = mpc. estim. x̂
399
- updatestate! (plant, up, d)
405
+ x = updatestate! (plant, up, d);
406
+ x[:] += x_noise.* randn (plant. nx)
400
407
updatestate! (mpc, u, ym, d)
401
408
end
402
409
res = SimResult (
0 commit comments