Page 1 of 1

What is State in Model.calcCenterMassPosition

Posted: Fri Nov 12, 2021 2:44 pm
by umerhuzaifa
Hi there,

I am trying to tracking center of mass position for a model. However, I am unable to find what goes inside the function model.calcCenterMassPosition() as argument. All I have found on Doxygen is that it accepts const SimTK::State & s. I have Moco solved state trajectories of size 102x2. I have tried passing in one of the rows to it but to no avail. Kindly guide.

Umer

Re: What is State in Model.calcCenterMassPosition

Posted: Fri Nov 12, 2021 3:30 pm
by aravind
if you are trying to do some post-hoc analysis with your moco solution in matlab or python, I think you can turn this into a StatesTrajectory and use get(index) to grab states from it

Code: Select all

states_storage = org.opensim.modeling.Storage(storagePath);
states_trajectory = org.opensim.modeling.StatesTrajectory().createFromStatesStorage(model, states_storage,true,true,false);
and you can get iterate over states in the states trajectory and realizing the model to positions or whatever else you need. There might be an easier way though

Re: What is State in Model.calcCenterMassPosition

Posted: Tue Nov 16, 2021 12:53 pm
by nbianco
Thanks for the response Aravind. I can provide a little more context if it's useful.

OpenSim has two main concepts regarding modeling and simulation: the Model and the State. The Model is the mathematical description of your system, but alone it cannot provide any information about your model at a given time point in a simulation. For that you need a State (i.e., SimTK::State), which is essentially a vector of numerical values that define the kinematics and kinetics of your system at a given time point.

When you solve a problem in Moco, you get back a trajectory of values, which is essentially a bunch of concatenated States. You can easily return a StatesTrajectory object from a MocoTrajectory:

Code: Select all

study = MocoStudy();
problem = study.updProblem();
% Your problem and solver settings here.
solution = study.solve();
statesTrajectory = solution.exportToStatesTrajectory(problem);