Muscle activation in Forward dynamics (API)

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Stefano Piazza
Posts: 4
Joined: Sun Sep 13, 2009 2:54 pm

Muscle activation in Forward dynamics (API)

Post by Stefano Piazza » Wed Jul 20, 2011 5:43 am

Hi all,
I want to perform a FD simulation using Opensim API.
Activation data and model properties are ok since I can perform the FD from the GUI, but I'm failing in doing the same with APIs.
I'm trying to import the .sto file with

Storage myStorage("excitation_control.sto");

and getting a segmentation fault.
Is this the correct procedure to import the controls.sto data?




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

RE: Muscle activation in Forward dynamics (API)

Post by Ayman Habib » Wed Jul 20, 2011 9:20 am

Hi Stefano,

I'm not sure about your context/use-case but if you want to build a ControlSet, there's a ControlSet constructor that takes a Storage as input, so you can do something like:

Storage myStorage("excitation_control.sto");
ControlSet cs(myStorage);

Hope this helps,
-Ayman

User avatar
Stefano Piazza
Posts: 4
Joined: Sun Sep 13, 2009 2:54 pm

RE: Muscle activation in Forward dynamics (API)

Post by Stefano Piazza » Thu Jul 21, 2011 4:34 am

Thank you Ayman, indeed it did help.

I wonder if there is a similar function for the initialization of system's states from file as well.

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

RE: Muscle activation in Forward dynamics (API)

Post by Ayman Habib » Tue Jul 26, 2011 11:25 am

Hi Stefano,

There's no method to set initial states directly from a file, however you should be able once you have a state object to populate it using the code snippet:

SimTK::Vector configuration;
.... // Code to populate configuration
state.updY() = configuration;

This however is risky and highly not recommended unless you know exactly the layout of the state object/vector. Instead, a more robust way to set the state is to set members of the state vector using higher order methods, for example:
Cooridnate.setValue(state, newValue) .. etc.

Please let me know if that answers your question.

Best regards,
-Ayman

User avatar
Stefano Piazza
Posts: 4
Joined: Sun Sep 13, 2009 2:54 pm

RE: Muscle activation in Forward dynamics (API)

Post by Stefano Piazza » Thu Jul 28, 2011 2:29 am

Dear Ayman,
thank you for the feedback. I resolved the issue by doing:

// obtain the complete generalized coordinates (q's) and generalized speeds (u's) from file
osimModel.getSimbodyEngine().formCompleteStorages(si, siFile, completeQs, completeUs);

// get the descriptor of the state in the initial instant
OpenSim::Array<double> aQInitial;
OpenSim::Array<double> aUInitial;
(..)
// get the values of state variable in the first instant of the simulation
completeQs->getDataAtTime(INITIAL_TIME, aQInitial.getSize(), aQInitial);
completeUs->getDataAtTime(INITIAL_TIME, aUInitial.getSize(), aUInitial);

// transform to vector
SimTK::Vector vQInitial(aQInitial.getSize(), &aQInitial[0]);
SimTK::Vector vUInitial(aUInitial.getSize(), &aUInitial[0]);

// set initial state
initialState.setQ(vQInitial);
initialState.setU(vUInitial);

// realize the state
osimModel.getSystem().realize(initialState, Stage::Acceleration);

After that I call equilibrateMuscles.
Since I am in a dynamic state (during walking), with the presence of accelerations and muscle activities, is it correct to do the call now, since equilibrateMuscles will take into accout all these contributes?
Or is it better to make it before, while the system is in a default quiet condition, and just then realize to this state?

Thank you.
Stefano

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

RE: Muscle activation in Forward dynamics (API)

Post by Ayman Habib » Fri Jul 29, 2011 1:32 pm

Hi Stefano,

EquilibriateMuscles doesn't depend on the "dynamic/inertial" properties of the multibody system, so either place would be fine (as long as you're not doing it during an integration loop as it can interfere with the state variables being integrated.

Hope this helps,
-Ayman

POST REPLY