Skip to content

Commit 3e37330

Browse files
directions tests
1 parent b39d42c commit 3e37330

File tree

4 files changed

+212
-0
lines changed

4 files changed

+212
-0
lines changed

src/Definitions/axesfromdir.jl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,25 @@ function add_axes_twodir!(
1616
project::Bool=false
1717
) where {O,T}
1818

19+
# Check directions
20+
if !(has_direction(frames, dir1))
21+
throw(
22+
ArgumentError("No direction with name $dir1 available.")
23+
)
24+
end
25+
26+
if !(has_direction(frames, dir2))
27+
throw(
28+
ArgumentError("No direction with name $dir2 available.")
29+
)
30+
end
31+
32+
if !(has_axes(frames, parent))
33+
throw(
34+
ArgumentError("No axes with id $pid available.")
35+
)
36+
end
37+
1938
fun = t -> twodir_to_dcm(
2039
direction3(frames, dir1, parent, t), direction3(frames, dir2, parent, t), seq
2140
)

test/Definitions/Definitions.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,8 @@ download(KERNELS; verbose=true, force=false)
4141
@safetestset "Lunar" begin
4242
include("lunar.jl")
4343
end
44+
@safetestset "Directions" begin
45+
include("directions.jl")
46+
include("twodir.jl")
47+
end
4448
end;

test/Definitions/directions.jl

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
using FrameTransformations
2+
using Ephemerides
3+
using RemoteFiles
4+
using Test
5+
using LinearAlgebra
6+
7+
@RemoteFileSet KERNELS "Spice Kernels Set" begin
8+
LEAP = @RemoteFile "https://naif.jpl.nasa.gov/pub/naif/generic_kernels/lsk/latest_leapseconds.tls" dir = joinpath(
9+
@__DIR__, "..", "assets"
10+
)
11+
DE432 = @RemoteFile "https://naif.jpl.nasa.gov/pub/naif/generic_kernels/spk/planets/de432s.bsp" dir = joinpath(
12+
@__DIR__, "..", "assets"
13+
)
14+
end;
15+
16+
download(KERNELS; verbose=true, force=false)
17+
18+
frames = FrameSystem{4,Float64}()
19+
add_axes_icrf!(frames)
20+
21+
eph = EphemerisProvider(path(KERNELS[:DE432]))
22+
23+
add_point!(frames, :SSB, 0, 1)
24+
add_point_alias!(frames, :SSB, :SolarSystemB)
25+
26+
add_point_ephemeris!(frames, eph, :Sun, 10)
27+
add_point_ephemeris!(frames, eph, :EarthB, 3)
28+
add_point_ephemeris!(frames, eph, :Earth, 399)
29+
30+
@testset "Position" verbose = false begin
31+
add_direction_position!(frames, :SunEarth, :Sun, :Earth, :ICRF)
32+
33+
for _ = 1:100
34+
e = rand(0:1e8)
35+
36+
ref = vector3(frames, :Sun, :Earth, :ICRF, e)
37+
ref /= norm(ref)
38+
39+
val = direction3(frames, :SunEarth, :ICRF, e)
40+
@test dot(val, ref) 1.0
41+
end
42+
end
43+
44+
@testset "Velocity" verbose = false begin
45+
add_direction_velocity!(frames, :SunEarthVel, :Sun, :Earth, :ICRF)
46+
47+
for _ = 1:100
48+
e = rand(0:1e8)
49+
50+
@views ref = vector6(frames, :Sun, :Earth, :ICRF, e)[4:end]
51+
ref /= norm(ref)
52+
53+
val = direction3(frames, :SunEarthVel, :ICRF, e)
54+
@test dot(val, ref) 1.0
55+
end
56+
end
57+
58+
@testset "Orthogonal" verbose = false begin
59+
add_direction_orthogonal!(frames, :SunEarthMom, :SunEarth, :SunEarthVel, :ICRF)
60+
61+
for _ = 1:100
62+
e = rand(0:1e8)
63+
64+
p, v = Translation(vector6(frames, :Sun, :Earth, :ICRF, e)...)
65+
p /= norm(p)
66+
v /= norm(v)
67+
ref = cross(p, v)
68+
ref /= norm(ref)
69+
70+
val = direction3(frames, :SunEarthMom, :ICRF, e)
71+
@test dot(val, ref) 1.0
72+
end
73+
end
74+
75+
@testset "Fixed" verbose = false begin
76+
add_direction_fixed!(frames, :Fix, :ICRF, [1.0, 0.0, 0.0])
77+
78+
for _ = 1:100
79+
e = rand(0:1e8)
80+
81+
val = direction3(frames, :Fix, :ICRF, e)
82+
@test val[1] 1.0
83+
end
84+
end

test/Definitions/twodir.jl

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
using FrameTransformations
2+
using Ephemerides
3+
using RemoteFiles
4+
using Test
5+
using LinearAlgebra
6+
using StaticArrays
7+
8+
@RemoteFileSet KERNELS "Spice Kernels Set" begin
9+
LEAP = @RemoteFile "https://naif.jpl.nasa.gov/pub/naif/generic_kernels/lsk/latest_leapseconds.tls" dir = joinpath(
10+
@__DIR__, "..", "assets"
11+
)
12+
DE432 = @RemoteFile "https://naif.jpl.nasa.gov/pub/naif/generic_kernels/spk/planets/de432s.bsp" dir = joinpath(
13+
@__DIR__, "..", "assets"
14+
)
15+
end;
16+
17+
download(KERNELS; verbose=true, force=false)
18+
19+
atol = 1e-8
20+
21+
# Define two non parallel vectors and their 1st, 2nd and 3rd order time derivatives!
22+
function get_v1(t)
23+
return SA[cos(3t), t*sin(t), t^2*cos(t)]
24+
end
25+
get_v2(t) = SA[t^3, t^2, t]
26+
27+
@testset "Sequence assembly" begin
28+
for _ = 1:100
29+
30+
θ = rand()
31+
a, b = get_v1(θ)[1:3], get_v2(θ)[1:3]
32+
c = cross(a, b)
33+
34+
aᵤ, bᵤ, cᵤ = a / norm(a), b / norm(b), c / norm(c)
35+
36+
# XY
37+
R = FrameTransformations.twodir_to_dcm(a, b, :XY)
38+
39+
@test R' * [1, 0, 0] aᵤ atol = atol
40+
@test R' * [0, 0, 1] cᵤ atol = atol
41+
@test dot(R' * [0, 1, 0], aᵤ) 0 atol = atol
42+
43+
# YX
44+
R = FrameTransformations.twodir_to_dcm(a, b, :YX)
45+
46+
@test R' * [0, 1, 0] aᵤ atol = atol
47+
@test R' * [0, 0, 1] -cᵤ atol = atol
48+
@test dot(R' * [1, 0, 0], aᵤ) 0 atol = atol
49+
50+
# XZ
51+
R = FrameTransformations.twodir_to_dcm(a, b, :XZ)
52+
53+
@test R' * [1, 0, 0] aᵤ atol = atol
54+
@test R' * [0, 1, 0] -cᵤ atol = atol
55+
@test dot(R' * [0, 1, 0], aᵤ) 0 atol = atol
56+
57+
# ZX
58+
R = FrameTransformations.twodir_to_dcm(a, b, :ZX)
59+
60+
@test R' * [0, 0, 1] aᵤ atol = atol
61+
@test R' * [0, 1, 0] cᵤ atol = atol
62+
@test dot(R' * [1, 0, 0], aᵤ) 0 atol = atol
63+
64+
# YZ
65+
R = FrameTransformations.twodir_to_dcm(a, b, :YZ)
66+
67+
@test R' * [0, 1, 0] aᵤ atol = atol
68+
@test R' * [1, 0, 0] cᵤ atol = atol
69+
@test dot(R' * [0, 0, 1], aᵤ) 0 atol = atol
70+
71+
# ZY
72+
R = FrameTransformations.twodir_to_dcm(a, b, :ZY)
73+
74+
@test R' * [0, 0, 1] aᵤ atol = atol
75+
@test R' * [1, 0, 0] -cᵤ atol = atol
76+
@test dot(R' * [0, 1, 0], aᵤ) 0 atol = atol
77+
78+
end
79+
end;
80+
81+
@testset "Frames" begin
82+
83+
frames = FrameSystem{4,Float64}()
84+
add_axes_icrf!(frames)
85+
86+
eph = EphemerisProvider(path(KERNELS[:DE432]))
87+
add_point!(frames, :SSB, 0, 1)
88+
add_point_ephemeris!(frames, eph, :Sun, 10)
89+
add_point_ephemeris!(frames, eph, :EarthB, 3)
90+
add_point_ephemeris!(frames, eph, :Earth, 399)
91+
add_direction_position!(frames, :SunEarthPos, :Sun, :Earth, :ICRF)
92+
add_direction_velocity!(frames, :SunEarthVel, :Sun, :Earth, :ICRF)
93+
add_axes_twodir!(frames, :SunEarthRot, 2, :ICRF, :SunEarthPos, :SunEarthVel, :XY)
94+
95+
@test_throws ArgumentError add_axes_twodir!(frames, :SunEarthRot, 2, :ICRF, :A, :SunEarthVel, :XY)
96+
@test_throws ArgumentError add_axes_twodir!(frames, :SunEarthRot, 2, :ICRF, :SunEarthPos, :B, :XY)
97+
98+
for _ = 1:100
99+
e = rand(0:1e8)
100+
v = vector3(frames, :Sun, :Earth, :SunEarthRot, e)
101+
v /= norm(v)
102+
@test v[1] 1.0
103+
end
104+
105+
end;

0 commit comments

Comments
 (0)