How to set inertia in Matlab

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
shoko horibata
Posts: 20
Joined: Fri Mar 22, 2013 8:12 pm

How to set inertia in Matlab

Post by shoko horibata » Fri Jun 13, 2014 3:47 am

I try to write code to create model using Matlab.
My code is below.

Code: Select all

model = Model();
model.setName('gait2492_simbody_new')

zeroVec3 = ArrayDouble.createVec3(0);

model.setGravity(zeroVec3);

ground = model.getGroundBody();

ground.addDisplayGeometry('treadmill.vtp');

% BODY
pelvis = Body();
pelvis.setName('pelvis');
pelvis.setMass(11.777);
pelvec3 = ArrayDouble.createVec3([-0.0707 0 0]);
pelvis.setMassCenter(pelvec3);
pelinertia = Mat33(1.0,1.0,1.0,1.0,1.0,1.0,0,0,0);
pelvis.setInertia(pelinertia);
It has error at last code(pelvis.setInertia).
What's wrong is it?

And I think inertias are xx,yy,zz,xy,xz,yz in gait2392_simbody.osim.

Code: Select all

<Body name="pelvis">
					<mass>11.777</mass>
					<mass_center> -0.0707 0 0</mass_center>
					<inertia_xx>0.1028</inertia_xx>
					<inertia_yy>0.0871</inertia_yy>
					<inertia_zz>0.0579</inertia_zz>
					<inertia_xy>0</inertia_xy>
					<inertia_xz>0</inertia_xz>
					<inertia_yz>0</inertia_yz>
How do I write the code?

User avatar
jimmy d
Posts: 1375
Joined: Thu Oct 04, 2007 11:51 pm

Re: How to set inertia in Matlab

Post by jimmy d » Fri Jun 13, 2014 10:42 am

Hi Shoko,

The setinertia() method takes an arrayDouble rather than a Mat33().

Here is a link to a thread that had the same issue (though using python); https://simtk.org/forums/viewtopic.php? ... rtia#p8553

Let us know how it goes,
-james
Last edited by jimmy d on Sat Jun 14, 2014 9:07 am, edited 1 time in total.

User avatar
shoko horibata
Posts: 20
Joined: Fri Mar 22, 2013 8:12 pm

Re: How to set inertia in Matlab

Post by shoko horibata » Sat Jun 14, 2014 8:56 am

Hi james,

Thank you for reply.
In reference to the link, I can set inertia.

Solution is below:

Code: Select all

pelinertia = ArrayDouble(1.0, 6);
pelinertia.set(0,0.1028);
pelinertia.set(1,0.0871);
pelinertia.set(2,0.0579);
pelinertia.set(3,0.0);
pelinertia.set(4,0.0);
pelinertia.set(5,0.0);
pelvis.setInertia(pelinertia);
Another problem I have.
To create customjoint, I think I need to set coordinate.
But [setCoordinateName] have error.
I try to define coordinate out of transformAxis.
it still have error.

Code: Select all

 pelvisSpatialTransform = SpatialTransform();
 pelvisSpatialTransform.getTransformAxis(0).setName('rotation1');
 pelvisSpatialTransform.getTransformAxis(1).setName('rotation2');
 pelvisSpatialTransform.getTransformAxis(2).setName('rotation3');
 pelvisSpatialTransform.getTransformAxis(3).setName('translation1');
 pelvisSpatialTransform.getTransformAxis(4).setName('translation2');
 pelvisSpatialTransform.getTransformAxis(5).setName('translation3');
 pelvisSpatialTransform.getTransformAxis(0).setAxis(z_Vec3);
 pelvisSpatialTransform.getTransformAxis(1).setAxis(x_Vec3);
 pelvisSpatialTransform.getTransformAxis(2).setAxis(y_Vec3);
 pelvisSpatialTransform.getTransformAxis(3).setAxis(x_Vec3);
 pelvisSpatialTransform.getTransformAxis(4).setAxis(y_Vec3);
 pelvisSpatialTransform.getTransformAxis(5).setAxis(z_Vec3);

pelvisSpatialTransform.getTransformAxis(0).setCoordinateName('pelvis_tilt');

ground_pelvis  = CustomJoint('gruond_pelvis', ground, zeroVec3, zeroVec3, pelvis, zeroVec3, zeroVec3, pelvisSpatialTransform, false);


POST REPLY