Skip to content

Commit 929f418

Browse files
committed
added : ArgumentError if updatestate! is called without ym for estimators and MPCs
1 parent 1a9b3ed commit 929f418

File tree

5 files changed

+11
-2
lines changed

5 files changed

+11
-2
lines changed

example/juMPC.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ mpcluen = LinMPC(luenberger)
5959

6060

6161

62-
#=
62+
6363
kalmanFilter1 = KalmanFilter(linModel1)
6464
kalmanFilter2 = KalmanFilter(linModel1,nint_ym=0)
6565

@@ -211,4 +211,3 @@ display(pu)
211211
display(py)
212212
213213
=#
214-
=#

src/predictive_control.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ end
345345
Call [`updatestate!`](@ref) on `mpc.estim` [`StateEstimator`](@ref).
346346
"""
347347
updatestate!(mpc::PredictiveController, u, ym, d=Float64[]) = updatestate!(mpc.estim,u,ym,d)
348+
updatestate!(::PredictiveController, _ ) = throw(ArgumentError("missing measured outputs ym"))
348349

349350
function validate_setpointdist(mpc::PredictiveController, ry, d, R̂y, D̂)
350351
ny, nd, Hp = mpc.estim.model.ny, mpc.estim.model.nd, mpc.Hp

src/state_estim.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ function updatestate!(estim::StateEstimator, u, ym, d=Float64[])
333333
update_estimate!(estim, u0, ym0, d0)
334334
return estim.
335335
end
336+
updatestate!(::StateEstimator, _ ) = throw(ArgumentError("missing measured outputs ym"))
336337

337338
include("estimator/kalman.jl")
338339
include("estimator/luenberger.jl")

test/test_predictive_control.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ end
8080
@test initstate!(mpc1, [10, 50], [50, 30+1]) [zeros(3); [1]]
8181
setstate!(mpc1, [1,2,3,4])
8282
@test mpc1.estim. [1,2,3,4]
83+
setstate!(mpc1, [0,0,0,0])
84+
updatestate!(mpc1, mpc1.estim.model.uop, mpc1.estim())
85+
@test mpc1.estim. [0,0,0,0]
86+
@test_throws ArgumentError updatestate!(mpc1, [0,0])
8387
end
8488

8589
@testset "NonLinMPC construction" begin
@@ -192,4 +196,7 @@ end
192196
@test initstate!(nmpc1, [10, 50], [20, 25]) [zeros(2); [20, 25]]
193197
setstate!(nmpc1, [1,2,3,4])
194198
@test nmpc1.estim. [1,2,3,4]
199+
setstate!(nmpc1, [0,0,0,0])
200+
updatestate!(nmpc1, nmpc1.estim.model.uop, nmpc1.estim())
201+
@test nmpc1.estim. [0,0,0,0]
195202
end

test/test_state_estim.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ end
5858
@test initstate!(skalmanfilter1, [10, 50], [50, 30+1]) [zeros(3); [1]]
5959
setstate!(skalmanfilter1, [1,2,3,4])
6060
@test skalmanfilter1. [1,2,3,4]
61+
@test_throws ArgumentError updatestate!(skalmanfilter1, [10, 50])
6162
end
6263

6364
@testset "KalmanFilter construction" begin

0 commit comments

Comments
 (0)