Skip to content

Commit cf6096c

Browse files
committed
debug: x_noise argument in sim! now works
1 parent 54a52aa commit cf6096c

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

src/plot_sim.jl

+6-5
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,8 @@ function sim_closedloop!(
286286
d = lastd + d_step + d_noise.*randn(plant.nd)
287287
y = evaloutput(plant, d) + y_step + y_noise.*randn(plant.ny)
288288
ym = y[estim.i_ym]
289-
preparestate!(est_mpc, ym, d)
289+
x = preparestate!(plant)
290+
= preparestate!(est_mpc, ym, d)
290291
u = sim_getu!(est_mpc, u_ry, d, ru)
291292
ud = u + u_step + u_noise.*randn(plant.nu)
292293
Y_data[:, i] .= y
@@ -296,10 +297,10 @@ function sim_closedloop!(
296297
Ud_data[:, i] .= ud
297298
Ru_data[:, i] .= ru
298299
D_data[:, i] .= d
299-
X_data[:, i] .= plant.x0 .+ plant.xop
300-
X̂_data[:, i] .= estim.x̂0 .+ estim.x̂op
301-
x = updatestate!(plant, ud, d);
302-
x[:] += x_noise.*randn(plant.nx)
300+
X_data[:, i] .= x
301+
X̂_data[:, i] .=
302+
updatestate!(plant, ud, d);
303+
plant.x0 .+= x_noise.*randn(plant.nx)
303304
updatestate!(est_mpc, u, ym, d)
304305
end
305306
res = SimResult(

src/sim_model.jl

+7-4
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,13 @@ function preparestate!(model::SimModel)
218218
return x
219219
end
220220

221-
@deprecate function preparestate!(model::SimModel, ::Any , ::Any=model.buffer.empty)
222-
x = model.buffer.x
223-
x .= model.x0 .+ model.xop
224-
return x
221+
function preparestate!(model::SimModel, ::Any , ::Any=model.buffer.empty)
222+
Base.depwarn(
223+
"The method preparestate!(model::SimModel, u, d=[]) is deprecated. Use "*
224+
" preparestate!(model::SimModel) instead.",
225+
:preparestate!,
226+
)
227+
return preparestate!(model)
225228
end
226229

227230
@doc raw"""

test/4_test_plot_sim.jl

+3
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ end
6565
@test res_man.D_data res.D_data
6666
@test res_man.X_data res.X_data
6767
@test res_man.X̂_data res.X̂_data
68+
69+
res2 = sim!(estim, 15, x_noise=[0.1, 0.2, 0.3, 0.4])
70+
@test !(res2.X_data res.X_data)
6871
end
6972

7073
@testitem "StateEstimator Plots" setup=[SetupMPCtests] begin

0 commit comments

Comments
 (0)