Skip to content

Commit 37fcf77

Browse files
committed
add limitations
1 parent c66c53d commit 37fcf77

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

docs/extras/mpc.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ function plot_trajectory!(plt, t, x, y, θ; N=5) # N: number of points where we
101101
end
102102

103103
function solve(t0, x0, y0, θ0, xf, yf, θf, w;
104-
grid_size=300, tol=1e-8, max_iter=500, print_level=4, display=true)
104+
grid_size=300, tol=1e-8, max_iter=500, print_level=4, display=true, disc_method=:euler)
105105

106106
# Definition of the problem
107107
ocp = @def begin
@@ -142,7 +142,7 @@ function solve(t0, x0, y0, θ0, xf, yf, θf, w;
142142
max_iter=max_iter,
143143
print_level=print_level,
144144
display=display,
145-
disc_method=:euler,
145+
disc_method=disc_method,
146146
)
147147

148148
# Retrieval of useful data

docs/src/tutorial-mpc.md

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ nothing # hide
132132

133133
```@example main-mpc
134134
function solve(t0, x0, y0, θ0, xf, yf, θf, w;
135-
grid_size=300, tol=1e-8, max_iter=500, print_level=4, display=true)
135+
grid_size=300, tol=1e-8, max_iter=500, print_level=4, display=true, disc_method=:euler)
136136
137137
# Definition of the problem
138138
ocp = @def begin
@@ -173,7 +173,7 @@ function solve(t0, x0, y0, θ0, xf, yf, θf, w;
173173
max_iter=max_iter,
174174
print_level=print_level,
175175
display=display,
176-
disc_method=:euler,
176+
disc_method=disc_method,
177177
)
178178
179179
# Retrieval of useful data
@@ -202,7 +202,9 @@ t, x, y, θ, u, tf, iter, cons = solve(t0, x0, y0, θ0, xf, yf, θf, current(x0,
202202
println("Iterations: ", iter)
203203
println("Constraints violation: ", cons)
204204
println("tf: ", tf)
205+
```
205206

207+
```@example main-mpc
206208
# Displaying the trajectory
207209
plt_q = plot(xlims=(-2, 6), ylims=(-1, 8), aspect_ratio=1, xlabel="x", ylabel="y")
208210
plot_state!(plt_q, x0, y0, θ0; color=2)
@@ -399,4 +401,39 @@ plot(plt_q, plt_u;
399401
bottommargin=5mm,
400402
plot_title="Simulation with Current Model"
401403
)
404+
```
405+
406+
## Limitations
407+
408+
If you use a discretization method other than `:euler`, the solver may converge to a local solution that is not globally optimal.
409+
410+
```@example main-mpc
411+
# Resolution
412+
t, x, y, θ, u, tf, iter, cons = solve(t0, x0, y0, θ0, xf, yf, θf, current(x0, y0);
413+
display=false, disc_method=:gauss_legendre_3);
414+
415+
println("Iterations: ", iter)
416+
println("Constraints violation: ", cons)
417+
println("tf: ", tf)
418+
```
419+
420+
```@example main-mpc
421+
# Displaying the trajectory
422+
plt_q = plot(xlims=(-2, 6), ylims=(-1, 8), aspect_ratio=1, xlabel="x", ylabel="y")
423+
plot_state!(plt_q, x0, y0, θ0; color=2)
424+
plot_state!(plt_q, xf, yf, θf; color=2)
425+
plot_current!(plt_q; current=(x, y) -> current(x0, y0))
426+
plot_trajectory!(plt_q, t, x, y, θ)
427+
428+
# Displaying the control
429+
plt_u = plot(t, u; color=1, legend=false, linewidth=2, xlabel="t", ylabel="u")
430+
431+
# Final display
432+
plot(plt_q, plt_u;
433+
layout=(1, 2),
434+
size=(1200, 600),
435+
leftmargin=5mm,
436+
bottommargin=5mm,
437+
plot_title="Constant Current Simulation"
438+
)
402439
```

0 commit comments

Comments
 (0)