Skip to content

Commit 6cd46c5

Browse files
committed
modif sim doc
1 parent bae6ed9 commit 6cd46c5

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

example/juMPC.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ test_mpc(linModel4, mpc)
155155
@time u_data, y_data, r_data, d_data = test_mpc(linModel4, mpc)
156156

157157

158-
res = sim(mpc, x0=zeros(mpc.estim.model.nx))
158+
res = sim(mpc, mpc.Hp+10, x0=zeros(mpc.estim.model.nx))
159159
ps = plot(res, plotD=false, plotŶminŶmax=false, plotUminUmax=false)
160160
display(ps)
161161

src/predictive_control.jl

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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
327327
Closed-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 ``\mathbf{r_y}`` value
334338
- `d = mpc.estim.model.dop` : plant measured disturbance ``\mathbf{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 ``\mathbf{y}``
340344
- `d_step = zeros(plant.nd)` : step disturbance on measured dist. ``\mathbf{d}``
341345
- `d_noise = zeros(plant.nd)` : additive gaussian noise on measured dist. ``\mathbf{d}``
346+
- `x_noise = zeros(plant.nx)` : additive gaussian noise on plant states ``\mathbf{x}``
342347
- `x0 = zeros(plant.nx)` : plant initial state ``\mathbf{x}(0)``
343348
- `x̂0 = nothing` : `mpc.estim` state estimator initial state ``\mathbf{x̂}(0)``, if `nothing`
344349
then ``\mathbf{x̂}`` is initialized with [`initstate!`](@ref)
@@ -347,7 +352,7 @@ Closed-loop simulation of `mpc` controller for `N` time steps, default to setpoi
347352
"""
348353
function 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.
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(

src/state_estim.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 @@ function ĥ(estim::StateEstimator, x̂, d)
187187
end
188188

189189

190-
191190
@doc raw"""
192191
initstate!(estim::StateEstimator, u, ym, d=Float64[])
193192

0 commit comments

Comments
 (0)