From eb234f1c728698735d6886efb0eec27e8922601a Mon Sep 17 00:00:00 2001 From: Uwe Fechner Date: Wed, 11 Sep 2024 16:11:52 +0200 Subject: [PATCH] add plot_steering --- examples/plot_steering.jl | 67 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 examples/plot_steering.jl diff --git a/examples/plot_steering.jl b/examples/plot_steering.jl new file mode 100644 index 00000000..6b37df89 --- /dev/null +++ b/examples/plot_steering.jl @@ -0,0 +1,67 @@ +using Printf +using KiteModels, KitePodModels, KiteUtils + +set = deepcopy(load_settings("system.yaml")) + +set.abs_tol=0.0006 +set.rel_tol=0.00001 + +# the following values can be changed to match your interest +dt = 0.05 +set.solver="DFBDF" # IDA or DFBDF +STEPS = 300 +PLOT = true +FRONT_VIEW = false +ZOOM = true +PRINT = false +STATISTIC = false +# end of user parameter section # + +kcu::KCU = KCU(set) +kps4::KPS4 = KPS4(kcu) + +if PLOT + using Pkg + if ! ("ControlPlots" ∈ keys(Pkg.project().dependencies)) + using TestEnv; TestEnv.activate() + end + using ControlPlots +end + +function simulate(integrator, steps, plot=false) + iter = 0 + for i in 1:steps + if PRINT + lift, drag = KiteModels.lift_drag(kps4) + @printf "%.2f: " round(integrator.t, digits=2) + println("lift, drag [N]: $(round(lift, digits=2)), $(round(drag, digits=2))") + end + + KiteModels.next_step!(kps4, integrator; set_speed=0, dt) + iter += kps4.iter + + if plot + reltime = i*dt-dt + if mod(i, 5) == 1 + plot2d(kps4.pos, reltime; zoom=ZOOM, front=FRONT_VIEW, segments=set.segments) + end + end + end + iter / steps +end + +integrator = KiteModels.init_sim!(kps4; delta=0.0, stiffness_factor=1, prn=STATISTIC) + +if PLOT + av_steps = simulate(integrator, STEPS, true) +else + println("\nStarting simulation...") + simulate(integrator, 100) + runtime = @elapsed av_steps = simulate(integrator, STEPS-100) + println("\nTotal simulation time: $(round(runtime, digits=3)) s") + speed = (STEPS-100) / runtime * dt + println("Simulation speed: $(round(speed, digits=2)) times realtime.") +end +lift, drag = KiteModels.lift_drag(kps4) +println("lift, drag [N]: $(round(lift, digits=2)), $(round(drag, digits=2))") +println("Average number of callbacks per time step: $av_steps")