Page 1 of 1

Center of Mass Trajectory using API vs. GUI

Posted: Thu Jul 01, 2021 2:50 pm
by tnt845
Hi everyone,

I would like to measure the trajectory of the vertical component of the center of mass for a .mot file. I have tried to do this in two ways:
1) Updating the coordinates of the model in the API for each timepoint followed by the commands:
model.assemble(state)
com_pos = model.calcMassCenterPosition(state)
v_com = com_pos[1]

2) Doing a body kinematics analysis using the analysis tool in the GUI with the same model and same .mot file.

However, I am getting different results using these two methods as seen in the graph.
vertical_COM_trajectories.PNG
vertical_COM_trajectories.PNG (16.54 KiB) Viewed 461 times
Should these approaches give the same results? Does the body kinematics analysis alter the kinematics in any way?

Thanks for your help!

Ty

Re: Center of Mass Trajectory using API vs. GUI

Posted: Fri Jul 02, 2021 10:36 am
by aymanh
Hi Tylan,

BodyKinematics analysis does not modify the model or the motion, so it appears the call sequence you're using is different from that used by the GUI. The likely culprit is an issue with mapping the values from the motion (.mot file) to states. We go the extra mile to make sure no assumptions are made about the size or ordering of entries of the state vector and account for missing entries in mot files as well as internal states etc. We have utility classes that can help simplify this mapping, so hopefully you can leverage them and get the same answers (e.g. StatesTrajectory https://simtk.org/api_docs/opensim/api_ ... ctory.html)

Hope this helps,
-Ayman

Re: Center of Mass Trajectory using API vs. GUI

Posted: Tue Jul 06, 2021 9:31 am
by tnt845
Hi Ayman,

Thank you for your response! I was able to map the .mot file to a States Trajectory. However, it seems from the API documentation that the individual states in the StatesTrajectory cannot be modified.

My overall goal is to ensure the center of mass of the model obeys the laws of projectile motion (gravity being the only force acting on the model during this flight phase of the motion).

My initial approach was to make small modifications the .mot file (generated by inverse kinematics) such that the center of mass followed the desired trajectory. Do you have any suggestions for how to accomplish this goal using a StatesTrajectory? Or is there a better approach?

Thanks!

Ty

Re: Center of Mass Trajectory using API vs. GUI

Posted: Tue Jul 06, 2021 9:59 am
by tnt845
I am currently updating the state using the following function in python:

def update_state(model,state,coord_dict):
for key in coord_dict.keys():
if key!='time':
q = coord_dict[key]
model.updCoordinateSet().get(key).setValue(state,q, False)

return state

Where coord_dict is a dictionary of degrees of freedom in the model and their updated values.
Please let me know if there is a better way to do this!

Ty