Skip to content

Commit d284c3e

Browse files
committed
debug: separate SimModel and StateEstimator buffers
1 parent bbbca90 commit d284c3e

File tree

4 files changed

+16
-16
lines changed

4 files changed

+16
-16
lines changed

src/controller/execute.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
44
Init the states of `mpc.estim` [`StateEstimator`](@ref) and warm start `mpc.ΔŨ` at zero.
55
"""
6-
function initstate!(mpc::PredictiveController, u, ym, d=mpc.estim.model.buffer.empty)
6+
function initstate!(mpc::PredictiveController, u, ym, d=mpc.estim.buffer.empty)
77
mpc.ΔŨ .= 0
88
return initstate!(mpc.estim, u, ym, d)
99
end
@@ -51,7 +51,7 @@ julia> ry = [5]; u = moveinput!(mpc, ry); round.(u, digits=3)
5151
function moveinput!(
5252
mpc::PredictiveController,
5353
ry::Vector = mpc.estim.model.yop,
54-
d ::Vector = mpc.estim.model.buffer.empty;
54+
d ::Vector = mpc.estim.buffer.empty;
5555
Dhat ::Vector = repeat(d, mpc.Hp),
5656
Rhaty::Vector = repeat(ry, mpc.Hp),
5757
Rhatu::Vector = mpc.Uop,
@@ -509,7 +509,7 @@ set_objective_linear_coef!(::PredictiveController, _ ) = nothing
509509
510510
Call [`updatestate!`](@ref) on `mpc.estim` [`StateEstimator`](@ref).
511511
"""
512-
function updatestate!(mpc::PredictiveController, u, ym, d=mpc.estim.model.buffer.empty)
512+
function updatestate!(mpc::PredictiveController, u, ym, d=mpc.estim.buffer.empty)
513513
return updatestate!(mpc.estim, u, ym, d)
514514
end
515515
updatestate!(::PredictiveController, _ ) = throw(ArgumentError("missing measured outputs ym"))

src/estimator/execute.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ julia> evaloutput(estim) ≈ y
113113
true
114114
```
115115
"""
116-
function initstate!(estim::StateEstimator, u, ym, d=estim.model.buffer.empty)
116+
function initstate!(estim::StateEstimator, u, ym, d=estim.buffer.empty)
117117
# --- validate arguments ---
118118
validate_args(estim, u, ym, d)
119119
# --- init state estimate ----
@@ -179,18 +179,18 @@ julia> ŷ = evaloutput(kf)
179179
20.0
180180
```
181181
"""
182-
function evaloutput(estim::StateEstimator{NT}, d=estim.model.buffer.empty) where NT <: Real
182+
function evaloutput(estim::StateEstimator{NT}, d=estim.buffer.empty) where NT <: Real
183183
validate_args(estim.model, d)
184-
ŷ0, d0 = estim.model.buffer.y, estim.model.buffer.d
184+
ŷ0, d0 = estim.buffer., estim.buffer.d
185185
d0 .= d .- estim.model.dop
186186
ĥ!(ŷ0, estim, estim.model, estim.x̂0, d0)
187-
= estim.model.buffer.y
188-
ŷ .= ŷ0 .+ estim.model.yop
187+
= ŷ0
188+
.+= estim.model.yop
189189
return
190190
end
191191

192192
"Functor allowing callable `StateEstimator` object as an alias for `evaloutput`."
193-
(estim::StateEstimator)(d=estim.model.buffer.empty) = evaloutput(estim, d)
193+
(estim::StateEstimator)(d=estim.buffer.empty) = evaloutput(estim, d)
194194

195195
@doc raw"""
196196
updatestate!(estim::StateEstimator, u, ym, d=[]) -> x̂
@@ -210,10 +210,10 @@ julia> x̂ = updatestate!(kf, [1], [0]) # x̂[2] is the integrator state (nint_y
210210
0.0
211211
```
212212
"""
213-
function updatestate!(estim::StateEstimator, u, ym, d=estim.model.buffer.empty)
213+
function updatestate!(estim::StateEstimator, u, ym, d=estim.buffer.empty)
214214
validate_args(estim, u, ym, d)
215215
u0, ym0, d0 = remove_op!(estim, u, ym, d)
216-
x̂0next = update_estimate!(estim, u0, ym0, d0)
216+
x̂0next = update_estimate!(estim, u0, ym0, d0)
217217
x̂next = x̂0next
218218
x̂next .+= estim.x̂op
219219
return x̂next

src/predictive_control.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ end
4242
"Functor allowing callable `PredictiveController` object as an alias for `moveinput!`."
4343
function (mpc::PredictiveController)(
4444
ry::Vector = mpc.estim.model.yop,
45-
d ::Vector = mpc.estim.model.buffer.empty;
45+
d ::Vector = mpc.estim.buffer.empty;
4646
kwargs...
4747
)
4848
return moveinput!(mpc, ry, d; kwargs...)

src/sim_model.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,8 @@ function updatestate!(model::SimModel{NT}, u, d=model.buffer.empty) where NT <:
241241
f!(xnext0, model, model.x0, u0, d0)
242242
xnext0 .+= model.fop .- model.xop
243243
model.x0 .= xnext0
244-
xnext = model.buffer.x
245-
xnext .= xnext0 .+ model.xop
244+
xnext = xnext0
245+
xnext .+= model.xop
246246
return xnext
247247
end
248248

@@ -268,8 +268,8 @@ function evaloutput(model::SimModel{NT}, d=model.buffer.empty) where NT <: Real
268268
d0 .= d .- model.dop
269269
y0 = model.buffer.y
270270
h!(y0, model, model.x0, d0)
271-
y = model.buffer.y
272-
y .= y0 .+ model.yop
271+
y = y0
272+
y .+= model.yop
273273
return y
274274
end
275275

0 commit comments

Comments
 (0)