Skip to content

Commit b6a148e

Browse files
committed
WIP: TrapezoidalMethod() collocation
1 parent 9b87de8 commit b6a148e

3 files changed

Lines changed: 43 additions & 1 deletion

File tree

docs/src/public/predictive_control.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,9 @@ SingleShooting
109109
```@docs
110110
MultipleShooting
111111
```
112+
113+
### TrapezoidalMethod
114+
115+
```@docs
116+
TrapezoidalMethod
117+
```

src/ModelPredictiveControl.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export MovingHorizonEstimator
3939
export ManualEstimator
4040
export default_nint, initstate!
4141
export PredictiveController, ExplicitMPC, LinMPC, NonLinMPC, setconstraint!, moveinput!
42-
export TranscriptionMethod, SingleShooting, MultipleShooting
42+
export TranscriptionMethod, SingleShooting, MultipleShooting, TrapezoidalMethod
4343
export SimResult, getinfo, sim!
4444

4545
include("general.jl")

src/controller/transcription.jl

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,42 @@ function get_nZ(estim::StateEstimator, ::MultipleShooting, Hp, Hc)
6161
return estim.model.nu*Hc + estim.nx̂*Hp
6262
end
6363

64+
65+
@doc raw"""
66+
TrapezoidalMethod()
67+
68+
An implicit trapezoidal transcription method (not yet implemented).
69+
70+
This is presumably the simplest collocation method. It can handle moderately stiff systems
71+
and is A-stable. However, it may not be as efficient as more advanced methods for highly
72+
stiff systems. The decision variables are the same as for [`MultipleShooting`](@ref), hence
73+
a similar algorithm complexity.
74+
75+
# Extended Help
76+
77+
!!! details "Extended Help"
78+
The trapezoidal method estimates the defects with:
79+
by:
80+
```math
81+
\mathbf{Ŝ}(k) = \mathbf{Ẽ_ŝ Z̃} + \mathbf{K_ŝ x̂_0}(k) + 0.5\frac{T_s}\big(\mathbf{F̂}(k+1) + \mathbf{F̂}(k)\big)
82+
```
83+
where ``T_s`` is the sampling period, ``\mathbf{Ẽ}`` the matrix defined at
84+
[`init_defectmat`](@ref), and ``\mathbf{F̂}(k+j)`` the stacked vector of system
85+
86+
where ``\mathbf{f̂}(k+j) = \mathbf{f̂}\big(\mathbf{x̂}(k+j), \mathbf{u}(k+j), \mathbf{d}(k+j)\big)``.
87+
This leads to the following defect constraints for ``j=0`` to ``H_p-1``:
88+
```math
89+
\mathbf{ŝ}(k+j) = \mathbf{x̂}(k+j+1) - \mathbf{x̂}(k+j) - \frac{T_s}{2} \big( \mathbf{f̂}(k+j) + \mathbf{f̂}(k+j+1) \big) = 0
90+
```
91+
which are added as equality constraints in the optimization problem. The initial state
92+
``\mathbf{x̂}(k)`` is given by the state estimator, and the future states
93+
``\mathbf{x̂}(k+j+1)`` are decision variables in the optimization problem. The method
94+
requires evaluating the system dynamics at both the current and next time steps, which
95+
can increase computational complexity compared to explicit methods like single shooting.
96+
"""
97+
struct TrapezoidalMethod <: TranscriptionMethod end
98+
99+
64100
@doc raw"""
65101
init_ZtoΔU(estim::StateEstimator, transcription::TranscriptionMethod, Hp, Hc) -> PΔu
66102

0 commit comments

Comments
 (0)