Skip to content

Commit

Permalink
Fix center_of_mass allocations.
Browse files Browse the repository at this point in the history
  • Loading branch information
tkoolen committed Aug 2, 2018
1 parent 9cd427a commit 4fa9e51
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/mechanism_algorithms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ function center_of_mass(state::MechanismState, itr)
com = Point3D(frame, zero(SVector{3, T}))
mass = zero(T)
for body in itr
inertia = spatial_inertia(body)
if inertia.mass > 0
bodycom = transform_to_root(state, body, false) * center_of_mass(inertia)
com += inertia.mass * FreeVector3D(bodycom)
mass += inertia.mass
if body.inertia !== nothing
inertia = spatial_inertia(body)
if inertia.mass > 0
bodycom = transform_to_root(state, body, false) * center_of_mass(inertia)
com += inertia.mass * FreeVector3D(bodycom)
mass += inertia.mass
end
end
end
com /= mass
Expand All @@ -51,7 +53,7 @@ $(SIGNATURES)
Compute the center of mass of the whole `Mechanism` in the given state.
"""
center_of_mass(state::MechanismState) = center_of_mass(state, non_root_bodies(state.mechanism))
center_of_mass(state::MechanismState) = center_of_mass(state, bodies(state.mechanism))

const geometric_jacobian_doc = """Compute a geometric Jacobian (also known as a
basic, or spatial Jacobian) associated with a directed path in the `Mechanism`'s
Expand Down

0 comments on commit 4fa9e51

Please sign in to comment.