Skip to content

Commit 33db183

Browse files
committed
added : ExtendedKalmanFilter based on ForwardDiff.jl
1 parent a49db53 commit 33db183

File tree

11 files changed

+248
-87
lines changed

11 files changed

+248
-87
lines changed

Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ version = "0.5.10"
55

66
[deps]
77
ControlSystemsBase = "aaaaaaaa-a6ca-5380-bf3e-84a91bcd477e"
8+
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
89
Ipopt = "b6b21f68-93f8-5de0-b562-5493be1d77c9"
910
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
1011
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

docs/src/internals/predictive_control.md

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,38 @@ The prediction methodology of this module is mainly based on Maciejowski textboo
55
[^1]: Maciejowski, J. 2000, "Predictive control : with constraints", 1st ed., Prentice Hall,
66
ISBN 978-0201398236.
77

8+
## Controller Initialization
9+
810
```@docs
911
ModelPredictiveControl.init_deterpred
1012
ModelPredictiveControl.init_ΔUtoU
11-
ModelPredictiveControl.relaxU
12-
ModelPredictiveControl.relaxΔU
13-
ModelPredictiveControl.relaxŶ
1413
ModelPredictiveControl.init_quadprog
1514
ModelPredictiveControl.init_stochpred
1615
ModelPredictiveControl.init_linconstraint
16+
```
17+
18+
## Constraint Relaxation
19+
20+
```@docs
21+
ModelPredictiveControl.relaxU
22+
ModelPredictiveControl.relaxΔU
23+
ModelPredictiveControl.relaxŶ
24+
```
25+
26+
## Get Estimates
27+
28+
```@docs
1729
ModelPredictiveControl.getestimates!
30+
```
31+
32+
## Predictions
33+
34+
```@docs
1835
ModelPredictiveControl.initpred!
36+
```
37+
38+
## Constraints
39+
40+
```@docs
1941
ModelPredictiveControl.linconstraint!
2042
```

docs/src/internals/state_estim.md

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,34 @@
11
# Functions: StateEstimator Internals
22

3+
## Estimator Initialization
4+
35
```@docs
46
ModelPredictiveControl.init_estimstoch
57
ModelPredictiveControl.augment_model
6-
ModelPredictiveControl.
7-
ModelPredictiveControl.
8+
ModelPredictiveControl.init_ukf
9+
ModelPredictiveControl.init_internalmodel
810
```
911

10-
## KalmanFilter
12+
## Augmented Model
1113

1214
```@docs
13-
ModelPredictiveControl.updatestate_kf!
15+
ModelPredictiveControl.f̂
16+
ModelPredictiveControl.ĥ
1417
```
1518

16-
## UnscentedKalmanFilter
19+
## Remove Operating Points
1720

1821
```@docs
19-
ModelPredictiveControl.init_ukf
20-
ModelPredictiveControl.updatestate_ukf!
22+
ModelPredictiveControl.remove_op!
2123
```
2224

23-
## InternalModel
25+
## Update Estimate
26+
27+
!!! info
28+
All these methods assume that the operating points are already removed in `u`, `ym`
29+
and `d` arguments. Strickly speaking, the arguments should be called `u0`, `ym0` and
30+
`d0`, following [`setop!`](@ref) notation. The `0` is dropped to simplify the notation.
2431

2532
```@docs
26-
ModelPredictiveControl.init_internalmodel
33+
ModelPredictiveControl.update_estimate!
2734
```

docs/src/public/state_estim.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ Luenberger
6262
UnscentedKalmanFilter
6363
```
6464

65+
## ExtendedKalmanFilter
66+
67+
```@docs
68+
ExtendedKalmanFilter
69+
```
70+
6571
## InternalModel
6672

6773
```@docs

example/juMPC.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ updatestate!(ssKalmanFilter2,[1, 1],[1,1])
7272

7373
initstate!(ssKalmanFilter1,[0,0],[2,1])
7474

75+
extKalmanFilter = ExtendedKalmanFilter(nonLinModel2)
76+
77+
initstate!(extKalmanFilter, [10,10], [50,30], [5])
78+
updatestate!(extKalmanFilter, [10,11], [50,30], [5])
79+
80+
81+
7582
uscKalmanFilter1 = UnscentedKalmanFilter(linModel1)
7683

7784
updatestate!(uscKalmanFilter1,[0,0],[2,1])

src/ModelPredictiveControl.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ using PrecompileTools
55
using LinearAlgebra, Random
66
using RecipesBase
77
using ControlSystemsBase
8+
using ForwardDiff
89
using JuMP
910
using PreallocationTools
1011
import OSQP, Ipopt
1112

1213

1314
export SimModel, LinModel, NonLinModel, setop!, setstate!, updatestate!, evaloutput
14-
export StateEstimator, InternalModel
15-
export SteadyKalmanFilter, KalmanFilter, Luenberger, UnscentedKalmanFilter
15+
export StateEstimator, InternalModel, Luenberger
16+
export SteadyKalmanFilter, KalmanFilter, UnscentedKalmanFilter, ExtendedKalmanFilter
1617
export initstate!
1718
export PredictiveController, LinMPC, NonLinMPC, setconstraint!, moveinput!, getinfo, sim!
1819

src/estimator/internal_model.jl

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,9 @@ optimally update the stochastic estimate ``\mathbf{x̂_s}`` are:
133133
```
134134
with current stochastic outputs estimation ``\mathbf{ŷ_s}(k)``, composed of the measured
135135
``\mathbf{ŷ_s^m}(k) = \mathbf{y^m}(k) - \mathbf{ŷ_d^m}(k)`` and unmeasured
136-
``\mathbf{ŷ_s^u = 0}`` outputs. See [^3].
136+
``\mathbf{ŷ_s^u = 0}`` outputs. See [^1].
137137
138-
[^3]: Desbiens, A., D. Hodouin & É. Plamondon. 2000, "Global predictive control : a unified
138+
[^1]: Desbiens, A., D. Hodouin & É. Plamondon. 2000, "Global predictive control : a unified
139139
control structure for decoupling setpoint tracking, feedforward compensation and
140140
disturbance rejection dynamics", *IEE Proceedings - Control Theory and Applications*,
141141
vol. 147, no 4, https://doi.org/10.1049/ip-cta:20000443, p. 465–475, ISSN 1350-2379.
@@ -147,14 +147,22 @@ function init_internalmodel(As, Bs, Cs, Ds)
147147
end
148148

149149
@doc raw"""
150-
updatestate!(estim::InternalModel, u, ym, d=Float64[])
150+
update_estimate!(estim::InternalModel, u, ym, d=Float64[])
151151
152152
Update `estim.x̂` \ `x̂d` \ `x̂s` with current inputs `u`, measured outputs `ym` and dist. `d`.
153+
154+
The [`InternalModel`](@ref) updates the deterministic `x̂d` and stochastic `x̂s` estimates with:
155+
```math
156+
\begin{aligned}
157+
\mathbf{x̂_d}(k+1) &= \mathbf{f}\Big( \mathbf{x̂_d}(k), \mathbf{u}(k), \mathbf{d}(k) \Big) \\
158+
\mathbf{x̂_s}(k+1) &= \mathbf{Â_s x̂_s}(k) + \mathbf{B̂_s ŷ_s}(k)
159+
\end{aligned}
160+
```
161+
This estimator does not augment the state vector, thus ``\mathbf{x̂ = x̂_d}``. See
162+
[`init_internalmodel`](@ref) for details.
153163
"""
154-
function updatestate!(estim::InternalModel, u, ym, d=Float64[])
164+
function update_estimate!(estim::InternalModel, u, ym, d=Float64[])
155165
model = estim.model
156-
# ---- remove operating points ----
157-
u, d, ym = remove_op!(estim, u, d, ym)
158166
x̂d, x̂s = estim.x̂d, estim.x̂s
159167
# -------------- deterministic model ---------------------
160168
ŷd = h(model, x̂d, d)

0 commit comments

Comments
 (0)