Acceleration of center of mass

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Gil Serrancolí
Posts: 9
Joined: Thu Mar 17, 2011 1:37 am

Acceleration of center of mass

Post by Gil Serrancolí » Wed Sep 23, 2015 12:46 am

Hi,

I am trying to calculate the mass acceleration of the total multibody system from the API in Matlab. I have the states stored in a .sto file. So, the code I was using is the following:

Code: Select all

model=Model('myModel.osim');
statesStorage=Storage('states_Storage.sto');
state=model.initSystem();
for i=0:(statesStorage.getSize-1)
    statei=statesStorage.getStateVector(i);
    state.setY(statei.getData.getAsVector)
    state.setTime(statei.getTime);
    
    valuesVec3=model.calcMassCenterAcceleration(state);
    CoMacc(i+1,1)=valuesVec3.get(0);
    CoMacc(i+1,2)=valuesVec3.get(1);
    CoMacc(i+1,3)=valuesVec3.get(2);
end
However, the acceleration that I got is just the gravity. I tried to run model.computeStateVariableDerivatives(states) before calculating the mass center acceleration, but I obtain the same. Should I calculate the accelerations of each body first? or does the function calcMassCenterAcceleration need to compute something else previously?

Then, I was also trying to compute the mass center acceleration of each body, with the following code:

Code: Select all

massCenter = Vec3(0.0,0.0,0.0);
acceleration = Vec3(0.0,0.0,0.0);
state=model.initSystem();
for i=0:(statesStorage.getSize-1)
    statei=statesStorage.getStateVector(i);
    state.setY(statei.getData.getAsVector)
    state.setTime(statei.getTime);
    Bodies=model.getBodySet();
    for j=0:(Bodies.getSize-1);
        Bodies.get(j).getMassCenter(massCenter);
        simbodyEngine=model.getSimbodyEngine();
        simbodyEngine.getAcceleration(state,Bodies.get(j),massCenter,acceleration);
        CoMAcc(i+1,1,j+1)=acceleration.get(0);
        CoMAcc(i+1,2,j+1)=acceleration.get(1);
        CoMAcc(i+1,3,j+1)=acceleration.get(2);
    end
end
However, I got the following error when computing the acceleration:
Java exception occurred:
java.lang.RuntimeException: SimTK Exception thrown at State.cpp:2069:
Expected stage to be at least Position in StateImpl::getCacheEntry() but current stage was Instance

Do you know what I am missing?

Thank you very much,

Gil Serrancolí

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

Re: Acceleration of center of mass

Post by jimmy d » Wed Oct 14, 2015 4:02 pm

Hi Gil,

looks like you need to realize the system to accelerations. Try adding this;

Code: Select all

model.computeStateVariableDerivatives(s)
Under the hood, the call will realize the system through to accelerations.

Let me know if that works,
-J

User avatar
Gil Serrancolí
Posts: 9
Joined: Thu Mar 17, 2011 1:37 am

Re: Acceleration of center of mass

Post by Gil Serrancolí » Fri Oct 16, 2015 6:24 am

Thanks James for the answer.

However, I tried it and it does not seem to work. I still obtain an acceleration equal to gravity.

I just added the line to compute state derivatives after setting the states.

Code: Select all

model=Model('myModel.osim');
statesStorage=Storage('states_Storage.sto');
state=model.initSystem();
for i=0:(statesStorage.getSize-1)
    statei=statesStorage.getStateVector(i);
    state.setY(statei.getData.getAsVector)
    state.setTime(statei.getTime);
    model.computeStateVariableDerivatives(state);

    valuesVec3=model.calcMassCenterAcceleration(state);
    CoMacc(i+1,1)=valuesVec3.get(0);
    CoMacc(i+1,2)=valuesVec3.get(1);
    CoMacc(i+1,3)=valuesVec3.get(2);
end
Does anyone know if it is possible to run the function model.calcMassCenterAcceleration(state) in Matlab? Am I missing something when setting the states?

Thank you very much,

Gil

User avatar
Robert Huffman
Posts: 3
Joined: Thu Jul 09, 2015 11:07 am

Re: Acceleration of center of mass

Post by Robert Huffman » Tue Jan 26, 2016 2:13 pm

I'm not sure I saw a resolution to this problem in this chain, but I am having the same issue in an analysis plugin. I tried adding the call to computeStateVariableDerivatives(s), but it didn't make any difference. I am actually working on an on orbit exercise simulation for NASA, so I have set my gravity accel to 0,0,0 in the model.

_model->computeStateVariableDerivatives(s);
totMass = _model->getTotalMass(s);
sysCgPos = _model->calcMassCenterPosition(s);
sysCgVel = _model->calcMassCenterVelocity(s);
sysCgAcc = _model->calcMassCenterAcceleration(s);
// sysCgAcc = (sysCgVel - sysCgVelLast) / dt;
sysCgVelLast = sysCgVel;

Anyway, sysCgAcc as coded, contains very small, essentially zero numbers, while if I do a finite difference calc (commented) based on the velocity call, I get something fairly reasonable. I've run through this in the debugger, and put in some prints (below), and it is calculating non-zero accels for each body, but the sum of the body accels * mass cancel each other out.

Vec3 SimbodyMatterSubsystem::calcSystemMassCenterAccelerationInGround(const State& s) const {
Real mass = 0;
Vec3 coma = Vec3(0);

for (MobilizedBodyIndex b(1); b < getNumBodies(); ++b) {
const MassProperties& MB_OB_B = getMobilizedBody(b).getBodyMassProperties(s);
const Vec3 a_G_CB = getMobilizedBody(b).findStationAccelerationInGround(s, MB_OB_B.getMassCenter());
const Real mb = MB_OB_B.getMass();

mass += mb;
coma += mb * a_G_CB; // weighted by mass

cout << b << " coma = " << coma << " " << mb * a_G_CB << " mass = " << mb << endl;
}

if (coma[1] > .1 || coma[1] < -.1)
cout << coma << endl;

if (mass != 0)
coma /= mass;

return coma;
}

Thanks,
Ken

User avatar
Namrata Kaundal
Posts: 9
Joined: Fri Mar 18, 2016 4:03 am

Re: Acceleration of center of mass

Post by Namrata Kaundal » Fri Mar 18, 2016 5:56 am

For some reason, the more I try to think about this problem, the more confused I seem to become :(. I hate to ask this, but might you be willing to give me a step-by-step explanation of how to solve it?
I don't know if they have any significance (or if they are even correct), but here are some values I've come up with so far:
x1 = -0.5, y1 = 0
x2 = 0, y2 = -0.1
xcom,sys = (m1x1 + m2x2)/(M) = -0.3
ycom,sys = (m1y1 + m2y2)/(M) = -0.04
and a couple of the equations I've been trying to work with:
Fnet = Macom
Macom = m1a1 + m2a2

User avatar
Matteo Lancini
Posts: 1
Joined: Mon Feb 11, 2013 5:11 am

Re: Acceleration of center of mass

Post by Matteo Lancini » Tue Jan 17, 2017 4:48 am

I have a similar problem using the OpenSim IDE. Whenever I try to compute the center of mass accelerations I get only gravity, while differentiating all the markers I get a result compatible with the movements of my subjects.
It seems that the inverse kinematics tools sets the center of mass to a constant velocity movement. Is that a bug or am I forgetting an option?

thanks
matteo

POST REPLY