Skip to content

Commit 508a100

Browse files
committed
Two more test scripts
1 parent 53944e9 commit 508a100

File tree

3 files changed

+121
-0
lines changed

3 files changed

+121
-0
lines changed

examples/menu.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ using REPL.TerminalMenus
33
options = ["test_mixer2 = include(\"../test/test_mixer2.jl\")",
44
"test_mixer3 = include(\"../test/test_mixer3.jl\")",
55
"test_solver = include(\"../test/test_solver.jl\")",
6+
"test_speedcontroller1 = include(\"../test/test_speedcontroller1.jl\")",
7+
"test_speedcontroller2 = include(\"../test/test_speedcontroller2.jl\")",
68
"test_lower_force1 = include(\"../test/test_lower_force1.jl\")",
79
"test_forcespeedcontroller1 = include(\"../test/test_forcespeedcontroller1.jl\")",
810
"test_forcespeedcontroller2 = include(\"../test/test_forcespeedcontroller2.jl\")",

test/test_speedcontroller1.jl

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# activate the test environment if needed
2+
using Pkg
3+
if ! ("ControlPlots" keys(Pkg.project().dependencies))
4+
using TestEnv; TestEnv.activate()
5+
end
6+
using Timers; tic()
7+
8+
# Test the speed controller.
9+
# Input: A varying wind speed. Implements the simulink block diagram, shown in
10+
# docs/speed_controller_test1.png
11+
using WinchControllers, ControlPlots, KiteUtils
12+
13+
set = deepcopy(load_settings("system.yaml"))
14+
wcs = WCSettings(dt=0.02)
15+
16+
DURATION = 10.0
17+
SAMPLES = Int(DURATION / wcs.dt + 1)
18+
TIME = range(0.0, DURATION, SAMPLES)
19+
V_WIND_MAX = 8.0 # max wind speed of test wind
20+
V_WIND_MIN = 4.0 # min wind speed of test wind
21+
FREQ_WIND = 0.25 # frequency of the triangle wind speed signal
22+
BENCHMARK = false
23+
24+
include("test_utilities.jl")
25+
26+
STARTUP = get_startup(wcs)
27+
V_WIND = STARTUP .* get_triangle_wind(wcs)
28+
V_RO = zeros(SAMPLES)
29+
V_SET_OUT = zeros(SAMPLES)
30+
FORCE = zeros(SAMPLES)
31+
ACC = zeros(SAMPLES)
32+
ACC_SET = zeros(SAMPLES)
33+
winch = Winch(wcs, set)
34+
pid1 = SpeedController(wcs)
35+
set_v_set(pid1, -0.5)
36+
set_tracking(pid1, -0.5)
37+
set_inactive(pid1, false)
38+
set_v_set_in(pid1, 4.0)
39+
last_v_set_out = 0.0
40+
if BENCHMARK
41+
# b = @benchmark for i in 1:SAMPLES
42+
# speed_controller_step!(pid1, winch, i, last_v_set_out, V_WIND, STARTUP, ACC, FORCE, ACC_SET, V_SET_OUT)
43+
# end
44+
else
45+
for i in 1:SAMPLES
46+
speed_controller_step!(pid1, winch, i, last_v_set_out, V_WIND, STARTUP, ACC, FORCE, ACC_SET, V_SET_OUT)
47+
end
48+
end
49+
50+
p=plotx(TIME, V_WIND, V_RO, V_SET_OUT, ACC, FORCE*0.001;
51+
ylabels=["v_wind [m/s]", "v_reel_out [m/s]", "v_set_out [m/s]", "acc [m/s²]", "force [kN]"],
52+
fig="test_speedcontroller1")
53+
display(p)
54+
55+
println("Max iterations needed: $(wcs.iter)")
56+
if BENCHMARK println("Average time per control step: $(mean(b.times)/SAMPLES/1e9) s") end
57+
toc()
58+
nothing

test/test_speedcontroller2.jl

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# activate the test environment if needed
2+
using Pkg
3+
if ! ("ControlPlots" keys(Pkg.project().dependencies))
4+
using TestEnv; TestEnv.activate()
5+
end
6+
using Timers; tic()
7+
8+
# Test the speed controller. , using a reel- out speed, proportional to the sqare-root
9+
# of the force.
10+
# Input: A varying wind speed. Implements the simulink block diagram, shown in
11+
# docs/speed_controller_test2.png
12+
using WinchControllers, ControlPlots, KiteUtils
13+
14+
set = deepcopy(load_settings("system.yaml"))
15+
wcs = WCSettings(dt=0.02)
16+
17+
DURATION = 10.0
18+
SAMPLES = Int(DURATION / wcs.dt + 1)
19+
TIME = range(0.0, DURATION, SAMPLES)
20+
V_WIND_MAX = 8.0 # max wind speed of test wind
21+
V_WIND_MIN = 4.0 # min wind speed of test wind
22+
FREQ_WIND = 0.25 # frequency of the triangle wind speed signal
23+
BENCHMARK = false
24+
25+
include("test_utilities.jl")
26+
27+
STARTUP = get_startup(wcs)
28+
V_WIND = STARTUP .* get_triangle_wind(wcs)
29+
V_RO = zeros(SAMPLES)
30+
V_SET_OUT = zeros(SAMPLES)
31+
FORCE = zeros(SAMPLES)
32+
ACC = zeros(SAMPLES)
33+
ACC_SET = zeros(SAMPLES)
34+
winch = Winch(wcs, set)
35+
calc = CalcVSetIn(wcs)
36+
pid1 = SpeedController(wcs)
37+
set_tracking(pid1, 0)
38+
set_inactive(pid1, true)
39+
set_inactive(pid1, false)
40+
set_v_set_in(pid1, 4.0)
41+
last_v_set_out = 0.0
42+
last_force = Ref(0.0)
43+
if BENCHMARK
44+
# b = @benchmark for i in 1:SAMPLES
45+
# speed_controller_step2!(pid1, winch, calc, i, last_force, last_v_set_out, V_WIND, STARTUP, ACC, FORCE, ACC_SET, V_SET_OUT)
46+
# end
47+
else
48+
for i in 1:SAMPLES
49+
speed_controller_step2!(pid1, winch, calc, i, last_force, last_v_set_out, V_WIND, STARTUP, ACC, FORCE, ACC_SET, V_SET_OUT)
50+
end
51+
end
52+
53+
p=plotx(TIME, V_WIND, V_RO, V_SET_OUT, ACC, FORCE*0.001;
54+
ylabels=["v_wind [m/s]", "v_reel_out [m/s]", "v_set_out [m/s]", "acc [m/s²]", "force [kN]"],
55+
fig="test_speedcontroller2")
56+
display(p)
57+
58+
println("Max iterations needed: $(wcs.iter)")
59+
if BENCHMARK println("Average time per control step: $(mean(b.times)/SAMPLES/1e9) s") end
60+
toc()
61+
nothing

0 commit comments

Comments
 (0)