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
+17-19Lines changed: 17 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -35,8 +35,9 @@ 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. The [`NonLinModel`](@ref) constructor assumes by default
39
+
that the state function `f` is continuous in time, that is, an ordinary differential
40
+
equation system (like here):
40
41
41
42
```@example 1
42
43
using ModelPredictiveControl
@@ -49,17 +50,17 @@ function pendulum(par, x, u)
49
50
return [dθ, dω]
50
51
end
51
52
# 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
53
+
const par= (9.8, 0.4, 1.2, 0.3)
54
+
f(x, u, _ ) = pendulum(par, x, u)
54
55
h(x, _ ) = [180/π*x[1]] # [°]
55
-
nu, nx, ny = 1, 2, 1
56
+
Ts, nu, nx, ny = 0.1, 1, 2, 1
56
57
model = NonLinModel(f, h, Ts, nu, nx, ny)
57
58
```
58
59
59
60
The output function ``\mathbf{h}`` converts the ``θ`` angle to degrees. Note that special
60
61
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).
62
+
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).
63
+
Note that a 4th order [`RungeKutta`](@ref) differential equation solver is used by default.
63
64
It is good practice to first simulate `model` using [`sim!`](@ref) as a quick sanity check:
We test `mpc` performance on `plant` by imposing an angular setpoint of 180° (inverted
115
-
position):
115
+
The option `Cwt=Inf` disables the slack variable `ϵ` for constraint softening. We test `mpc` performance on `plant` by imposing an angular setpoint of 180° (inverted position):
0 commit comments