Skip to content

Commit

Permalink
use PyPlot
Browse files Browse the repository at this point in the history
  • Loading branch information
Uwe Fechner committed Mar 15, 2024
1 parent 954b654 commit bc98e79
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 23 deletions.
2 changes: 2 additions & 0 deletions bin/run_julia
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ if [[ $HOSTNAME == "tuxedi" ]]; then
sudo performance.sh
fi

export MPLBACKEND=qt5agg

# instead of 8, use the number of fast CPU cores you have
GCT="--gcthreads=7,1"

Expand Down
10 changes: 10 additions & 0 deletions examples/autopilot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ 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

function simulate(integrator)
start_time_ns = time_ns()
Expand All @@ -57,6 +59,10 @@ 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)
T[i] = dt * i
DELTA_T[i] = time_ns() - start_time_ns - 1e9*dt
end
on_new_systate(ssc, sys_state)
if mod(i, TIME_LAPSE_RATIO) == 0
KiteViewers.update_system(viewer, sys_state; scale = 0.04/1.1, kite_scale=6.6)
Expand Down Expand Up @@ -119,3 +125,7 @@ on(viewer.btn_AUTO.clicks) do c; autopilot(); end

play()
stop(viewer)

include("../test/plot.jl")
p1 = plot1(T, DELTA_T)

17 changes: 9 additions & 8 deletions test/plot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ using Pkg
if ! ("Plots" keys(Pkg.project().dependencies))
using TestEnv; TestEnv.activate()
end
using Plots; inspectdr()
InspectDR.defaults.xaxiscontrol_visible = false
import PyPlot;

x=0:0.05:100
y1=sin.(x)

p1 = plot(x,y1, width=2, xtickfontsize=12, ytickfontsize=12, legendfontsize=12, legend=false)
pIDR = display(p1) # Display with InspectDR and keep plot object
resize!(pIDR.wnd, 1200, 700) # Resize GTK window directly
function plot1(X, Y; label="", width=2, xtickfontsize=12, ytickfontsize=12, legendfontsize=12, fig="")
if fig != ""
PyPlot.figure(fig)
end
p = PyPlot.plot(X, Y; label)
PyPlot.grid(true)
p
end
20 changes: 5 additions & 15 deletions test/test_flightpathcontroller1.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ TIME = range(0.0, DURATION, SAMPLES)

# Test the flight path controller against the simplified kite model as shown
# in diagram docs/flight_path_controller_test1.png .
using KiteControllers, Plots, BenchmarkTools
inspectdr()
InspectDR.defaults.xaxiscontrol_visible = false
InspectDR.defaults.pointdropmatrix = InspectDR.PDM_DEFAULTS[:never]
using KiteControllers, PyPlot, BenchmarkTools
fpc = FlightPathController(fcs)
kite = KiteModel(fcs)
kite.omega = 0.08
Expand All @@ -43,17 +40,10 @@ for i in 1:SAMPLES
on_timer(kite)
end

p1=plot(TIME, PSI, label="heading angle psi [°]", width=2, xtickfontsize=12, ytickfontsize=12, legend=false)
pIDR = display(p1) # Display with InspectDR and keep plot object
resize!(pIDR.wnd, 1200, 700) # Resize GTK window directly
include("plot.jl")

p2=plot(TIME, BETA, label="elevation β [°]", width=2, xtickfontsize=12, ytickfontsize=12, legendfontsize=12)
plot!(TIME, PHI, label="azimuth ϕ [°]", width=2, xtickfontsize=12, ytickfontsize=12, legendfontsize=12)
pIDR2 = display(p2) # Display with InspectDR and keep plot object
resize!(pIDR2.wnd, 1200, 700) # Resize GTK window directly

p3=plot(TIME, PSI_DOT, label="psi_dot [rad/s]", width=2, xtickfontsize=12, ytickfontsize=12, legendfontsize=12)
pIDR3 = display(p3) # Display with InspectDR and keep plot object
resize!(pIDR3.wnd, 1200, 700) # Resize GTK window directly
p1 = plot1(TIME, PSI; label="heading angle psi [°]", fig = "heading")
p2 = plot1(TIME, BETA, label="elevation β [°]", fig = "elevation")
p3 = plot1(TIME, PSI_DOT, label="psi_dot [rad/s]", fig = "psi_dot")

# return TIME, PSI, BETA, PHI, PSI_DOT

0 comments on commit bc98e79

Please sign in to comment.