Calculate the Center of Gravity of a PHX

Questions about Marilou Open Devices Access (MODA)
Post Reply
trussi
Posts: 3
Joined: Fri Jan 20, 2012 6:57 pm

Calculate the Center of Gravity of a PHX

Post by trussi » Mon Jan 23, 2012 8:00 am

I have a complex structure with multiple Geoms and Joints in a PHX file. I'd like to calculate the position of the center of gravity for entire component at any given position in space (XYZ).

Is this possible?

Thanks,
Travis

LR
Posts: 305
Joined: Mon Feb 12, 2007 11:55 pm
Location: FR

Re: Calculate the Center of Gravity of a PHX

Post by LR » Mon Jan 23, 2012 9:18 am

Hi travis,

Well, it is not possible directly.

If you are using 'auto' rigid bodies, the inertia matrix is computed automatically, per body. So, the body position is exactly the inertia matrix position. But, today, it is not possible to retrieve the entire matrix ...

If you are interested in retrieve the body's inertia matrix values, please say me : i will add this feature in TODO list.

Because you are using joint, you will have to combine inertia matrix of each connected bodies in order to get the total matrix.
LR

trussi
Posts: 3
Joined: Fri Jan 20, 2012 6:57 pm

Re: Calculate the Center of Gravity of a PHX

Post by trussi » Mon Jan 23, 2012 8:20 pm

LR,

Thanks for the quick reply and building an awesome modeling product!

To confirm, if I have two Geoms that each weight 1kg and the position of Geom1 is -1, 0, 0 and the position of Geom2 is 1, 0, 0, then the center of gravity would be 0, 0, 0. Is that correct?

Any simulation involving balance requires a calculation of the center of gravity of any moving part (i.e. an arm or leg) and usually those parts are made up of multiple geoms. So, I think it would be a very helpful feature to be able to calculate the center of gravity for a group of Geoms.

BTW, where can I find your roadmap for the product and the list of all future enhancements? I'd like to see what features to expect.

Thanks again!

trussi
Posts: 3
Joined: Fri Jan 20, 2012 6:57 pm

Re: Calculate the Center of Gravity of a PHX

Post by trussi » Tue Jan 24, 2012 5:53 am

The calculation of the COG of multiple objects looks pretty straight-forward (http://www.wikihow.com/Calculate-Center-of-Gravity).

However, I could not find in the documentation where to programmatically get the mass of a Geom. I see were to set it in the editor, but not in the MODA namespace.

What function can I use to get the mass of a Geom?

LR
Posts: 305
Joined: Mon Feb 12, 2007 11:55 pm
Location: FR

Re: Calculate the Center of Gravity of a PHX

Post by LR » Tue Jan 24, 2012 10:08 am

hi,
To confirm, if I have two Geoms that each weight 1kg and the position of Geom1 is -1, 0, 0 and the position of Geom2 is 1, 0, 0, then the center of gravity would be 0, 0, 0. Is that correct?
Yes it is correct. The inertia position should be 0,0,0, the other values are computer according to geometry type. The inertia matrix is not the same if there is a box at -1,0,0 and a big sphere at 1,0,0 or if you have 2 boxes.
So, I think it would be a very helpful feature to be able to calculate the center of gravity for a group of Geoms.
It is the case ! the inertia matrix of a body is computed according to its geometries type, mass, length. Today you cannot retrieve it by using MODA but this matrix is available in the simulator. So it is not complex for us to maque this matrix 'readable' from MODA.
BTW, where can I find your roadmap for the product and the list of all future enhancements? I'd like to see what features to expect.
Well, i add today the "ModaCPP::GeomBody::GetInertiaMatrix()" in TODO list. I thing it will be available for the end of the week (in beta download, i will contact you when ready).

Is it ok for you ?
LR

adminforum
Site Admin
Posts: 95
Joined: Wed Feb 07, 2007 11:10 am
Location: Montpellier - FR

Re: Calculate the Center of Gravity of a PHX

Post by adminforum » Wed Jan 25, 2012 2:06 pm

Hi,

Can you please send an email to support at anykode dot com about this topic.

LR will send-back a link to download the update (within the next 2 days) . Please say in this email if you are using Marilou X86 or X64.

The update allows to get the Inertia values of a specified rigid body: Mass, Kinematic mode, Center offset/Body position, Tensor values.

Thanks

Martin
Posts: 25
Joined: Tue Mar 19, 2013 11:41 pm

Re: Calculate the Center of Gravity of a PHX

Post by Martin » Fri Aug 02, 2013 7:11 pm

Hi!

I 'm trying to calculate the CG of a complex body too.
Well, i add today the "ModaCPP::GeomBody::GetInertiaMatrix()" in TODO list. I thing it will be available for the end of the week (in beta download, i will contact you when ready).
Is ModaCPP::GeomBody::GetInertiaMatrix() available now and what kind of data it retrives?
The update allows to get the Inertia values of a specified rigid body: Mass, Kinematic mode, Center offset/Body position, Tensor values.
How i can use this function to retrieve the mass or the centre offset for example?.

Thanks,
Martin.

LR
Posts: 305
Joined: Mon Feb 12, 2007 11:55 pm
Location: FR

Re: Calculate the Center of Gravity of a PHX

Post by LR » Sat Aug 03, 2013 7:21 pm

Hi,

You have a sample in the documentation: http://doc.anykode.com/ModaCPP__GeomBod ... tia__.html

The inertia Matrix par of the returned structure is computed by ODE: it is an accumulation of body's geoms inertia type and masses (see ODE doc for more details).

Cheers
LR

Martin
Posts: 25
Joined: Tue Mar 19, 2013 11:41 pm

Re: Calculate the Center of Gravity of a PHX

Post by Martin » Wed Aug 07, 2013 11:53 pm

Hi! thanks for reply.

I have some questions about the values it retrieves. I will take an example to explain myself better. i have a Sphere of 50 kg , radius 5 m and positioned at :
0,0 ; 5,0; 0,0 and Inerty type: Auto.

The fuction retrives Centre, the position of the Centre of Mass of a geometry , in the example the CM must be in 0,0;5,0;0;0 however it retrives 0;0; 0,0; 0,0 and this is not true...what kind of reference Moda takes for calculate the CM? Between wich points is it calculated? I try to change the geometry trying a box but the Centre is still : 0;0; 0,0; 0,0 no matter its mass or geometry its always the same.

I really don't understand the meaning of the inetertia matrix , the fuction retrives 3 vectors in this case :
0,036 ; 0,0; 0,0
0,0 ; 0,036; 0,0
0,0 ; 0,0; 0,036

What mean this values ?


Other question is: How to calculate the CM of a complex body wich rigid bodies has more than one geometry and are conected by joints? I have read that LR said.
Because you are using joint, you will have to combine inertia matrix of each connected bodies in order to get the total matrix.
How can do this?


Sorry for this so much extended reply, i hope someone could help me, I will be glad .

Thanks,

Martin. :)

LR
Posts: 305
Joined: Mon Feb 12, 2007 11:55 pm
Location: FR

Re: Calculate the Center of Gravity of a PHX

Post by LR » Fri Aug 09, 2013 10:47 am

Hi,

The CM you retrieves is relative to the parent of the geometry: its rigid body. When the RB is in auto mode, the sphere is centered on the RB. So your CM is (0,0,0). If you combine several geoms, the center will probably not be (0,0,0).
I really don't understand the meaning of the inetertia matrix , the fuction retrives 3 vectors in this case :
0,036 ; 0,0; 0,0
0,0 ; 0,036; 0,0
0,0 ; 0,0; 0,036

What mean this values ?
You should refer to ODE documentation, mass.cpp file. For exemple for the sphere:

Code: Select all

void dMassSetSphere (dMass *m, dReal density, dReal radius)
{
  dMassSetSphereTotal (m, (dReal) ((REAL(4.0)/REAL(3.0)) * M_PI *
			  radius*radius*radius * density), radius);
}


void dMassSetSphereTotal (dMass *m, dReal total_mass, dReal radius)
{
  dAASSERT (m);
  dMassSetZero (m);
  m->mass = total_mass;
  dReal II = REAL(0.4) * total_mass * radius*radius;
  m->_I(0,0) = II;
  m->_I(1,1) = II;
  m->_I(2,2) = II;
}
Other question is: How to calculate the CM of a complex body wich rigid bodies has more than one geometry and are conected by joints? I have read that LR said.
CM of a joints connected bodies is a complex stuff ... you should retrieve CM of each body and combine them according to joints orientation / angle. Take a look at ODE functions dMassAdd, dMassTranslate and dMassRotate : we are using those functions to create 'auto' bodies CM.
LR

Martin
Posts: 25
Joined: Tue Mar 19, 2013 11:41 pm

Re: Calculate the Center of Gravity of a PHX

Post by Martin » Mon Oct 28, 2013 1:53 pm

Hi !

Thanks for the replay, i really don't understand how i can make a reference beteween the origin of World, it being (0;0;0), and the CM of my rigid bodie ( complex or not). For example, i have a humanoide with joints. I added the CM of every part in order to calculate the CM of the whole body. However, this function retrieves the same vector (x;y;z) wherever humanoide's position is. How can i refer this CM to the origin of the world? and Is this value real?.

The ecuation i used was:

Summation of (M*P) = m1*p1 + m2*p2 + ... + mn*pn

Final position in X is: XF=( m1*p1 + m2*p2 + ... + mn*pn)/M
Final position in Y is: =
Final position in Z is: =

In my code is (with less part to make it easier):

M= (float)((InertiaValues1.Mass)+(InertiaValues2.Mass)+(InertiaValues3.Mass));

XF =((InertiaValues1.InertiaMatrix[1].x)+(InertiaValues2.InertiaMatrix[1].x)+(InertiaValues3.InertiaMatrix[1].x)) /M;
YF= ((InertiaValues1.InertiaMatrix[2].y)+(InertiaValues2.InertiaMatrix[2].y)+(InertiaValues3.InertiaMatrix[2].y)) /M;
ZF= ((InertiaValues1.InertiaMatrix[3].z)+(InertiaValues2.InertiaMatrix[3].z)+(InertiaValues3.InertiaMatrix[3].z)) /M;

Note: i have use the method "Inertia Matrix" believing that it returns a matrix of three vectors which has 3 float positions each one, one of this vectors is supposed to retrive the CM. How ever, i really don´t know what that vectors refers to so i added them aleatory (the position which has a value, for example: the inertia matrix of the sphere). In this case, the first component of the first vector for X , then the second component of the second vector for Y and the same for Z. I did so because the method "Centre" always retrieves (0;0;0) no matter the body position or it's compositions of geometries.

Thanks,

Martin. :)

LR
Posts: 305
Joined: Mon Feb 12, 2007 11:55 pm
Location: FR

Re: Calculate the Center of Gravity of a PHX

Post by LR » Mon Oct 28, 2013 5:20 pm

How can i refer this CM to the origin of the world?
The inertia matrix is not a position/orientation matrix. As explained before, this is the components of the inertia:
- the offset from the body's world position = (0,0,0) if your CM is located exactly at the body's absolute position
- the 3*3 components of the inertia matrix

Your body location in the world can be retrieved by GetMatrixAbsolute.
i really don´t know what that vectors refers to so i added them aleatory
Read the post here before :) The inertia is depending of the geometry(ies) types/masses/and offsets

Code: Select all

You should refer to ODE documentation, mass.cpp file. For exemple for the sphere:

Code: Select all
    void dMassSetSphere (dMass *m, dReal density, dReal radius)
    {
      dMassSetSphereTotal (m, (dReal) ((REAL(4.0)/REAL(3.0)) * M_PI *
               radius*radius*radius * density), radius);
    }


    void dMassSetSphereTotal (dMass *m, dReal total_mass, dReal radius)
    {
      dAASSERT (m);
      dMassSetZero (m);
      m->mass = total_mass;
      dReal II = REAL(0.4) * total_mass * radius*radius;
      m->_I(0,0) = II;
      m->_I(1,1) = II;
      m->_I(2,2) = II;
    }
LR

Post Reply