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
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
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í