Skip to content

Commit 4a757cd

Browse files
committed
test: new tests with NonLinModel parameter arg. p
1 parent 0437551 commit 4a757cd

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

src/model/nonlinmodel.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ functions are defined as:
6969
```
7070
where ``\mathbf{x}``, ``\mathbf{y}``, ``\mathbf{u}``, ``\mathbf{d}`` and ``\mathbf{p}`` are
7171
respectively the state, output, manipulated input, measured disturbance and parameter
72-
vectors. If the dynamics is a function of time, simply add a measured disturbance defined as
73-
``d(t) = t``. The functions can be implemented in two possible ways:
72+
vectors. If the dynamics is a function of the time, simply add a measured disturbance
73+
defined as ``d(t) = t``. The functions can be implemented in two possible ways:
7474
7575
1. **Non-mutating functions** (out-of-place): define them as `f(x, u, d, p) -> ẋ` and
7676
`h(x, d, p) -> y`. This syntax is simple and intuitive but it allocates more memory.

test/test_predictive_control.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -474,9 +474,9 @@ end
474474
linmodel1 = LinModel(sys,Ts,i_d=[3])
475475
nmpc0 = NonLinMPC(linmodel1, Hp=15)
476476
@test isa(nmpc0.estim, SteadyKalmanFilter)
477-
f = (x,u,d,_) -> linmodel1.A*x + linmodel1.Bu*u + linmodel1.Bd*d
478-
h = (x,d,_) -> linmodel1.C*x + linmodel1.Dd*d
479-
nonlinmodel = NonLinModel(f, h, Ts, 2, 4, 2, 1, solver=nothing)
477+
f = (x,u,d,model) -> model.A*x + model.Bu*u + model.Bd*d
478+
h = (x,d,model) -> model.C*x + model.Dd*d
479+
nonlinmodel = NonLinModel(f, h, Ts, 2, 4, 2, 1, p=linmodel1, solver=nothing)
480480
nmpc1 = NonLinMPC(nonlinmodel, Hp=15)
481481
@test isa(nmpc1.estim, UnscentedKalmanFilter)
482482
@test size(nmpc1.R̂y0, 1) == 15*nmpc1.estim.model.ny

test/test_sim_model.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,9 @@ end
144144

145145
@testset "NonLinModel construction" begin
146146
linmodel1 = LinModel(sys,Ts,i_u=[1,2])
147-
f1(x,u,_,_) = linmodel1.A*x + linmodel1.Bu*u
148-
h1(x,_,_) = linmodel1.C*x
149-
nonlinmodel1 = NonLinModel(f1,h1,Ts,2,2,2,solver=nothing)
147+
f1(x,u,_,model) = model.A*x + model.Bu*u
148+
h1(x,_,model) = model.C*x
149+
nonlinmodel1 = NonLinModel(f1,h1,Ts,2,2,2,solver=nothing,p=linmodel1)
150150
@test nonlinmodel1.nx == 2
151151
@test nonlinmodel1.nu == 2
152152
@test nonlinmodel1.nd == 0
@@ -244,9 +244,9 @@ end
244244

245245
@testset "NonLinModel sim methods" begin
246246
linmodel1 = LinModel(sys,Ts,i_u=[1,2])
247-
f1(x,u,_,_) = linmodel1.A*x + linmodel1.Bu*u
248-
h1(x,_,_) = linmodel1.C*x
249-
nonlinmodel = NonLinModel(f1,h1,Ts,2,2,2,solver=nothing)
247+
f1(x,u,_,model) = model.A*x + model.Bu*u
248+
h1(x,_,model) = model.C*x
249+
nonlinmodel = NonLinModel(f1,h1,Ts,2,2,2,p=linmodel1,solver=nothing)
250250

251251
@test updatestate!(nonlinmodel, zeros(2,)) zeros(2)
252252
@test updatestate!(nonlinmodel, zeros(2,), Float64[]) zeros(2)

0 commit comments

Comments
 (0)