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.
Should these approaches give the same results? Does the body kinematics analysis alter the kinematics in any way?
Thanks for your help!
Ty
Center of Mass Trajectory using API vs. GUI
- Tylan Templin
- Posts: 40
- Joined: Mon Jan 15, 2018 10:55 am
- Ayman Habib
- Posts: 2252
- Joined: Fri Apr 01, 2005 12:24 pm
Re: Center of Mass Trajectory using API vs. GUI
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
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
- Tylan Templin
- Posts: 40
- Joined: Mon Jan 15, 2018 10:55 am
Re: Center of Mass Trajectory using API vs. GUI
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
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
- Tylan Templin
- Posts: 40
- Joined: Mon Jan 15, 2018 10:55 am
Re: Center of Mass Trajectory using API vs. GUI
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
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