Skip to content

Commit

Permalink
Update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Uwe Fechner committed Mar 28, 2024
1 parent 3c49bc0 commit f048326
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 19 deletions.
12 changes: 7 additions & 5 deletions examples/parking_4p.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
11 changes: 7 additions & 4 deletions examples/tune_1p.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
21 changes: 11 additions & 10 deletions examples/tune_4p.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit f048326

Please sign in to comment.