setInertia Values In Python Script

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
User avatar
Brad Humphreys
Posts: 79
Joined: Thu Feb 03, 2011 11:32 am

setInertia Values In Python Script

Post by Brad Humphreys » Tue Dec 04, 2012 11:07 am

I am attempting to set the inertia tensor of a body in a Python Script. I can tell from the docs that I need to use a Mat33 for SimTK. Not sure how to do this though.

For example, to set the center of mass I just use:

cmVec = modeling.ArrayDouble.createVec3(1, 2, 3)
block.setMassCenter(cmVec)

What do I use for setInertia?

User avatar
Ayman Habib
Posts: 2235
Joined: Fri Apr 01, 2005 12:24 pm

Re: setInertia Values In Python Script

Post by Ayman Habib » Tue Dec 04, 2012 3:54 pm

Hi Brad,

SimTK namespace classes are not exposed to scripting, instead we have utility methods that take modeling.ArrayDouble and converts them to SimTK::Inertia. E.g.

Code: Select all

pelvis = m.getBodySet().get('pelvis')
unitInertia = modeling.ArrayDouble(1.0, 6)
pelvis.setInertia(unitInertia)
A similar getInertia() method exists.

Hope this helps,
-Ayman

User avatar
Brad Humphreys
Posts: 79
Joined: Thu Feb 03, 2011 11:32 am

Re: setInertia Values In Python Script

Post by Brad Humphreys » Tue Dec 04, 2012 7:09 pm

Ayman,

Thanks much for the quick reply. Your code works, but it sets all of the inertia terms (the entire tensor) to the value of 1.0 (not physically practical). How do you set each of the values?

I tried your code but with:
unitInertia = modeling.ArrayDouble([10.0,10.0,10.0,0,0,0],1) #A typical/practical Inertia

I get an error that the first argument must be a double.

Thanks,

Brad

User avatar
Yannik Schröder
Posts: 14
Joined: Wed Apr 18, 2012 11:40 am

Re: setInertia Values In Python Script

Post by Yannik Schröder » Wed Dec 05, 2012 4:40 am

There is probably an easier way to do it, but you could try to first create the ArrayDouble and then edit the values of the array via the set(index, value) method (e.g. unitInertia.set(3, 0.0)).

Regards,
Yannik

User avatar
Brad Humphreys
Posts: 79
Joined: Thu Feb 03, 2011 11:32 am

Re: setInertia Values In Python Script

Post by Brad Humphreys » Wed Dec 05, 2012 12:03 pm

Yannik, Ayman,

That works beautifully! So the code becomes:

Code: Select all

pelvis = m.getBodySet().get('pelvis')
unitInertia = modeling.ArrayDouble(1.0, 6)
unitInertia.set(0,10.0)  
unitInertia.set(1,10.0)
.....
pelvis.setInertia(unitInertia)
Thanks!

User avatar
Brad Humphreys
Posts: 79
Joined: Thu Feb 03, 2011 11:32 am

Re: setInertia Values In Python Script

Post by Brad Humphreys » Fri Dec 07, 2012 3:02 pm

On a related note, I understand that Inertia are with respect to the center of mass. But is the directionality (xx, yy, zz. xy, etc.) of the tensor with respect to the global space coordinate system of the model?

As I don't see a means to define a body coordinate system, I believe this is the only means to provide directionality for the inertia tensor. I did look through the forum and the location question is answered (the body CM) but not the direction.

Thanks!

Brad

User avatar
Michael Sherman
Posts: 800
Joined: Fri Apr 01, 2005 6:05 pm

Re: setInertia Values In Python Script

Post by Michael Sherman » Mon Dec 10, 2012 11:53 am

Hi, Brad.

The inertia matrix is defined in the local frame of the body. The reason there is no way to specify a body's local frame is that the local frame defines the body. Every body begins as just an unadorned body frame B. Then you add geometry and mass properties in that frame. Later the multibody system positions the frame B with respect to inertial space, taking the geometry and mass properties along with it.

Regards,
Sherm

User avatar
Brad Humphreys
Posts: 79
Joined: Thu Feb 03, 2011 11:32 am

Re: setInertia Values In Python Script

Post by Brad Humphreys » Tue Dec 11, 2012 7:06 am

Sherm,

Thanks for the response. Just to clarify a bit more. I am building the bodies "from scratch" using python scripting. When the unadorned B frame is placed, it would be aligned to the inertial space coordinate system, correct? So when I set the inertia values they end up initially aligned to the global inertial frame. Your point is then later as constraints/joints/motions drive the body positions, this frame of course changes. Am I interpreting that correct?

Regards,

Brad

User avatar
Michael Sherman
Posts: 800
Joined: Fri Apr 01, 2005 6:05 pm

Re: setInertia Values In Python Script

Post by Michael Sherman » Tue Dec 11, 2012 9:53 am

No, you're thinking too hard about this Brad! A body frame doesn't have a placement in space until you have built a set of generalized coordinates for the multibody system containing it. The inertia properties you specify are simply aligned with the body frame -- there is no need to talk about the placement of the body in space at that point. You can read more about this in the Simbody theory manual, chapter 2 if you want: https://simtk.org/docman/view.php/47/23 ... Manual.pdf.

Most likely you are thinking about bodies whose motion is parameterized in Cartesian space, and then restricted by constraints to form joints, like in ADAMS for example. OpenSim is an internal coordinate code -- the generalized coordinates that define the joints are the coordinate system; there is no underlying Cartesian system.

Regards,
Sherm

User avatar
Brad Humphreys
Posts: 79
Joined: Thu Feb 03, 2011 11:32 am

Re: setInertia Values In Python Script

Post by Brad Humphreys » Tue Dec 11, 2012 10:38 am

Sherm,

Thanks - the light bulb just finally lit. And this is for importing our ADAMS models into OpenSim. What is interesting, is even with the completely different "build-up" methodologies of OpenSim and Adams and my lack of understanding that till now, the models import nicely and I have it working for all of the base joint types in OpenSim. I was just concerned with the inertia values, but I may have to go back and think of model topology issues that could possibly be caused by the differences here.

Thanks,

Brad

POST REPLY