Page 1 of 1

Center of Mass velocity

Posted: Fri Jan 20, 2023 1:11 pm
by s.fleischmann
Hello,

i have a .trc file that stores the results of an Inverse Kinematics Analysis.
In Matlab, I load this file as a StatesTrajectory. Then, for every state, I assemble my model to match this state. I then want to extract the position and velocity of the assebled state. This works well for the center of mass position, but not for the center of mass velocity.
I do it like this:
state = model.initSystem()
current_state = traj.get(i); (where traj is the state trajectory)
model.assemble(current_state);
model.realizePosition(current_state);
com = model.calcMassCenterPosition(current_state)
model.realizeVelocity(current_state);
current_state.setSystemTopologyStageVersion(7);
comdot = model.calcMassCenterVelocity(current_state);

Nevertheless, for comdot I only get NaNs.

What do I do wrong?
I really appreciate your help!!

Thanks and best regards,
Sophie

Re: Center of Mass velocity

Posted: Mon Jan 23, 2023 11:57 am
by nbianco
Hi Sophie,

Do you have any locked coordinates in your model? There's a known bug where COM values get returned as NaN when locked coordinates exist in the model.

You also might consider using 'SimulationUtilities::analyze<T>()', which might work better than manually assembling the model for your trajectory.

Matlab example:

Code: Select all

model.initSystem();
statesTable = traj.exportToTable(model);
% create an empty controls table (not needed for velocity-level info)
controlsTable = TimeSeriesTable(statesTable.getIndependentColumn());

outputPaths = StdVectorString();
outputPaths.add('/com_position');
outputPaths.add('/com_velocity');

com = opensimSimulation.analyzeVec3(model, statesTable, controlsTable, outputPaths);