Skip to content

Commit 31cac69

Browse files
authored
Merge pull request #173 from JuliaControl/doc_correction
Debug `x_noise` argument in `sim!` and deprecate `preparestate!(::SimModel, _ , _ )`
2 parents ea1044b + cf6096c commit 31cac69

File tree

6 files changed

+24
-10
lines changed

6 files changed

+24
-10
lines changed

src/controller/nonlinmpc.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ Also return vectors with the nonlinear inequality constraint functions `gfuncs`,
525525
`∇gfuncs!`, for the associated gradients. Lastly, also return vectors with the nonlinear
526526
equality constraint functions `geqfuncs` and gradients `∇geqfuncs!`.
527527
528-
This method is really indicated and I'm not proud of it. That's because of 3 elements:
528+
This method is really intricate and I'm not proud of it. That's because of 3 elements:
529529
530530
- These functions are used inside the nonlinear optimization, so they must be type-stable
531531
and as efficient as possible.

src/estimator/mhe/construct.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1275,7 +1275,7 @@ Return the nonlinear objective `Jfunc` function, and `∇Jfunc!`, to compute its
12751275
Also return vectors with the nonlinear inequality constraint functions `gfuncs`, and
12761276
`∇gfuncs!`, for the associated gradients.
12771277
1278-
This method is really indicated and I'm not proud of it. That's because of 3 elements:
1278+
This method is really intricate and I'm not proud of it. That's because of 3 elements:
12791279
12801280
- These functions are used inside the nonlinear optimization, so they must be type-stable
12811281
and as efficient as possible.

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

+11-2
Original file line numberDiff line numberDiff line change
@@ -208,16 +208,25 @@ function initstate!(model::SimModel, u, d=model.buffer.empty)
208208
end
209209

210210
@doc raw"""
211-
preparestate!(model::SimModel, _ , _ ) -> x
211+
preparestate!(model::SimModel) -> x
212212
213213
Do nothing for [`SimModel`](@ref) and return the current model state ``\mathbf{x}(k)``.
214214
"""
215-
function preparestate!(model::SimModel, ::Any , ::Any=model.buffer.empty)
215+
function preparestate!(model::SimModel)
216216
x = model.buffer.x
217217
x .= model.x0 .+ model.xop
218218
return x
219219
end
220220

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)
228+
end
229+
221230
@doc raw"""
222231
updatestate!(model::SimModel, u, d=[]) -> xnext
223232

test/1_test_sim_model.jl

+2-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ end
107107
@test evaloutput(linmodel1, Float64[]) linmodel1(Float64[]) [50,30]
108108
x = initstate!(linmodel1, [10, 60])
109109
@test evaloutput(linmodel1) [50 + 19.0, 30 + 7.4]
110-
@test preparestate!(linmodel1, [10, 60]) x
110+
@test preparestate!(linmodel1) x # new method
111+
@test preparestate!(linmodel1, [10, 60]) x # deprecated method
111112
@test updatestate!(linmodel1, [10, 60]) x
112113
linmodel2 = LinModel(append(tf(1, [1, 0]), tf(2, [10, 1])), 1.0)
113114
x = initstate!(linmodel2, [10, 3])

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)