Skip to content

Commit c0f99eb

Browse files
committed
Get underlying quaternion parameters via Rotations.params(q)
1 parent 198ac52 commit c0f99eb

File tree

5 files changed

+25
-17
lines changed

5 files changed

+25
-17
lines changed

src/joint_types/quaternion_floating.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ end
3434
@propagate_inbounds function set_rotation!(q::AbstractVector, jt::QuaternionFloating, rot::Rotation{3})
3535
T = eltype(rot)
3636
quat = convert(QuatRotation{T}, rot)
37-
q[1] = quat.q.s
38-
q[2] = quat.q.v1
39-
q[3] = quat.q.v2
40-
q[4] = quat.q.v3
37+
w, x, y, z = Rotations.params(quat)
38+
q[1] = w
39+
q[2] = x
40+
q[3] = y
41+
q[4] = z
4142
nothing
4243
end
4344

src/joint_types/quaternion_spherical.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@ end
3030
@propagate_inbounds function set_rotation!(q::AbstractVector, jt::QuaternionSpherical, rot::Rotation{3})
3131
T = eltype(rot)
3232
quat = convert(QuatRotation{T}, rot)
33-
q[1] = quat.q.s
34-
q[2] = quat.q.v1
35-
q[3] = quat.q.v2
36-
q[4] = quat.q.v3
33+
w, x, y, z = Rotations.params(quat)
34+
q[1] = w
35+
q[2] = x
36+
q[3] = y
37+
q[4] = z
3738
nothing
3839
end
3940

src/spatial/util.jl

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,12 @@ function spquat_derivative end
125125
function angular_velocity_in_body end
126126

127127
@inline function velocity_jacobian(::typeof(quaternion_derivative), q::QuatRotation)
128+
w, x, y, z = Rotations.params(q)
128129
(@SMatrix [
129-
-q.q.v1 -q.q.v2 -q.q.v3;
130-
q.q.s -q.q.v3 q.q.v2;
131-
q.q.v3 q.q.s -q.q.v1;
132-
-q.q.v2 q.q.v1 q.q.s ]) / 2
130+
-x -y -z;
131+
w -z y;
132+
z w -x;
133+
-y x w ]) / 2
133134
end
134135

135136
@inline function velocity_jacobian(::typeof(spquat_derivative), q::ModifiedRodriguesParam)
@@ -140,10 +141,11 @@ end
140141
end
141142

142143
@inline function velocity_jacobian(::typeof(angular_velocity_in_body), q::QuatRotation)
144+
w, x, y, z = Rotations.params(q)
143145
2 * @SMatrix [
144-
-q.q.v1 q.q.s q.q.v3 -q.q.v2;
145-
-q.q.v2 -q.q.v3 q.q.s q.q.v1;
146-
-q.q.v3 q.q.v2 -q.q.v1 q.q.s ]
146+
-x w z -y;
147+
-y -z w x;
148+
-z y -x w ]
147149
end
148150

149151
@inline function velocity_jacobian(::typeof(angular_velocity_in_body), q::ModifiedRodriguesParam)

src/util.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ end
4444
## VectorSegment: type of a view of a vector
4545
const VectorSegment{T} = SubArray{T,1,Array{T, 1},Tuple{UnitRange{Int64}},true} # TODO: a bit too specific
4646

47-
quatnorm(quat::QuatRotation) = sqrt(quat.q.s^2 + quat.q.v1^2 + quat.q.v2^2 + quat.q.v3^2)
47+
function quatnorm(quat::QuatRotation)
48+
w, x, y, z = Rotations.params(quat)
49+
sqrt(w^2 + x^2 + y^2 + z^2)
50+
end
4851

4952

5053
## Modification count stuff

test/test_mechanism_algorithms.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -905,8 +905,9 @@ end
905905
elseif joint_type_k isa QuaternionFloating || joint_type_k isa QuaternionSpherical
906906
rot_orig = rotation(joint_type_k, q_orig)
907907
rot_prin = rotation(joint_type_k, q_prin)
908+
w, x, y, z = Rotations.params(rot_prin)
908909
@test isapprox(rot_orig, rot_prin)
909-
@test rot_prin.q.s > 0
910+
@test w > 0
910911
else
911912
@test q_orig == q_prin
912913
end

0 commit comments

Comments
 (0)