Skip to content

Commit cc76a96

Browse files
committed
Cleanup
1 parent eefa372 commit cc76a96

File tree

7 files changed

+27
-40
lines changed

7 files changed

+27
-40
lines changed

examples/system_identification/methods/utils.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ function initial_state_box(;
176176
x = xlims[1] + rand(3) .* (xlims[2] - xlims[1])
177177
v = vlims[1] + rand(3) .* (vlims[2] - vlims[1])
178178
ω = ωlims[1] + rand(3) .* (ωlims[2] - ωlims[1])
179-
return Dict(:x => x, :v => v , :q => rand(Quaternion), => ω)
179+
return Dict(:x => x, :v => v , :q => rand(QuatRotation).q, => ω)
180180
end
181181

182182
function build_pairs(mechanism::Mechanism, trajs::AbstractVector)

src/Dojo.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ using StaticArrays
99
using SparseArrays
1010
using StaticArrays: SUnitRange
1111
using Rotations
12-
# using Rotations: RotationError, params, lmult, rmult, tmat, vmat, hmat, skew, pure_quaternion
1312
using Quaternions
1413
using Parameters
1514
using Statistics

src/orientation/quaternion.jl

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,6 @@
1-
# Quaternion(w::T, v::StaticVector{3,T}, normalize::Bool = true) where T = Quaternion{T}(w, v[1], v[2], v[3], normalize)
2-
# Quaternion(w::T, v::Vector{T}, normalize::Bool = true) where T = (@assert length(v)==3; Quaternion{T}(w, v[1], v[2], v[3], normalize))
3-
# Quaternion(v::StaticVector{3,T}) where T = pure_quaternion(v)
4-
# Quaternion(v::Vector) = (@assert length(v)==3; pure_quaternion(v))
5-
6-
# imag(q::Quaternion) = vector(q)
7-
8-
# Remove once added to Rotations.jl
9-
# function Base.:/(q::Quaternion, w::Real)
10-
# return Quaternion(q.s/w, q.v1/w, q.v2/w, q.v3/w, false)
11-
# end
12-
13-
MeshCat.LinearMap(q::Quaternion) = MeshCat.LinearMap(QuatRotation(q))
14-
MeshCat.js_quaternion(q::Quaternion) = [q.v1, q.v2, q.v3, q.s]
15-
16-
quateltype(x) = eltype(x)
1+
quateltype(x) = eltype(x) # TODO not super elegant
172
quateltype(::Quaternion{T}) where T = T
183

19-
Base.rand(::Type{Quaternion}) = Quaternion(rand(QuatRotation))
20-
214
Quaternion(q::Rotation) = Quaternion(QuatRotation(q))
225

236
vector(q::Quaternion) = SA[q.s, q.v1, q.v2, q.v3]
@@ -230,4 +213,9 @@ end
230213

231214
function ∂skew∂p(λ) # 𝞉(skew(p)*λ)/∂p
232215
skew(-λ)
233-
end
216+
end
217+
218+
219+
# MeshCat fixes
220+
MeshCat.LinearMap(q::Quaternion) = MeshCat.LinearMap(QuatRotation(q))
221+
MeshCat.js_quaternion(q::Quaternion) = [q.v1, q.v2, q.v3, q.s]

test/impulse_map.jl

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
mech = Dojo.get_mechanism(:pendulum)
66
joint0 = mech.joints[1]
77
rot0 = joint0.rotational
8-
rot0.axis_offset = rand(Quaternion)
8+
rot0.axis_offset = rand(QuatRotation).q
99

1010

1111
xa = rand(3)
12-
qa = rand(Quaternion)
12+
qa = rand(QuatRotation).q
1313
xb = rand(3)
14-
qb = rand(Quaternion)
14+
qb = rand(QuatRotation).q
1515

1616
# displacement_jacobian_configuration
1717
X0, Q0 = Dojo.displacement_jacobian_configuration(:parent, rot0, xa, qa, xb, qb,
@@ -42,9 +42,9 @@ end
4242
tra0 = joint0.translational
4343

4444
xa = rand(3)
45-
qa = rand(Quaternion)
45+
qa = rand(QuatRotation).q
4646
xb = rand(3)
47-
qb = rand(Quaternion)
47+
qb = rand(QuatRotation).q
4848

4949
# displacement_jacobian_configuration
5050
X0, Q0 = Dojo.displacement_jacobian_configuration(:parent, tra0, xa, qa, xb, qb,
@@ -77,12 +77,12 @@ end
7777
mech = Dojo.get_mechanism(:pendulum)
7878
joint0 = mech.joints[1]
7979
rot0 = joint0.rotational
80-
rot0.axis_offset = rand(Quaternion)
80+
rot0.axis_offset = rand(QuatRotation).q
8181

8282
xa = rand(3)
83-
qa = rand(Quaternion)
83+
qa = rand(QuatRotation).q
8484
xb = rand(3)
85-
qb = rand(Quaternion)
85+
qb = rand(QuatRotation).q
8686

8787
p0 = rand(3)
8888
J0 = Dojo.impulse_transform_jacobian(:parent, :parent, rot0, xa, qa, xb, qb, p0)
@@ -124,9 +124,9 @@ end
124124
tra0 = joint0.translational
125125

126126
xa = rand(3)
127-
qa = rand(Quaternion)
127+
qa = rand(QuatRotation).q
128128
xb = rand(3)
129-
qb = rand(Quaternion)
129+
qb = rand(QuatRotation).q
130130

131131
p0 = rand(3)
132132
J0 = Dojo.impulse_transform_jacobian(:parent, :parent, tra0, xa, qa, xb, qb, p0)
@@ -172,9 +172,9 @@ end
172172
tra0 = joint0.translational
173173

174174
xa = rand(3)
175-
qa = rand(Quaternion)
175+
qa = rand(QuatRotation).q
176176
xb = rand(3)
177-
qb = rand(Quaternion)
177+
qb = rand(QuatRotation).q
178178
λ = rand(3)
179179
η = rand(0)
180180
Dojo.impulse_map(:parent, tra0, xa, qa, xb, qb, η)
@@ -230,13 +230,13 @@ end
230230
mech = Dojo.get_mechanism(:pendulum)
231231
joint0 = mech.joints[1]
232232
rot0 = joint0.rotational
233-
rot0.axis_offset = rand(Quaternion)
233+
rot0.axis_offset = rand(QuatRotation).q
234234

235235

236236
xa = rand(3)
237-
qa = rand(Quaternion)
237+
qa = rand(QuatRotation).q
238238
xb = rand(3)
239-
qb = rand(Quaternion)
239+
qb = rand(QuatRotation).q
240240
λ = rand(2)
241241
η = rand(0)
242242
Dojo.impulse_map(:parent, rot0, xa, qa, xb, qb, η)

test/integrator.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Random.seed!(100)
33
x0 = srand(3)
44
v0 = srand(3)
5-
q0 = rand(Quaternion)
5+
q0 = rand(QuatRotation).q
66
ϕ0 = srand(3)
77
timestep0 = 0.01
88
x1 = Dojo.next_position(x0, v0, timestep0)

test/minimal.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ joint_types = [
3535

3636
x = srand(1)
3737
Δx = Dojo.zerodimstaticadjoint(Dojo.nullspace_mask(tra2)) * x
38-
Δq = rand(Quaternion)
38+
Δq = rand(QuatRotation).q
3939
Dojo.set_maximal_configurations!(pbody, cbody;
4040
parent_vertex=tra2.vertices[1],
4141
child_vertex=tra2.vertices[2],
@@ -223,7 +223,7 @@ end
223223

224224
timestep = mech.timestep
225225
for joint in mech.joints
226-
joint.rotational.axis_offset = rand(Quaternion)
226+
joint.rotational.axis_offset = rand(QuatRotation).q
227227
end
228228
joint0 = mech.joints[1]
229229
tra0 = joint0.translational

test/mrp.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@testset "Modified Rodrigues Parameters" begin
2-
q = rand(Quaternion)
2+
q = rand(QuatRotation).q
33
@test norm(Dojo.dmrpdq(Dojo.vector(q)) -
44
FiniteDiff.finite_difference_jacobian(Dojo.mrp, Dojo.vector(q)), Inf) < 1.0e-5
55
@test norm(Dojo.daxisdq(Dojo.vector(q)) -

0 commit comments

Comments
 (0)