Skip to content

Commit

Permalink
Compute center of mass using spatial algebra.
Browse files Browse the repository at this point in the history
  * Previous computation scheme was not wrong.
  * Compute each body spatial inertia in world frame.
  * Compute sum of all inertias to retrieve center of mass position.
  • Loading branch information
Antonio El Khoury committed Oct 1, 2012
1 parent 69b18e4 commit adce9e0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/private/DynMultiBodyPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ namespace dynamicsJRLJapan
matrix3d SkewCoM;

/** Weighted CoM position. */
Spatial::Inertia sIa;
vector3d positionCoMPondere;
vector3d ldv_c_g;
/** Splitted inertial matrices. */
Expand Down
13 changes: 11 additions & 2 deletions src/private/DynamicMultiBodyNewtonEuler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ void DynMultiBodyPrivate::NewtonEulerAlgorithm(MAL_S3_VECTOR(&PosForRoot,double)
positionCoMPondere[0] = 0;
positionCoMPondere[1] = 0;
positionCoMPondere[2] = 0;
matrix3d I;
I.setZero ();
vector3d h (0,0,0);
sIa = Spatial::Inertia (I, h, 0);
MAL_S3_VECTOR_FILL(ldv_c_g,0);


Expand Down Expand Up @@ -125,7 +129,12 @@ void DynMultiBodyPrivate::NewtonEulerAlgorithm(MAL_S3_VECTOR(&PosForRoot,double)
if (m_ComputeCoM)
{
currentJoint->updateWorldCoMPosition();
positionCoMPondere += currentBody->w_c * currentBody->getMass();
// Use spatial algebra to first compute total spatial
// inertia, then retrieve com from it.
Spatial::PluckerTransform sXi0;
sXi0.inverse (currentBody->sX0i);
Spatial::Inertia sIai0 = sXi0 * currentBody->sIa;
sIa = sIa + sIai0;
}

/* Update the momentum. */
Expand Down Expand Up @@ -253,8 +262,8 @@ void DynMultiBodyPrivate::NewtonEulerAlgorithm(MAL_S3_VECTOR(&PosForRoot,double)
SkewCoM(2,2) = 0;
}

positionCoMPondere = positionCoMPondere/m_mass;
ldv_c_g = ldv_c_g / m_mass;
positionCoMPondere = sIa.h() / m_mass;

ODEBUG4INC(ldv_c_g , "AccelerationCoM.dat", " ");
ODEBUG4INC(" " , "AccelerationCoM.dat", endl);
Expand Down

0 comments on commit adce9e0

Please sign in to comment.