From ec494b7aa7efe0a3cc9ba6151ca021f98df09339 Mon Sep 17 00:00:00 2001 From: Uwe Fechner Date: Sat, 16 Mar 2024 11:37:29 +0100 Subject: [PATCH] Good results with autopilot and GC disabled --- examples/autopilot.jl | 29 +++++++++++++---- test/plot.jl | 72 ++++++++++++++++++++++--------------------- 2 files changed, 60 insertions(+), 41 deletions(-) diff --git a/examples/autopilot.jl b/examples/autopilot.jl index e7bf4313..0a8058bb 100644 --- a/examples/autopilot.jl +++ b/examples/autopilot.jl @@ -5,7 +5,7 @@ if ! ("Plots" ∈ keys(Pkg.project().dependencies)) end using Timers; tic() -using KiteControllers, KiteViewers, KiteModels +using KiteControllers, KiteViewers, KiteModels, StatsBase const Model = KPS4 @@ -20,7 +20,7 @@ dt = wcs.dt # the following values can be changed to match your interest if ! @isdefined MAX_TIME; MAX_TIME=460; end -TIME_LAPSE_RATIO = 2 +TIME_LAPSE_RATIO = 4 SHOW_KITE = true # end of user parameter section # @@ -33,6 +33,7 @@ if ! @isdefined viewer; const viewer = Viewer3D(SHOW_KITE); end steps = 0 if ! @isdefined T; const T = zeros(Int64(MAX_TIME/dt)); end if ! @isdefined DELTA_T; const DELTA_T = zeros(Int64(MAX_TIME/dt)); end +if ! @isdefined STEERING; const STEERING = zeros(Int64(MAX_TIME/dt)); end function simulate(integrator) start_time_ns = time_ns() @@ -40,6 +41,10 @@ function simulate(integrator) i=1 j=0; k=0 GC.gc() + GC.gc() + if Sys.total_memory()/1e9 > 24 && MAX_TIME < 500 + GC.enable(false) + end max_time = 0 t_gc_tot = 0 sys_state = SysState(kps4) @@ -59,9 +64,11 @@ function simulate(integrator) # t_sim = @elapsed KiteModels.next_step!(kps4, integrator, v_ro=v_ro, dt=dt) sys_state = SysState(kps4) - if i <= length(T) + if i <= length(T) && i > 10/dt T[i] = dt * i - DELTA_T[i] = time_ns() - start_time_ns - 1e9*dt + # DELTA_T[i] = (time_ns() - start_time_ns - 1e9*dt)/1e6 + dt*1000 + DELTA_T[i] = t_sim * 1000 + STEERING[i] = sys_state.steering end on_new_systate(ssc, sys_state) if mod(i, TIME_LAPSE_RATIO) == 0 @@ -126,6 +133,16 @@ on(viewer.btn_AUTO.clicks) do c; autopilot(); end play() stop(viewer) +GC.enable(true) include("../test/plot.jl") -p1 = plot1(T, DELTA_T) - +p1 = plot2(T, DELTA_T, STEERING, labels=["t_sim [ms]", "steering [-]"]) +println("Mean time per timestep: $(mean(DELTA_T)) ms") +println("Maximum time per timestep: $(maximum(DELTA_T)) ms") +index=Int64(round(12/dt)) +println("Maximum for t>12s : $(maximum(DELTA_T[index:end])) ms") + +# GC disabled, Ryzen 7950X, 4x realtime +# Missed the deadline for 0.04 %. Max time: 166.1 ms +# Mean time per timestep: 3.0985575495652173 ms +# Maximum time per timestep: 11.14224 ms +# Maximum for t>12s : 11.14224 ms \ No newline at end of file diff --git a/test/plot.jl b/test/plot.jl index e59769ae..8943140d 100644 --- a/test/plot.jl +++ b/test/plot.jl @@ -2,52 +2,54 @@ using Pkg if ! ("Plots" ∈ keys(Pkg.project().dependencies)) using TestEnv; TestEnv.activate() end -import PyPlot; +import PyPlot as plt function plot1(X, Y; label="", width=2, xtickfontsize=12, ytickfontsize=12, legendfontsize=12, fig="") if fig != "" - PyPlot.figure(fig) + plt.figure(fig) end - p = PyPlot.plot(X, Y; label) - PyPlot.grid(true) + p = plt.plot(X, Y; label) + plt.grid(true) p end function plot2(X, Y1, Y2; labels=["", ""], fig="", title="") - fig_ = PyPlot.figure(fig, figsize=(8, 6)) - ax1 = PyPlot.subplot(211) - PyPlot.suptitle(title, fontsize=14) # Super title - PyPlot.plot(X, Y1, label=labels[1]); - ylabel(labels[1], fontsize=14); - PyPlot.grid(true) - setp(ax1.get_xticklabels(), visible=false) - ax2 = PyPlot.subplot(212, sharex = ax1) - PyPlot.plot(X, Y2, label=labels[2]) - PyPlot.grid(true) - ylabel(labels[2], fontsize=14); grid(true) - xlabel("time [s]", fontsize=14) - xlim(0, X[end]) - tight_layout() + fig_ = plt.figure(fig, figsize=(8, 6)) + ax1 = plt.subplot(211) + plt.suptitle(title, fontsize=14) # Super title + plt.plot(X, Y1, label=labels[1]); + plt.ylabel(labels[1], fontsize=14); + plt.grid(true) + plt.setp(ax1.get_xticklabels(), visible=false) + ax2 = plt.subplot(212, sharex = ax1) + plt.plot(X, Y2, label=labels[2]) + plt.grid(true) + plt.ylabel(labels[2], fontsize=14); + plt.grid(true) + plt.xlabel("time [s]", fontsize=14) + plt.xlim(0, X[end]) + plt.tight_layout() end function plot3(X, Y1, Y2, Y3; labels=["", "", ""], fig="", title="") - fig_ = PyPlot.figure(fig, figsize=(8, 6)) - ax1 = PyPlot.subplot(311) - PyPlot.suptitle(title, fontsize=14) # Super title - PyPlot.plot(X, Y1, label=labels[1]); + fig_ = plt.figure(fig, figsize=(8, 6)) + ax1 = plt.subplot(311) + plt.suptitle(title, fontsize=14) # Super title + plt.plot(X, Y1, label=labels[1]); ylabel(labels[1], fontsize=14); - PyPlot.grid(true) - setp(ax1.get_xticklabels(), visible=false) - ax2 = PyPlot.subplot(312, sharex = ax1) - PyPlot.plot(X, Y2, label=labels[2]) - PyPlot.grid(true) + plt.grid(true) + plt.setp(ax1.get_xticklabels(), visible=false) + ax2 = plt.subplot(312, sharex = ax1) + plt.plot(X, Y2, label=labels[2]) + plt.grid(true) ylabel(labels[2], fontsize=14); grid(true) - setp(ax2.get_xticklabels(), visible=false) - ax3 = PyPlot.subplot(313, sharex = ax1) - PyPlot.plot(X, Y3, label=labels[3]) - PyPlot.grid(true) - ylabel(labels[3], fontsize=14); grid(true) - xlabel("time [s]", fontsize=14) - xlim(0, X[end]) - tight_layout() + plt.setp(ax2.get_xticklabels(), visible=false) + ax3 = plt.subplot(313, sharex = ax1) + plt.plot(X, Y3, label=labels[3]) + plt.grid(true) + plt.ylabel(labels[3], fontsize=14); + plt.grid(true) + plt.xlabel("time [s]", fontsize=14) + plt.xlim(0, X[end]) + plt.tight_layout() end \ No newline at end of file