What is State in Model.calcCenterMassPosition

OpenSim Moco is a software toolkit to solve optimal control problems with musculoskeletal models defined in OpenSim using the direct collocation method.
POST REPLY
User avatar
Umer Huzaifa
Posts: 10
Joined: Wed Mar 04, 2020 11:41 pm

What is State in Model.calcCenterMassPosition

Post by Umer Huzaifa » Fri Nov 12, 2021 2:44 pm

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

User avatar
Aravind Sundararajan
Posts: 17
Joined: Mon Aug 29, 2016 2:59 pm

Re: What is State in Model.calcCenterMassPosition

Post by Aravind Sundararajan » Fri Nov 12, 2021 3:30 pm

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

User avatar
Nicholas Bianco
Posts: 1041
Joined: Thu Oct 04, 2012 8:09 pm

Re: What is State in Model.calcCenterMassPosition

Post by Nicholas Bianco » Tue Nov 16, 2021 12:53 pm

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);

POST REPLY