11using Pkg
22Pkg. 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
612t0 = 0.
713x0 = 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
285298end
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
290303plt_q = plot (xlims= (- 2 , 6 ), ylims= (- 1 , 8 ), aspect_ratio= 1 , xlabel= " x" , ylabel= " y" )
0 commit comments