Skip to content

Commit

Permalink
improve plotting
Browse files Browse the repository at this point in the history
  • Loading branch information
Uwe Fechner committed Mar 18, 2024
1 parent 97cbc25 commit c21e4ae
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
12 changes: 8 additions & 4 deletions examples/autopilot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down
6 changes: 4 additions & 2 deletions test/plot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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="")
Expand All @@ -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="")
Expand Down Expand Up @@ -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

0 comments on commit c21e4ae

Please sign in to comment.