Skip to content

Commit c66c53d

Browse files
committed
up tuto mpc
1 parent d4ff9cb commit c66c53d

File tree

3 files changed

+34
-8
lines changed

3 files changed

+34
-8
lines changed

docs/extras/mpc.jl

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
using Pkg
22
Pkg.activate("docs")
33

4-
using OptimalControl, NLPModelsIpopt, Plots, OrdinaryDiffEq, LinearAlgebra, Plots.PlotMeasures
4+
using LinearAlgebra
5+
using NLPModelsIpopt
6+
using OptimalControl
7+
using OrdinaryDiffEq
8+
using Plots
9+
using Plots.PlotMeasures
10+
using Printf
511

612
t0 = 0.
713
x0 = 0.
@@ -255,7 +261,6 @@ function MPC(t0, x0, y0, θ0, xf, yf, θf, current)
255261
t2 = t1 + Δt
256262
else
257263
t2 = tf
258-
println("t2=tf: ", t2)
259264
stop = true
260265
end
261266

@@ -271,7 +276,15 @@ function MPC(t0, x0, y0, θ0, xf, yf, θf, current)
271276

272277
# Calculate the distance to the target position
273278
distance = norm([x1, y1, θ1] - [xf, yf, θf])
274-
println("N: ", N, "\t distance: ", distance, "\t iterations: ", iter, "\t constraints: ", cons, "\t tf: ", tf)
279+
if N == 1
280+
println(" N Distance Iterations Constraints tf")
281+
println("------------------------------------------------------")
282+
end
283+
@printf("%6d", N)
284+
@printf("%12.4f", distance)
285+
@printf("%12d", iter)
286+
@printf("%14.4e", cons)
287+
@printf("%10.4f\n", tf)
275288
if !((distance > ε) && (N < Nmax))
276289
stop = true
277290
end
@@ -284,7 +297,7 @@ function MPC(t0, x0, y0, θ0, xf, yf, θf, current)
284297
return data
285298
end
286299

287-
data = MPC(t0, x0, y0, θ0, xf, yf, θf, current)
300+
data = MPC(t0, x0, y0, θ0, xf, yf, θf, current);
288301

289302
# Trajectory
290303
plt_q = plot(xlims=(-2, 6), ylims=(-1, 8), aspect_ratio=1, xlabel="x", ylabel="y")

docs/make.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ cp("./docs/Project.toml", "./docs/src/assets/Project.toml"; force=true)
88
repo_url = "github.com/control-toolbox/Tutorials.jl"
99

1010
makedocs(;
11-
draft=true, # if draft is true, then the julia code from .md is not executed
11+
draft=false, # if draft is true, then the julia code from .md is not executed
1212
warnonly=[:cross_references, :autodocs_block],
1313
sitename="Tutorials",
1414
format=Documenter.HTML(;

docs/src/tutorial-mpc.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@ The angular velocity is limited and normalized: $\|u(t)\| \leq 1$. There are bou
2626
## Data
2727

2828
```@example main-mpc
29-
using OptimalControl, NLPModelsIpopt, Plots, OrdinaryDiffEq, LinearAlgebra, Plots.PlotMeasures
29+
using LinearAlgebra
30+
using NLPModelsIpopt
31+
using OptimalControl
32+
using OrdinaryDiffEq
33+
using Plots
34+
using Plots.PlotMeasures
35+
using Printf
3036
3137
t0 = 0.
3238
x0 = 0.
@@ -308,7 +314,6 @@ function MPC(t0, x0, y0, θ0, xf, yf, θf, current)
308314
t2 = t1 + Δt
309315
else
310316
t2 = tf
311-
println("t2=tf: ", t2)
312317
stop = true
313318
end
314319
@@ -324,7 +329,15 @@ function MPC(t0, x0, y0, θ0, xf, yf, θf, current)
324329
325330
# Calculate the distance to the target position
326331
distance = norm([x1, y1, θ1] - [xf, yf, θf])
327-
println("N: ", N, "\t distance: ", distance, "\t iterations: ", iter, "\t constraints: ", cons, "\t tf: ", tf)
332+
if N == 1
333+
println(" N Distance Iterations Constraints tf")
334+
println("------------------------------------------------------")
335+
end
336+
@printf("%6d", N)
337+
@printf("%12.4f", distance)
338+
@printf("%12d", iter)
339+
@printf("%14.4e", cons)
340+
@printf("%10.4f\n", tf)
328341
if !((distance > ε) && (N < Nmax))
329342
stop = true
330343
end

0 commit comments

Comments
 (0)