Skip to content

Commit

Permalink
add plot_steering
Browse files Browse the repository at this point in the history
  • Loading branch information
ufechner7 committed Sep 11, 2024
1 parent 287118f commit eb234f1
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions examples/plot_steering.jl
Original file line number Diff line number Diff line change
@@ -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")

0 comments on commit eb234f1

Please sign in to comment.