MATLAB ForwardTool() with new initial conditions

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Samuel Masters
Posts: 3
Joined: Wed Mar 26, 2014 3:47 pm

MATLAB ForwardTool() with new initial conditions

Post by Samuel Masters » Fri Jun 06, 2014 11:11 pm

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

User avatar
Samuel Masters
Posts: 3
Joined: Wed Mar 26, 2014 3:47 pm

Re: MATLAB ForwardTool() with new initial conditions

Post by Samuel Masters » Sat Jun 07, 2014 8:45 am

Solution:

setDefaultValue instead of setValue
setDefaultSpeedValue instead of setSpeedValue

-Samuel Masters

User avatar
Ayman Habib
Posts: 2254
Joined: Fri Apr 01, 2005 12:24 pm

Re: MATLAB ForwardTool() with new initial conditions

Post by Ayman Habib » Tue Jun 10, 2014 9:57 am

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

POST REPLY