Skip to content

Commit 9a81963

Browse files
authored
Improve docs (#82)
1 parent dff9e39 commit 9a81963

File tree

4 files changed

+22
-52
lines changed

4 files changed

+22
-52
lines changed

docs/src/examples/invpend.md

Lines changed: 0 additions & 33 deletions
This file was deleted.

docs/src/manual/game.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# [Robust MPC](@id man_robust)
1+
# [Game-Theoretic MPC](@id man_robust)
22

33
**LinearMPC.jl** can also solve general Nash equilibria to game-theoretic linear MPC problems.
44
Specifically it can handle objective of the form

docs/src/manual/moveblock.md

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,44 +28,43 @@ Finally, it is possible to define different move blocks for different control si
2828

2929
Consider the example of the control of an inverted pendulum on a cart, which is predefined as one of the examples in **LinearMPC.jl** and can be accessed with the call `mpc_examples`. We consider the case when we want the first output (the position of the cart) to reach a certain value (1 m to be specific.) Below we create three different MPC controllers with different prediction horizons and show the resulting step responses.
3030

31-
```julia
31+
```@example move_block
3232
using LinearMPC,Plots
3333
tsolve, plt = zeros(3),plot();
3434
for (k,Np) in enumerate([100,75,50])
3535
mpc,_ = LinearMPC.mpc_examples("invpend",Np)
36-
tsolve[k] = @elapsed sim = LinearMPC.Simulation(mpc;r=[1,0],N=500);
36+
dynamics = (x,u,d) -> mpc.model.F*x + mpc.model.G*u # Since long horizon
37+
tsolve[k] = @elapsed sim = LinearMPC.Simulation(dynamics,mpc;r=[1,0],N=500);
3738
plot!(plt, sim,yids=[1],uids=[], color = k, label="Np = "*string(Np))
3839
end
39-
plot!(plt,ylims=(-0.5,1.25))
40-
```
41-
42-
```@raw html
43-
<p><img src="../../assets/moveblock_horizon.svg" alt="simple_sim1" width=700 style="background-color:white;
44-
border:20px solid white; display: block; margin-left: auto; margin-right: auto;"/></p>
40+
plot!(plt,ylims=(-0.5,1.25), legend=true)
4541
```
4642

4743
As can be seen, the higher the prediction horizon, the faster the setpoint is reached. (Note that for even lower values of the prediction horizon, the resulting closed-loop system becomes unstable.) The cost of the horizon can, however, be seen in the solve times, where the solve times are about four times slower for $N_p = 100$ compared with $N_p = 50$.
4844

4945
To reduce the computation time, we consider three different move blocks. We consider the case of no move blocks (which an empty vector of move blocks encodes,) of evenly spaced move blocks `[1,1,1,1,1]` and a more dynamics set of move blocks `[1,1,5,10,10]`. For all of the cases, we consider a prediction horizon of $N_p = 100$. The resulting step responses are shown below.
5046

5147

52-
```julia
53-
using LinearMPC,Plots
48+
```@example move_block
5449
mpc,_ = LinearMPC.mpc_examples("invpend",100)
50+
dynamics = (x,u,d) -> mpc.model.F*x + mpc.model.G*u # Since long horizon
5551
tsolve, plt = zeros(3),plot();
5652
move_blocks = [Int[], [1,1,1,1,1], [1,1,5,10,10]]
53+
solve_times = []
5754
for (k,mb) in enumerate(move_blocks)
5855
move_block!(mpc,mb)
59-
tsolve[k] = @elapsed sim = LinearMPC.Simulation(mpc;r=[1,0],N=500);
56+
tsolve[k] = @elapsed sim = LinearMPC.Simulation(dynamics,mpc;r=[1,0],N=500);
6057
plot!(plt, sim,yids=[1],uids=[], color = k, label="move block = "*string(mb))
58+
push!(solve_times,sim.solve_times)
6159
end
62-
plot!(plt,ylims=(-0.5,1.25))
60+
plot!(plt,ylims=(-0.5,1.25),legend=true)
6361
```
6462

65-
```@raw html
66-
<p><img src="../../assets/moveblocks.svg" alt="simple_sim1" width=700 style="background-color:white;
67-
border:20px solid white; display: block; margin-left: auto; margin-right: auto;"/></p>
63+
We see that the adaptive move block almost performs as well as using no move blocks. The main difference is that when no move blocks are used, there are 100 decision variables, while for both the move blocks `[1,1,1,1,1]` and `[1,1,5,10,10]` there are only 5 decision variables.
64+
This can be seen in the solution times, where both of the move blocks leads to solution times that are about 5-10 times faster.
65+
```@example move_block
66+
using Statistics
67+
for (k,mb) in enumerate(move_blocks)
68+
println("median solve time: $(round(median(solve_times[k]),sigdigits=3)) | move block: "*string(mb))
69+
end
6870
```
69-
70-
As can be seen, the adaptive move block almost performs as well as using no move blocks. The main difference is that when no move blocks are used, there are 100 decision variables, while for both the move blocks `[1,1,1,1,1]` and `[1,1,5,10,10]` there are only 5 decision variables.
71-
This can be seen in the solution times, where both of the move blocks leads to solution times that are about 6 times faster (note that the actual speedup is even higher due to some overhead from the simulation.)

docs/src/manual/prestab.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ A popular choice of $K$ is as the gain from solving an infinite horizon LQR prob
2121
```julia
2222
set_prestabilizing_feedback!(mpc)
2323
```
24+
25+
!!! note "Prestabilization + Move block"
26+
If you use prestabilization and move blocking, only $v_k$ is held constant, not $u_k$. Hence, the closed-loop behaviour with/without prestabilization might differ.
27+
2428
## Example
2529
Consider a first-order system with a pole in 10, which has the transfer function
2630
```math

0 commit comments

Comments
 (0)