From c21e4ae7e8346a37194f2a73e7fd2e2f6d91e0d5 Mon Sep 17 00:00:00 2001 From: Uwe Fechner Date: Mon, 18 Mar 2024 10:37:52 +0100 Subject: [PATCH] improve plotting --- examples/autopilot.jl | 12 ++++++++---- test/plot.jl | 6 ++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/examples/autopilot.jl b/examples/autopilot.jl index 766a6973..99434b7b 100644 --- a/examples/autopilot.jl +++ b/examples/autopilot.jl @@ -31,9 +31,10 @@ phi_set = 21.48 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 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 +if ! @isdefined DEPOWER_; const DEPOWER_ = zeros(Int64(MAX_TIME/dt)); end function simulate(integrator) start_time_ns = time_ns() @@ -67,8 +68,9 @@ function simulate(integrator) if i <= length(T) && i > 10/dt T[i] = dt * i # DELTA_T[i] = (time_ns() - start_time_ns - 1e9*dt)/1e6 + dt*1000 - DELTA_T[i] = t_sim * 1000 + DELTA_T[i] = t_sim * 1000 STEERING[i] = sys_state.steering + DEPOWER_[i] = sys_state.depower end on_new_systate(ssc, sys_state) if mod(i, TIME_LAPSE_RATIO) == 0 @@ -135,7 +137,9 @@ stop(viewer) GC.enable(true) include("../test/plot.jl") -p1 = plot2(T, DELTA_T, STEERING, labels=["t_sim [ms]", "steering [-]"]) +plotx(T, DELTA_T, 100*STEERING, 100*DEPOWER_, + labels=["t_sim [ms]", "steering [%]", "depower [%]"], + fig="simulation_timing") println("Mean time per timestep: $(mean(DELTA_T)) ms") println("Maximum time per timestep: $(maximum(DELTA_T)) ms") index=Int64(round(12/dt)) diff --git a/test/plot.jl b/test/plot.jl index c0538b08..ef6ac403 100644 --- a/test/plot.jl +++ b/test/plot.jl @@ -8,9 +8,9 @@ function plot1(X, Y; label="", fig="") if fig != "" plt.figure(fig) end - p = plt.plot(X, Y; label) + plt.plot(X, Y; label) plt.grid(true) - p + nothing end function plotxy(X, Y; xlabel="", ylabel, fig="") @@ -22,6 +22,7 @@ function plotxy(X, Y; xlabel="", ylabel, fig="") plt.ylabel(ylabel, fontsize=14); plt.grid(true) plt.tight_layout() + nothing end function plotx(X, Y...; labels=nothing, fig="", title="") @@ -55,4 +56,5 @@ function plotx(X, Y...; labels=nothing, fig="", title="") plt.xlabel("time [s]", fontsize=14) plt.xlim(0, X[end]) plt.tight_layout() + nothing end