Define the initial muscle states for FD (API)

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Sina Porsa
Posts: 99
Joined: Thu Feb 03, 2011 7:21 pm

Define the initial muscle states for FD (API)

Post by Sina Porsa » Sun Jun 03, 2012 10:35 pm

Hi all;
I am trying to load an existing osim file to perform a forward dynamic. But I cannot initiate the muscle states (activation and fiber length). The model has 2 Thelen muscles.
Here is my code:

Code: Select all

/////////////////////////
// Load the Osim model //
/////////////////////////
Model osimModel ("twoMuscles_model.osim");

////////////////////////////
// Initialize the muscle states //
///////////////////////////
const Set<Actuator>& actuatorSet = osimModel.getActuators();
Muscle* muscle1 = dynamic_cast<Muscle*>( &actuatorSet.get(0) );
Muscle* muscle2 = dynamic_cast<Muscle*>( &actuatorSet.get(1) );
muscle1->setDefaultActivation(0.9); // muscle1 activation
muscle1->setDefaultFiberLength(0.1); // muscle1 fiber length
muscle2->setDefaultActivation(0.8); // muscle2 activation
muscle2->setDefaultFiberLength(0.1); // muscle2 fiber length
When I want to compile this code, it returns this error:
error C2039: 'setDefaultFiberLength' : is not a member of 'OpenSim::Muscle'

This code is based on the "OpenSim Developer's Guide" pages 57 and 58
It would be great if you could help me,
Thanks
Sina

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

Re: Define the initial muscle states for FD (API)

Post by Ayman Habib » Mon Jun 04, 2012 3:42 pm

Hi Sina,

The method you're referrng to is not in the base OpenSim::Muscle class but is in the subclass OpenSim::ActivationFiberLengthMuscle (as there could be muscle models out there that do not have a FiberLength state) so you should use something similar to the code snippet below...

Code: Select all

ActivationFiberLengthMuscle* muscle2 = dynamic_cast<ActivationFiberLengthMuscle*>( &actuatorSet.get(0) );
muscle1->setDefaultActivation(0.9); // muscle1 activation
Hope this helps,
-Ayman

User avatar
Sina Porsa
Posts: 99
Joined: Thu Feb 03, 2011 7:21 pm

Re: Define the initial muscle states for FD (API)

Post by Sina Porsa » Mon Jun 04, 2012 6:49 pm

Hi Ayman

Thanks for your help. I have another strange problem. I changed my code to this:

Code: Select all

		const Set<Actuator>& actuatorSet = osimModel.getActuators();
		ActivationFiberLengthMuscle* muscle1 = dynamic_cast<ActivationFiberLengthMuscle*>( &actuatorSet.get(0) );
		ActivationFiberLengthMuscle* muscle2 = dynamic_cast<ActivationFiberLengthMuscle*>( &actuatorSet.get(1) );
		muscle1->setDefaultActivation(0.9); // muscle1 activation
		muscle1->setDefaultFiberLength(0.2); // muscle1 fiber length
		muscle2->setDefaultActivation(0.8); // muscle2 activation
		muscle2->setDefaultFiberLength(0.1); // muscle2 fiber length
		std::cout << "default activations: " << muscle1->getDefaultActivation() << "  " << muscle2->getDefaultActivation() << std::endl;
		std::cout << "default fiber lenghts: " << muscle1->getDefaultFiberLength() << "  " << muscle2->getDefaultFiberLength() << std::endl;
The last two lines print the prescribed values of the initial muscle lengths and activations. But when I plot the results using GUI, the initial values does not match the prescribed values. I have attached the plots.

I was wondering maybe the "default activation and fiber length" defer from the "initial activation and fiber length". Am I right?

Thanks
Sina.
Attachments
delete.jpg

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

Re: Define the initial muscle states for FD (API)

Post by Ayman Habib » Tue Jun 05, 2012 12:29 pm

Hi Sina,

I'm not sure what tool are you using but as of version 2.4 you have one of two ways to initialize muscle states:
1. Reading in a consistent set of states (for example as computed by a simulation)
2. setting the flag to "compute equilibrium" which would take whatever states/default values you have and would numerically solve for consistent values of muscle states using your input as an initial guess.

I suspect you're accidentally invoking the second path above and that messes up your initialization.

Hope this helps,
-Ayman

User avatar
Sina Porsa
Posts: 99
Joined: Thu Feb 03, 2011 7:21 pm

Re: Define the initial muscle states for FD (API)

Post by Sina Porsa » Tue Jun 05, 2012 6:17 pm

Hi Ayman and thanks for your help.
I just found out the problem, I was initializing the muscle states after initializing the system.
Thanks for your helps.
Your last post popped a new question into my mind. What is the difference between these two:


void Model::equilibrateMuscles
void Model::computeEquilibriumForAuxiliaryStates

Cheers,
Sina

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

Re: Define the initial muscle states for FD (API)

Post by Ayman Habib » Wed Jun 06, 2012 9:56 am

Hi Sina,

Glad you got to the bottom of this. The two methods below are identical and the latter (Model::computeEquilibriumForAuxiliaryStates) has been removed and will not be available in the next release to avoid confusion.

Thanks for reporting and please let us know if you have more questions,
-Ayman

POST REPLY