|
| 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