Skip to content

Commit 0f42d29

Browse files
authored
Merge pull request #618 from JuliaRobotics/tk/fix-rotation-vector-rate-eps
Fix numerical epsilon check in rotation_vector_rate.
2 parents c86bc6e + fea0081 commit 0f42d29

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

src/spatial/util.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,11 @@ function rotation_vector_rate(rotation_vector::AbstractVector{T}, angular_veloci
9191
ω = angular_velocity_in_body
9292
@boundscheck length(ϕ) == 3 || error("ϕ has wrong length")
9393
@boundscheck length(ω) == 3 || error("ω has wrong length")
94+
ϕ̇ = ω +× ω) / 2
9495
θ = norm(ϕ)
95-
ϕ̇ = ω
96-
if θ > eps(θ)
96+
if θ > eps(typeof(θ))
9797
s, c = sincos(θ)
98-
ϕ̇ += × ω) / 2 + 1 / θ^2 * (1 -* s) / (2 * (1 - c))) * ϕ ×× ω)
98+
ϕ̇ += 1 / θ^2 * (1 -* s) / (2 * (1 - c))) * ϕ ×× ω)
9999
end
100100
ϕ̇
101101
end

test/test_simulate.jl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,4 +225,28 @@
225225
energy20 = gravitational_potential_energy(state) + kinetic_energy(state)
226226
@test energy20 energy15 atol=1e-5 # stabilization doesn't significantly affect energy after converging
227227
end
228+
229+
@testset "Ball joint pendulum" begin
230+
# Issue #617
231+
translation = [0.3, 0, 0]
232+
233+
world = RigidBody{Float64}("world")
234+
pendulum = Mechanism(world; gravity=[0., 0., -9.81])
235+
236+
center_of_mass = [0, 0, 0.2]
237+
q0 = [cos(pi/8), sin(pi/8), 0.0, 0.0]
238+
239+
joint1 = Joint("joint1", QuaternionSpherical{Float64}())
240+
inertia1 = SpatialInertia(frame_after(joint1), com=center_of_mass, moment_about_com=diagm([1.,1.,1.]), mass=1.)
241+
link1 = RigidBody("link1", inertia1)
242+
before_joint1_to_world = Transform3D(frame_before(joint1), default_frame(world), one(RotMatrix{3}), SVector{3}(translation))
243+
attach!(pendulum, world, link1, joint1, joint_pose=before_joint1_to_world)
244+
245+
state = MechanismState(pendulum)
246+
247+
set_configuration!(state, joint1, q0)
248+
ts, qs, vs = simulate(state, 1., Δt=0.001)
249+
@test all(all(!isnan, q) for q in qs)
250+
@test all(all(!isnan, v) for v in vs)
251+
end
228252
end

0 commit comments

Comments
 (0)