Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ufechner7 committed Mar 16, 2024
1 parent a72dba6 commit 91fe332
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 72 deletions.
84 changes: 20 additions & 64 deletions test/plot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,72 +24,28 @@ function plotxy(X, Y; xlabel="", ylabel, fig="")
plt.tight_layout()
end

function plot2(X, Y1, Y2; labels=["", ""], fig="", title="")
function plotx(X, Y...; labels=nothing, fig="", title="")
len=length(Y)
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_ = plt.figure(fig, figsize=(8, 6))
ax1 = plt.subplot(311)
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(312, sharex = ax1)
plt.plot(X, Y2, label=labels[2])
plt.grid(true)
plt.ylabel(labels[2], fontsize=14);
plt.grid(true)
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)
i=1
ax=[]
for y in Y
subplot=100len+10+i
push!(ax, plt.subplot(subplot))
if i==1
plt.suptitle(title, fontsize=14) # Super title
end
if ! isnothing(labels)
lbl=labels[i]
else
lbl=""
end
plt.plot(X, y, label=lbl)
plt.ylabel(lbl, fontsize=14);
plt.grid(true)
i+=1
end
plt.xlabel("time [s]", fontsize=14)
plt.xlim(0, X[end])
plt.tight_layout()
end

function plot4(X, Y1, Y2, Y3, Y4; labels=["", "", "", ""], fig="", title="")
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);
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)
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)
ax4 = plt.subplot(313, sharex = ax1)
plt.plot(X, Y4, label=labels[4])
plt.grid(true)
plt.ylabel(labels[4], fontsize=14);
plt.grid(true)
plt.xlabel("time [s]", fontsize=14)
plt.xlim(0, X[end])
plt.tight_layout()
end
2 changes: 1 addition & 1 deletion test/test_flightpathcontroller1.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ end

include("plot.jl")

plot3(TIME, PSI, BETA, PSI_DOT;
plotx(TIME, PSI, BETA, PSI_DOT;
labels=["heading angle psi [°]","elevation β [°]", "psi_dot [rad/s]"],
fig = "test_fpc1")

Expand Down
2 changes: 1 addition & 1 deletion test/test_flightpathcontroller2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ for i in 1:SAMPLES
on_timer(kite)
end
include("plot.jl")
plot3(TIME, PSI, BETA, PSI_DOT;
plotx(TIME, PSI, BETA, PSI_DOT;
labels=["heading angle psi [°]", "elevation β [°]", "psi_dot [rad/s]"],
fig="test_fpc2")

Expand Down
6 changes: 3 additions & 3 deletions test/test_forcespeedcontroller1.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ for i in 1:SAMPLES
end

include("plot.jl")
plot3(TIME, V_WIND, V_RO, V_SET_OUT,
plotx(TIME, V_WIND, V_RO, V_SET_OUT,
labels=["v_wind [m/s]", "v_reel_out [m/s]", "v_set_out [m/s]"],
fig="test_forcespeed_1a")

plot2(TIME, F_ERR*0.001, V_ERR,
plotx(TIME, F_ERR*0.001, V_ERR,
labels=["f_err [kN]", "v_error [m/s"],
fig="test_forcespeed_1b")

plot2(TIME, ACC, FORCE*0.001,
plotx(TIME, ACC, FORCE*0.001,
labels=["acc [m/s²]", "force [kN]"],
fig="test_forcespeed_1c")

Expand Down
6 changes: 3 additions & 3 deletions test/test_forcespeedcontroller2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ for i in 1:SAMPLES
speed_controller_step4!(pid1, pid2, pid3, mix3, winch, calc, i, last_force, last_v_set_out, V_WIND, STARTUP, V_RO, ACC, FORCE, V_SET_OUT, STATE, V_ERR, F_ERR)
end

plot3(TIME, V_WIND, V_RO, V_SET_OUT;
plotx(TIME, V_WIND, V_RO, V_SET_OUT;
labels=["v_wind [m/s]", "v_reel_out [m/s]", "v_set_out [m/s]"],
fig="test_forcespeed_2a")

plot2(TIME, F_ERR*0.001, V_ERR;
plotx(TIME, F_ERR*0.001, V_ERR;
labels=["f_err [kN]", "v_error [m/s]"],
fig="test_forcespeed_2b")

plot3(TIME, ACC, FORCE*0.001, STATE;
plotx(TIME, ACC, FORCE*0.001, STATE;
labels=["acc [m/s²]", "force [kN]", "state"],
fig="test_forcespeed_2c")

Expand Down

0 comments on commit 91fe332

Please sign in to comment.