Page 1 of 1

MATLAB ForwardTool() with new initial conditions

Posted: Fri Jun 06, 2014 11:11 pm
by masters08
I am currently using the OpenSim-MATLAB interface to run an optimization routine. Some of the parameters that I am optimizing are the initial conditions of each body. Currently, I am writing a handle to the coordinate set and changing the position and velocity by the following example commands:

Code: Select all

   system = osimModel.initSystem() ; 
    Pelvis_tx = osimModel.updCoordinateSet().get('Pelvis_tx')     ;
    Pelvis_tx.setValue(system, pelvis_position_new)                         ;
    Pelvis_tx.setSpeedValue(system, pelvis_velocity_new)    
After I change the initial conditions for each body, I run the forward tool by the following commands:

Code: Select all

    tool = ForwardTool() ; 
    tool.setModel(osimModel) ; 
    tool.setStartTime(0) ; 
    tool.setFinalTime(5) ;
    tool.setName('test_opt2') ; 
    tool.run() ;


But whenever I view the new motion files, the initial conditions are set to the default pose (as described in the .xml file that contains the entire model).

Any ideas on how to create a handle to the initial conditions such that the forward tool does not revert to the default initial pose?

I am also optimizing the mass distribution of each segment, but that does not seem to give me any problems.

Regards!
Sam

Re: MATLAB ForwardTool() with new initial conditions

Posted: Sat Jun 07, 2014 8:45 am
by masters08
Solution:

setDefaultValue instead of setValue
setDefaultSpeedValue instead of setSpeedValue

-Samuel Masters

Re: MATLAB ForwardTool() with new initial conditions

Posted: Tue Jun 10, 2014 9:57 am
by aymanh
Hi Samuel,

The ForwardTool internally calls initSystem() on the model to handle cases where the forces acting on the model change for the purposes of the tool run (e.g. ExternalForces), so to communicate initial conditions you can either change defaults (which are used for initialization) as you did or specify an initialStatesFile.

Best regards.
-Ayman