From f04832658c3df468feb3e22a61535c88516883e6 Mon Sep 17 00:00:00 2001 From: Uwe Fechner Date: Thu, 28 Mar 2024 09:43:38 +0100 Subject: [PATCH] Update examples --- examples/parking_4p.jl | 12 +++++++----- examples/tune_1p.jl | 11 +++++++---- examples/tune_4p.jl | 21 +++++++++++---------- 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/examples/parking_4p.jl b/examples/parking_4p.jl index 532b359..b8c698d 100644 --- a/examples/parking_4p.jl +++ b/examples/parking_4p.jl @@ -5,15 +5,15 @@ if ! ("Plots" ∈ keys(Pkg.project().dependencies)) end using Timers; tic() -using KiteControllers, KiteViewers, KiteModels, Plots +using KiteControllers, KiteViewers, KiteModels, ControlPlots se().abs_tol=0.0000006 se().rel_tol=0.000001 -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 = WCSettings(); wcs.dt = 1/se().sample_freq fcs::FPCSettings = FPCSettings(); fcs.dt = wcs.dt -fpps:FPPSettings = FPPSettings() +fpps::FPPSettings = FPPSettings() ssc::SystemStateControl = SystemStateControl(wcs, fcs, fpps) dt::Float64 = wcs.dt @@ -133,4 +133,6 @@ on(viewer.btn_PARKING.clicks) do c; parking(); end play() stop(viewer) -plot(T, rad2deg.(AZIMUTH)) +plt.plot(T, rad2deg.(AZIMUTH)) +plt.pause(0.01) +plt.show(block=false) diff --git a/examples/tune_1p.jl b/examples/tune_1p.jl index a920e15..04e43be 100644 --- a/examples/tune_1p.jl +++ b/examples/tune_1p.jl @@ -8,11 +8,10 @@ using KiteUtils se().abs_tol=0.0000006 se().rel_tol=0.000001 -using KiteControllers, KiteModels, BayesOpt -import PyPlot as plt +using KiteControllers, KiteModels, BayesOpt, ControlPlots -if ! @isdefined kcu; const kcu = KCU(se()); end -if ! @isdefined kps; const kps = KPS3(kcu); end +kcu::KCU = KCU(se()) +kps::KPS3 = KPS3(kcu) wcs::WCSettings = WCSettings(); wcs.dt = 1/se().sample_freq fcs::FPCSettings = FPCSettings(); fcs.dt = wcs.dt fpps::FPPSettings = FPPSettings() @@ -110,6 +109,8 @@ end function show_result() plt.plot(T, rad2deg.(AZIMUTH)) + plt.pause(0.01) + plt.show(block=false) end function f(x) @@ -161,6 +162,8 @@ function plot_res() plt.plot(1:71, P) plt.plot!(1:71, D) plt.plot!(1:71, 10*RES) + plt.pause(0.01) + plt.show(block=false) end fcs.p=17.33 # 14.36 # 15.61 # 14.43 # 13.65 # 14.08 # 14.72 # 15.41 # 14.74 # 14.35 # 13.68 # 13.87 # 14.99 # 13.63 diff --git a/examples/tune_4p.jl b/examples/tune_4p.jl index 5c898bf..d42c2c3 100644 --- a/examples/tune_4p.jl +++ b/examples/tune_4p.jl @@ -8,11 +8,10 @@ using KiteUtils se().abs_tol=0.0000006 se().rel_tol=0.000001 -using KiteControllers, KiteModels, BayesOpt -import PyPlot as plt +using KiteControllers, KiteModels, BayesOpt, ControlPlots -if ! @isdefined kcu; const kcu = KCU(se()); end -if ! @isdefined kps; const kps = KPS4(kcu); end +kcu::KCU = KCU(se()) +kps4::KPS4 = KPS4(kcu) wcs::WCSettings = WCSettings(); wcs.dt = 1/se().sample_freq fcs::FPCSettings = FPCSettings(); fcs.dt = wcs.dt fpps::FPPSettings = FPPSettings() @@ -32,7 +31,7 @@ if ! @isdefined AZIMUTH; const AZIMUTH = zeros(Int64(MAX_TIME/dt)); end function simulate(integrator) i=1 - sys_state = SysState(kps) + sys_state = SysState(kps4) on_new_systate(ssc, sys_state) while true if i > 100 @@ -46,11 +45,11 @@ function simulate(integrator) elseif time < 21 steering = 0.1 end - set_depower_steering(kps.kcu, depower, steering) + set_depower_steering(kps4.kcu, depower, steering) end v_ro = 0.0 - KiteModels.next_step!(kps, integrator, v_ro=v_ro, dt=dt) - sys_state = SysState(kps) + KiteModels.next_step!(kps4, integrator, v_ro=v_ro, dt=dt) + sys_state = SysState(kps4) T[i] = dt * i AZIMUTH[i] = sys_state.azimuth on_new_systate(ssc, sys_state) @@ -80,10 +79,10 @@ end # the azimuth error in degrees squared and divided by the test duration function test_parking(suppress_overshoot_factor = 3.0) global LAST_RES - clear!(kps) + clear!(kps4) init_kcu(kcu, se()) AZIMUTH .= zeros(Int64(MAX_TIME/dt)) - integrator = KiteModels.init_sim!(kps, stiffness_factor=0.04) + integrator = KiteModels.init_sim!(kps4, stiffness_factor=0.04) simulate(integrator) res = calc_res(AZIMUTH, suppress_overshoot_factor) if res < LAST_RES @@ -96,6 +95,8 @@ end function show_result() plt.plot(T, rad2deg.(AZIMUTH)) + plt.pause(0.01) + plt.show(block=false) end function f(x)