Page 1 of 1
Edit muscle excitations using MATLAB
Posted: Thu Feb 23, 2017 9:55 am
by william_a
Dear all,
How to edit or change muscle excitations in MATLAB and then use it for forward dynamics simulation?
Thanks.
Re: Edit muscle excitations using MATLAB
Posted: Thu Feb 23, 2017 12:00 pm
by jimmy
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
Re: Edit muscle excitations using MATLAB
Posted: Thu Feb 23, 2017 11:15 pm
by william_a
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?
Re: Edit muscle excitations using MATLAB
Posted: Fri Feb 24, 2017 12:01 am
by jimmy
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')