Skip to content

Commit 15577a2

Browse files
authored
✨ Add conversion methods to DCM (#19)
1 parent db73613 commit 15577a2

File tree

6 files changed

+58
-5
lines changed

6 files changed

+58
-5
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
*.jl.mem
55
docs/build/
66
docs/site/
7+
Manifest.toml

Project.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1111
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
1212
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
1313

14-
[extras]
15-
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
16-
1714
[compat]
18-
julia = "1"
1915
Crayons = "4.0"
2016
StaticArrays = "1"
17+
julia = "1"
18+
19+
[extras]
20+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
2121

2222
[targets]
2323
test = ["Test"]

src/ReferenceFrameRotations.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ using StaticArrays
1616
export I
1717

1818
################################################################################
19-
# Types
19+
# Types & Conversions
2020
################################################################################
2121

2222
include("types.jl")
23+
include("conversions.jl")
2324

2425
################################################################################
2526
# Constants

src/conversions.jl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
2+
#
3+
# Description
4+
# ==============================================================================
5+
#
6+
# Conversion methods between different rotation types.
7+
#
8+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
9+
10+
# Base.convert is already exported
11+
12+
################################################################################
13+
# Conversion Methods
14+
################################################################################
15+
16+
# TODO: deprecate angle_to_dcm, quat_to_dcm, ...
17+
# TODO: move all the implementations over here
18+
19+
Base.convert(::Type{<:DCM}, a::EulerAngles) = angle_to_dcm(a)
20+
Base.convert(::Type{<:DCM}, a::Quaternion) = quat_to_dcm(a)
21+
Base.convert(::Type{<:DCM}, a::EulerAngleAxis) = angleaxis_to_dcm(a)

test/conversions.jl

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
2+
#
3+
# Desription
4+
# ==============================================================================
5+
#
6+
# Tests related to conversion methods.
7+
#
8+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
9+
10+
# File: ./src/conversions.jl
11+
# =========================================
12+
13+
# Functions: Base.convert
14+
# -------------------------
15+
16+
@testset "Conversion Methods" begin
17+
T = Float64
18+
19+
for rot_seq in valid_rot_seqs
20+
# Sample Euler angles.
21+
ea = EulerAngles(_rand_ang(T), _rand_ang(T), _rand_ang(T), rot_seq)
22+
23+
# Convert to DCM.
24+
D = convert(DCM, ea)
25+
@test D isa SArray
26+
@test eltype(D) === T
27+
@test size(D) == (3, 3)
28+
end
29+
end

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ end
119119
println("")
120120

121121
@time @addverbose @testset "Conversions" begin
122+
include("conversions.jl")
122123
include("./conversions/angle_to_angle.jl")
123124
include("./conversions/angle_to_angleaxis.jl")
124125
include("./conversions/angle_to_dcm.jl")

0 commit comments

Comments
 (0)