You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/manual/nonlinmpc.md
+10-12
Original file line number
Diff line number
Diff line change
@@ -35,8 +35,8 @@ The plant model is nonlinear:
35
35
36
36
in which ``g`` is the gravitational acceleration in m/s², ``L``, the pendulum length in m,
37
37
``K``, the friction coefficient at the pivot point in kg/s, and ``m``, the mass attached at
38
-
the end of the pendulum in kg. Here, the explicit Euler method discretizes the system to
39
-
construct a [`NonLinModel`](@ref):
38
+
the end of the pendulum in kg. Here, a [fourth order Runge-Kutta method](https://en.wikipedia.org/wiki/Runge%E2%80%93Kutta_methods)
39
+
solves the differential equations to construct a [`NonLinModel`](@ref):
40
40
41
41
```@example 1
42
42
using ModelPredictiveControl
@@ -49,17 +49,17 @@ function pendulum(par, x, u)
49
49
return [dθ, dω]
50
50
end
51
51
# declared constants, to avoid type-instability in the f function, for speed:
52
-
const par, Ts = (9.8, 0.4, 1.2, 0.3), 0.1
53
-
f(x, u, _ ) = x + Ts*pendulum(par, x, u) # Euler method
52
+
const par= (9.8, 0.4, 1.2, 0.3)
53
+
f(x, u, _ ) = pendulum(par, x, u)
54
54
h(x, _ ) = [180/π*x[1]] # [°]
55
-
nu, nx, ny = 1, 2, 1
55
+
Ts, nu, nx, ny = 0.1, 1, 2, 1
56
56
model = NonLinModel(f, h, Ts, nu, nx, ny)
57
57
```
58
58
59
59
The output function ``\mathbf{h}`` converts the ``θ`` angle to degrees. Note that special
60
60
characters like ``θ`` can be typed in the Julia REPL or VS Code by typing `\theta` and
61
-
pressing the `<TAB>` key. The tuple `par`and `Ts` are declared as constants here to improve
62
-
the [performance](https://docs.julialang.org/en/v1/manual/performance-tips/#Avoid-untyped-global-variables).
61
+
pressing the `<TAB>` key. The tuple `par`is constant here to improve the [performance](https://docs.julialang.org/en/v1/manual/performance-tips/#Avoid-untyped-global-variables).
62
+
Note that a 4th order [`RungeKutta`](@ref) differential equation solver is used by default.
63
63
It is good practice to first simulate `model` using [`sim!`](@ref) as a quick sanity check:
64
64
65
65
```@example 1
@@ -91,7 +91,7 @@ estimator tuning is tested on a plant with a 25 % larger friction coefficient ``
NonLinMPC controller with a sample time Ts = 10.0 s, Ipopt optimizer, UnscentedKalmanFilter estimator and:
@@ -166,8 +166,8 @@ NonLinMPC controller with a sample time Ts = 10.0 s, Ipopt optimizer, UnscentedK
166
166
167
167
The optimization relies on [`JuMP`](https://github.com/jump-dev/JuMP.jl) automatic
168
168
differentiation (AD) to compute the objective and constraint derivatives. Optimizers
169
-
generally benefit from exact derivatives like AD. However, the [`NonLinModel`](@ref) `f`
170
-
and `h` functions must be compatible with this feature. See [Automatic differentiation](https://jump.dev/JuMP.jl/stable/manual/nlp/#Automatic-differentiation)
169
+
generally benefit from exact derivatives like AD. However, the [`NonLinModel`](@ref)
170
+
state-space functions must be compatible with this feature. See [Automatic differentiation](https://jump.dev/JuMP.jl/stable/manual/nlp/#Automatic-differentiation)
171
171
for common mistakes when writing these functions.
172
172
173
173
Note that if `Cwt≠Inf`, the attribute `nlp_scaling_max_gradient` of `Ipopt` is set to
@@ -221,7 +221,7 @@ Use custom state estimator `estim` to construct `NonLinMPC`.
221
221
222
222
# Examples
223
223
```jldoctest
224
-
julia> model = NonLinModel((x,u,_)->0.5x+u, (x,_)->2x, 10.0, 1, 1, 1);
224
+
julia> model = NonLinModel((x,u,_)->0.5x+u, (x,_)->2x, 10.0, 1, 1, 1, solver=nothing);
0 commit comments