model "snap shot" of a single state via API

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Marc Carmichael
Posts: 45
Joined: Thu Jul 16, 2009 2:50 am

model "snap shot" of a single state via API

Post by Marc Carmichael » Sun Feb 27, 2011 10:37 pm

Hello everyone. For anyone who has read my threads before you may have noticed I typically use opensim via the API for what may be considered "unintended uses". Because of this I often have off topic questions, and I apologize because here is another one :)


I wish to take a single "snap shot" of a model's parameters in a defined state. I wish to set the generalized coordinate angles, velocities, muscle activations, and maybe (not essential) joint accelerations.

Once put into this state, I then wish to calculate...
* musculotendon lengths and velocities
* muscle fibre lengths and velocities
* musculotendon tensions
* muscle moment arms
* Kinematic Jacobian
* Mass matrix

To date I have been pretty successful, but I keep finding small inconsistencies in the results which makes me think the method I am using the API is not correct.

A typical example is when I set the joint angles/velocities to set values, and slowly increase the muscle activations while viewing the corresponding muscle tensions. I would expect the tensions to increase linearly with activation, however at some activations the tensions drop to zero. I also find that this behaviour changes when I ramp the activations slower or faster, or start from a different value.

I suspect this is because the way I am doing it makes a new state instance every time, and the new state depends on the previous to some extent? Here are my basic steps:

1 - create model and initialize the system/state
2 - I set coordinate values using OpenSim::Coordinate::setValue();
3 - I set coordinate speeds using OpenSim::Coordinate::setSpeedValue();
4 - I set muscle activation using OpenSim::Muscle:setActivation();
5 - I run osimModel.getSimbodyEngine().projectConfigurationToSatisfyConstraints(si,0.01);
6 - I run osimModel.getSystem().realize(si,SimTK::Stage::Velocity);
7 - I run osimModel.computeEquilibriumForAuxiliaryStates(si);

I then go ahead and get the information I need, for example I use getLength() to get musculotendon length. Is there a step I am missing or performing in the wrong order which could mess up the calculation?

Could it be the function I am using for muscle tension? I am happy to assume muscle equilibrium (fibre velocity = musculotendon velocity) so I was using computeIsokineticForceAssumingInfinitelyStiffTendon(), but if I use getForce() the inconsistent results go away (but I am unsure if it is in equilibrium). Maybe I need to manually equilibriate the muscle before hand?

Sorry again for the novel I just posed :) Any help is greatly appreciated.

Also, on a side note would it be a good idea to start a new forum section on API related questions only? I am sure the majority of OpenSim users operate via the GUI only and are not interested in reading these long winded API questions ;)

Cheers

Marc

User avatar
Ayman Habib
Posts: 2238
Joined: Fri Apr 01, 2005 12:24 pm

RE: model "snap shot" of a single state via API

Post by Ayman Habib » Thu Mar 03, 2011 11:15 am

Hi Marc,

I agree that we should separate the API issues/discussion from the Application's and we're working on revamping the forums so I hope this will happen soon.

Basically, an OpenSim model is backed by a const SimTK::System and a SimTK::State. The state is all what you want to capture. The state contains all attributes of interest in the model (including which forces or constraints are enabled/disabled, mass, inertia, qs, etc.).

For the purpose of this discussion, the important parts of the state would be the q's (cooridnates), u's (speeds), and z's (muscle states). Most our muscle models have two states: Fiber_length and Activation.

You can get these values and print them from the state object by calling state.getQ(), getU(), getZ() respectively, then you'll see what call is not doing what you expect or causing undesirable side effects.

Good luck and please let us know if you have any questions,
-Ayman

POST REPLY