Edit muscle excitations using MATLAB

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
William A
Posts: 21
Joined: Thu Feb 16, 2017 10:02 am

Edit muscle excitations using MATLAB

Post by William A » Thu Feb 23, 2017 9:55 am

Dear all,

How to edit or change muscle excitations in MATLAB and then use it for forward dynamics simulation?

Thanks.

User avatar
jimmy d
Posts: 1375
Joined: Thu Oct 04, 2007 11:51 pm

Re: Edit muscle excitations using MATLAB

Post by jimmy d » Thu Feb 23, 2017 12:00 pm

Hi, William-

I assume you are using OpenSim 3.3?

If so, you will have to edit the controls file that the Forward Tool uses to set the actuator controls.

Code: Select all

import org.opensim.modeling.*

% read the controls file into memory
cset = ControlSet('ResultsCMC/subject01_walk1_controls.xml')

% get the number of controls
sz = cset.getSize()

for i = 0 : sz - 1
	    
    csi = cset.get(0)
    % safedowncast to the concrete classs — ControlLinear in this case
    csiL = ControlLinear.safeDownCast(csi)
	    
    controlName = csi.getName()
    % Get the control value at time 0
    csiL.getControlValue(0.0)
    % Set the control value at time 0
    csiL.setControlValue(0.0, 0.9)
    
 end
the doxygen documenation for ControlLinear is here;
https://simtk.org/api_docs/opensim/api_ ... c45beb6534

User avatar
William A
Posts: 21
Joined: Thu Feb 16, 2017 10:02 am

Re: Edit muscle excitations using MATLAB

Post by William A » Thu Feb 23, 2017 11:15 pm

Thanks James!

Using this code i am able to edit control values but how can I save these new values to a new control(.xml) file ? Because forward tool takes excitations through control files. Or is there any other way to give controls to forward tool through MATLAB?

User avatar
jimmy d
Posts: 1375
Joined: Thu Oct 04, 2007 11:51 pm

Re: Edit muscle excitations using MATLAB

Post by jimmy d » Fri Feb 24, 2017 12:01 am

Once you have made your edits, then you print the ControlSet back to file. In this case, your last line of code would be something like;

Code: Select all

% Write edited controls to file
cset.print('ResultsCMC/subject01_walk1_controls_EDITED.xml')

POST REPLY