Skip to content

Commit

Permalink
start stopped
Browse files Browse the repository at this point in the history
  • Loading branch information
Uwe Fechner committed Mar 22, 2024
1 parent 383ad76 commit 69577b8
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions examples/autopilot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ using Timers; tic()

using KiteControllers, KiteViewers, KiteModels, StatsBase

if ! @isdefined kcu; const kcu = KCU(se()); end
if ! @isdefined kps4; const kps4 = KPS4(kcu); end
kcu::KCU = KCU(se())
kps4::KPS4 = KPS4(kcu)

wcs = WCSettings(); update(wcs); wcs.dt = 1/se().sample_freq
fcs::FPCSettings = FPCSettings(); fcs.dt = wcs.dt
Expand Down Expand Up @@ -38,7 +38,10 @@ LAST_I::Int64=0
function simulate(integrator)
global LAST_I
start_time_ns = time_ns()
tmp=viewer.stop
clear_viewer(viewer)
viewer.stop=tmp
println("viewer.stop: ", viewer.stop)
i=1
j=0; k=0
GC.gc()
Expand All @@ -50,6 +53,7 @@ function simulate(integrator)
t_gc_tot = 0
sys_state = SysState(kps4)
on_new_systate(ssc, sys_state)
KiteViewers.update_system(viewer, sys_state; scale = 0.04/1.1, kite_scale=6.6)
while true
if viewer.stop
sleep(dt)
Expand Down Expand Up @@ -112,11 +116,12 @@ function simulate(integrator)
return div(i, TIME_LAPSE_RATIO)
end

function play()
function play(stop_=false)
global steps
viewer.stop=false
viewer.stop=stop_
integrator = KiteModels.init_sim!(kps4, stiffness_factor=0.04)
toc()
println("viewer.stop: ", viewer.stop)
steps = simulate(integrator)
GC.enable(true)
end
Expand All @@ -140,14 +145,14 @@ function autopilot()
end

on_stop(ssc)
parking()
viewer.stop=true
clear!(kps4)
on(viewer.btn_PLAY.clicks) do c; viewer.stop=false; end
# on(viewer.btn_STOP.clicks) do c; on_stop(ssc) end
on(viewer.btn_PARKING.clicks) do c; parking(); end
on(viewer.btn_AUTO.clicks) do c; autopilot(); end

play()
play(true)
stop(viewer)
KiteViewers.GLMakie.closeall()

Expand Down

0 comments on commit 69577b8

Please sign in to comment.