@@ -132,7 +132,7 @@ nothing # hide
132132
133133``` @example main-mpc
134134function 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,
202202println("Iterations: ", iter)
203203println("Constraints violation: ", cons)
204204println("tf: ", tf)
205+ ```
205206
207+ ``` @example main-mpc
206208# Displaying the trajectory
207209plt_q = plot(xlims=(-2, 6), ylims=(-1, 8), aspect_ratio=1, xlabel="x", ylabel="y")
208210plot_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