Skip to content

Commit 5de9a22

Browse files
committed
Add tests
1 parent 51211b0 commit 5de9a22

1 file changed

Lines changed: 28 additions & 15 deletions

File tree

test/test_flightpathcontroller1.jl

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ end
66
using ControlPlots, KiteControllers, Timers; tic()
77
using Printf: @sprintf
88
using Statistics: mean
9+
using Test: @test, @testset
910
using KiteUtils: Settings, load_settings
1011
using Printf: @sprintf
1112

@@ -23,8 +24,9 @@ fpc = FlightPathController(fcs; u_d0, u_d)
2324
kite = KiteModel(fcs)
2425
kite.omega = 0.08
2526
v_a = 20.0
26-
u_d = 0.2 # was: u_d_prime
27-
on_control_command(fpc, psi_dot_set=51.566)
27+
u_d = 0.19 # was: u_d_prime
28+
psi_dot_set = 51.566
29+
on_control_command(fpc; psi_dot_set=psi_dot_set)
2830
PSI, BETA, PHI, PSI_DOT = zeros(SAMPLES), zeros(SAMPLES), zeros(SAMPLES), zeros(SAMPLES)
2931
u_s = 0.0
3032
for i in 1:SAMPLES
@@ -50,19 +52,30 @@ p=plotx(TIME, PSI, BETA, PSI_DOT;
5052
fig = "test_fpc1")
5153
display(p)
5254

53-
start_idx = findfirst(t -> t >= 10.0, TIME)
54-
if start_idx !== nothing
55-
psi_dot_slice = @view PSI_DOT[start_idx:end]
56-
psi_dot_avg = mean(psi_dot_slice)
57-
psi_dot_min = minimum(psi_dot_slice)
58-
psi_dot_max = maximum(psi_dot_slice)
59-
psi_dot_avg_deg = rad2deg(psi_dot_avg)
60-
psi_dot_min_deg = rad2deg(psi_dot_min)
61-
psi_dot_max_deg = rad2deg(psi_dot_max)
62-
println("psi_dot stats for t>=10s [deg/s]:")
63-
println("avg: $(@sprintf("%.2f", psi_dot_avg_deg))")
64-
println("min: $(@sprintf("%.2f", psi_dot_min_deg))")
65-
println("max: $(@sprintf("%.2f", psi_dot_max_deg))")
55+
@testset "Flight path controller psi_dot tracking" begin
56+
start_idx = findfirst(t -> t >= 10.0, TIME)
57+
@test start_idx !== nothing
58+
59+
if start_idx !== nothing
60+
psi_dot_slice = @view PSI_DOT[start_idx:end]
61+
psi_dot_avg = mean(psi_dot_slice)
62+
psi_dot_min = minimum(psi_dot_slice)
63+
psi_dot_max = maximum(psi_dot_slice)
64+
psi_dot_avg_deg = rad2deg(psi_dot_avg)
65+
psi_dot_min_deg = rad2deg(psi_dot_min)
66+
psi_dot_max_deg = rad2deg(psi_dot_max)
67+
psi_dot_error_pct = ((psi_dot_avg_deg / psi_dot_set) - 1) * 100
68+
variation_pct = ((psi_dot_max_deg - psi_dot_min_deg) / (2 * psi_dot_set)) * 100
69+
println("psi_dot stats for t>=10s:")
70+
println("avg: $(@sprintf("%6.2f", psi_dot_avg_deg)) °/s")
71+
println("min: $(@sprintf("%6.2f", psi_dot_min_deg)) °/s")
72+
println("max: $(@sprintf("%6.2f", psi_dot_max_deg)) °/s")
73+
println("error: $(@sprintf("%6.2f", psi_dot_error_pct)) %")
74+
println("variation: ±$(@sprintf("%6.2f", variation_pct)) %\n")
75+
@test abs(psi_dot_error_pct) < 5.0
76+
@test variation_pct < 25.0
77+
end
6678
end
79+
nothing
6780

6881
# return TIME, PSI, BETA, PHI, PSI_DOT

0 commit comments

Comments
 (0)