How to assign setMaxIsometricForce in Matlab API

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
RoZi A
Posts: 13
Joined: Sat Feb 06, 2016 10:04 pm

How to assign setMaxIsometricForce in Matlab API

Post by RoZi A » Mon Aug 06, 2018 7:51 pm

Hi All,

I am trying to assign Activation,maxIsometricForce, optimalFiberLength, tendonSlackLength and pennationAngle for each muscles of arm26.osim within Matlab. Below are my codes:

Code: Select all

import org.opensim.modeling.*;

%Call the model
model = Model('arm26.osim');

%Get initial state of the model
state = model.initSystem;

%Get the muscles, get the size of the muscle arrays
muscles= model.getMuscles();
nMuscles = muscles.getSize();

% Set muscle parameters
Activation         = [0.05, 0.05, 0.05, 0.05, 0.05, 0.05];
maxIsometricForce  = [798.52, 624.3, 624.3, 624.3, 435.56, 987.26];
optimalFiberLength = [0.134, 0.1134, 0.1138, 0.1157, 0.1321, 0.0858];
tendonSlackLength  = [0.134, 0.098, 0.0908, 0.2723, 0.1923, 0.0535];
pennationAngle 	   = [0.20943951, 0.15707963, 0.15707963, 0, 0, 0];

%Creating for loop to assign above values to each muscle in the model

for i = 1:nMuscles
	muscles.get(i).setActivation(state, Activation(i));
    muscles.get(i).setMaxIsometricForce(state, maxIsometricForce(i));
    muscles.get(i).setOptimalFiberLength(state, optimalFiberLength(i));
    muscles.get(i).setTendonSlackLength(state, tendonSlackLength(i));
    muscles.get(i).setPennationAngleAtOptimalFiberLength(state, pennationAngle(i));
end

The problem is that I am only able to assignActivation, and I got an error when the program reaches muscles.get(i).setMaxIsometricForce(state, maxIsometricForce(i)) line. The error is: No method 'setMaxIsometricForce' with matching signature found for class 'org.opensim.modeling.Muscle'.
I think the problem is due to 'state' input but I couldn't figure that out. I spent the whole two days but it still does not work.
Any help is appreciated.

RoZi

User avatar
Aaron Fox
Posts: 286
Joined: Sun Aug 06, 2017 10:54 pm

Re: How to assign setMaxIsometricForce in Matlab API

Post by Aaron Fox » Mon Aug 06, 2018 11:01 pm

Hi RoZi,

I've achieved this with slightly different code by editing the imported model:

model = Model('arm26.osim');

for i = 1:nmuscles
model.getMuscles.get(i).set_max_isometric_force(maxIsometricForce(i));
model.getMuscles.get(i).set_optimal_fiber_length(optimalFiberLength(i));
model.getMuscles.get(i).set_tendon_slack_length(tendonSlackLength(i));
model.getMuscles.get(i).set_pennation_angle_at_optimal(pennationAngle(i));
end

Hope that helps,

Aaron

User avatar
RoZi A
Posts: 13
Joined: Sat Feb 06, 2016 10:04 pm

Re: How to assign setMaxIsometricForce in Matlab API

Post by RoZi A » Tue Aug 07, 2018 9:07 am

Hi Aaron,

Thanks for your answer. Your codes work perfectly when I type them in Command window, one by one, but when I run the whole for loop, I got below error. Do you have any idea? ( my current folder is bin when I run the codes).

Java exception occurred:
java.lang.RuntimeException: ArrayPtrs.get: Array index out of bounds.

at org.opensim.modeling.opensimModelJNI.SetMuscles_get__SWIG_0(Native Method)

at org.opensim.modeling.SetMuscles.get(SetMuscles.java:145)


Thanks again,
RoZi

User avatar
Nicos Haralabidis
Posts: 194
Joined: Tue Aug 16, 2016 1:46 am

Re: How to assign setMaxIsometricForce in Matlab API

Post by Nicos Haralabidis » Tue Aug 07, 2018 10:34 am

Hello Rozi,

I think that error message occurs due to the indexing - OpenSim indexing begins at 0.

Perhaps try:

for i = 0:nmuscles-1

model.getMuscles.get(i).set_max_isometric_force(maxIsometricForce(i+1));

end

I hope that helps!

Nicos

User avatar
RoZi A
Posts: 13
Joined: Sat Feb 06, 2016 10:04 pm

Re: How to assign setMaxIsometricForce in Matlab API

Post by RoZi A » Tue Aug 07, 2018 10:50 am

Hi Nicos,

I really really appreciate it. No error anymore :)

Thanks,
RoZi

User avatar
Aaron Fox
Posts: 286
Joined: Sun Aug 06, 2017 10:54 pm

Re: How to assign setMaxIsometricForce in Matlab API

Post by Aaron Fox » Tue Aug 07, 2018 4:39 pm

Hi Nicos & RoZi,

Fair point made with regard to the indexing and something I missed with my original post. Another way around this is you can "get" the muscle by using a string with it's name instead of the index value. So if you create a list of the muscles you want to change you can pass through those strings and access the muscles that way.

Aaron

POST REPLY