From 206dd4db51ad40e39047ae600f52ff8786a7f705 Mon Sep 17 00:00:00 2001 From: Uwe Fechner Date: Mon, 8 Jul 2024 12:22:15 +0200 Subject: [PATCH] Add test_parking.jl --- test/test_parking.jl | 51 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 test/test_parking.jl diff --git a/test/test_parking.jl b/test/test_parking.jl new file mode 100644 index 0000000..a9552a5 --- /dev/null +++ b/test/test_parking.jl @@ -0,0 +1,51 @@ +using Pkg +if ! ("KiteModels" ∈ keys(Pkg.project().dependencies)) + using TestEnv; TestEnv.activate() +end + +using KiteViewers, KiteModels, KitePodModels, Rotations, Timers + +# change this to KPS3 or KPS4 +const Model = KPS4 +set_data_path() + +if ! @isdefined kcu; const kcu = KCU(se()); end +if ! @isdefined kps4; const kps4 = Model(kcu); end + +# the following values can be changed to match your interest +dt = 0.05 +TIME = 30 +TIME_LAPSE_RATIO = 1 +STEPS = Int64(round(TIME/dt)) +STATISTIC = false +SHOW_KITE = false +# end of user parameter section # + +viewer::Viewer3D = Viewer3D(SHOW_KITE) + +function update_system2(kps) + sys_state = SysState(kps) + KiteViewers.update_system(viewer, sys_state; scale = 0.08, kite_scale=3) +end + +function simulate(integrator, steps) + start = integrator.p.iter + start_time_ns = time_ns() + for i in 1:steps + set_depower_steering(kps4.kcu, 0.25, 0.0) + # KitePodModels.on_timer(kcu, dt) + KiteModels.next_step!(kps4, integrator, dt=dt) + reltime = i*dt + if mod(i, TIME_LAPSE_RATIO) == 0 || i == steps + update_system2(kps4) + wait_until(start_time_ns+dt, always_sleep=true) + start_time_ns = time_ns() + end + end + (integrator.p.iter - start) / steps +end + +integrator = KiteModels.init_sim!(kps4, stiffness_factor=0.5, prn=STATISTIC) + +av_steps = simulate(integrator, STEPS) +nothing