Hello Mr. Uchida,
You're quite correct. I was able to reproduce GUI results in MATLAB.
As a note to future users, there are 2 possible ways to reproduce using an OpenSim tool in MATLAB after setting default values of/locking coordinates (and neither involve using an initialStates.sto or .mot file in the associated setup .xml). As per obtaining a list of methods for the org.opensim.modeling.Model object (type 'methods org.opensim.modeling.Model;' in the MATLAB command window after configuring OpenSim-MATLAB use and other installations), it seems the Model object has certain methods such as model.getConstraintSet(), but with no API I didn't know what parameters each method expected, and I wasn't able to effectively use MATLAB to set default values of or lock coordinates, if possible in the first place.
However, you may set default values of/lock coordinates in MATLAB through editing the model file .osim (see the first block of code), instantiating an OpenSim model in MATLAB, performing any other necessary actions before running the tool (such as adding an analysis or setup files), and running the tool (see the second block of code).
In the .osim,
change the default_value as necessary; be sure to set the coordinate in radians if editing a rotational coordinate.
change <clamped>false</clamped> to true (at least, that's what I did; I see no reason to have a <range> if the coordinate's values may leave the range (that is, the coordinate's values aren't <clamped>)).
change <locked>false</locked> to true if the joint would be locked if you're using the GUI. (Locked joints cannot change their value, and the simulation typically adjusts other model values to compensate.)
Code: Select all
<Coordinate name="deviation">
<!--Coordinate can describe rotational, translational, or coupled motion. Defaults to rotational.-->
<motion_type>rotational</motion_type>
<!--The value of this coordinate before any value has been set. Rotational coordinate value is in radians and Translational in meters.-->
<default_value>0.1857030324</default_value>
<!--The speed value of this coordinate before any value has been set. Rotational coordinate value is in rad/s and Translational in m/s.-->
<default_speed_value>0</default_speed_value>
<!--The minimum and maximum values that the coordinate can range between. Rotational coordinate range in radians and Translational in meters.-->
<range>-0.17453293 0.43633231</range>
<!--Flag indicating whether or not the values of the coordinates should be limited to the range, above.-->
<clamped>true</clamped>
<!--Flag indicating whether or not the values of the coordinates should be constrained to the current (e.g. default) value, above.-->
<locked>false</locked>
<!--If specified, the coordinate can be prescribed by a function of time. It can be any OpenSim Function with valid second order derivatives.-->
<prescribed_function />
<!--Flag indicating whether or not the values of the coordinates should be prescribed according to the function above. It is ignored if the no prescribed function is specified.-->
<prescribed>false</prescribed>
</Coordinate>
In MATLAB,
Code: Select all
import org.opensim.modeling.*
model = Model('modelFile.osim');
ft = ForwardTool('forwardDynamicsSetup.xml');
ft.setModel(model);
ft.run();
I hope the post helps,
Stephanie Hachem