Skip to content

Commit e1e6f55

Browse files
committed
debug manual nonlinmpc
1 parent 05268f0 commit e1e6f55

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

docs/src/manual/nonlinmpc.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ friction coefficient at the pivot point, and ``m``, the mass attached at the end
2727
pendulum. Here, the explicit Euler method discretizes the system to construct a
2828
[`NonLinModel`](@ref):
2929

30-
```@example 2
30+
```@example 1
3131
using ModelPredictiveControl
3232
function pendulum(par, x, u)
3333
g, L, K, m = par # [m/s], [m], [kg/s], [kg]
3434
θ, ω = x[1], x[2] # [rad], [rad/s]
3535
τ = u[1] # [N m]
3636
dθ = ω
37-
dω = -g/L*sin(θ) - k/m*ω + τ/m/L^2
37+
dω = -g/L*sin(θ) - K/m*ω + τ/m/L^2
3838
return [dθ, dω]
3939
end
4040
Ts = 0.1 # [s]
@@ -48,42 +48,42 @@ model = NonLinModel(f, h, Ts, nu, nx, ny)
4848
The output function ``\mathbf{h}`` converts the angular position ``θ`` to degrees. It
4949
is good practice to first simulate `model` using [`sim!`](@ref) as a quick sanity check:
5050

51-
```@example 2
51+
```@example 1
5252
using Plots
5353
u = [0.5] # τ = 0.5 N m
5454
plot(sim!(model, 60, u), plotu=false)
5555
```
5656

5757
An [`UnscentedKalmanFilter`](@ref) estimates the plant state :
5858

59-
```@example 2
59+
```@example 1
6060
estim = UnscentedKalmanFilter(model, σQ=[0.5, 2.5], σQ_int=[0.5])
6161
```
6262

6363
The standard deviation of the angular velocity ``ω`` is higher here (`σQ` second value)
6464
since ``\dot{ω}(t)`` equation includes an uncertain parameter: the friction coefficient
6565
``K``. The estimator tuning is tested on a plant simulated with a different ``K``:
6666

67-
```@example 2
67+
```@example 1
6868
par_plant = (par[1], par[2], par[3] + 0.25, par[4])
6969
f_plant(x, u, _) = x + Ts*pendulum(par_plant, x, u)
7070
plant = NonLinModel(f_plant, h, Ts, nu, nx, ny)
7171
res = sim!(estim, 30, [0.5], plant=plant, y_noise=[0.5]) # τ = 0.5 N m
72-
p2 = plot(res, plotu=false, plotx=true, plotx̂=true)
72+
plot(res, plotu=false, plotx=true, plotx̂=true)
7373
```
7474

7575
The Kalman filter performance seems sufficient for control. As the motor torque is limited
7676
to -1.5 to 1.5 N m, we incorporate the input constraints in a [`NonLinMPC`](@ref):
7777

78-
```@example 2
78+
```@example 1
7979
mpc = NonLinMPC(estim, Hp=20, Hc=2, Mwt=[0.1], Nwt=[1.0], Cwt=Inf)
8080
mpc = setconstraint!(mpc, umin=[-1.5], umax=[+1.5])
8181
```
8282

8383
We test `mpc` performance on `plant` by imposing an angular setpoint of 180° (inverted
8484
position):
8585

86-
```@example 2
86+
```@example 1
8787
res = sim!(mpc, 30, [180.0], x̂0=zeros(mpc.estim.nx̂), plant=plant, x0=zeros(plant.nx))
8888
plot(res, plotŷ=true)
8989
```

0 commit comments

Comments
 (0)