Page 1 of 1

how can i set initial states in forward dynamics-MatLab API

Posted: Mon May 27, 2013 10:02 pm
by porsasina
Hi All
I want to set the initial states (joint angles and velocities) to specific values and use forward dynamics to integrate the equations of motion forward in time.
I am using MatLab API. here is my script:

Code: Select all

system = osimModel.initSystem();
modelCoordinateSet = osimModel.updCoordinateSet();
modelCoordinateSet.get(aCoor).setValue(system,aValue);
tool = ForwardTool();
tool.setModel(osimModel);
tool.setStartTime(0);
tool.setFinalTime(finalTime);
tool.run(); 
When I look at the results, all of the joint angles and velocities have an initial value of zero. Any idea how can I solve this problem?
Thanks,
Sina

Re: how can i set initial states in forward dynamics-MatLab

Posted: Tue May 28, 2013 2:13 pm
by aymanh
Hi Sina,

The method

Code: Select all

ForwardTool.run() 
ends up calling initSystem again, to add Forces to the model in case these were specified in the setup file, and that wipes out your initial states. You can work around this by calling

Code: Select all

model.setPropertiesFromState(goodInitialState)
and pass in the state you initialized before calling tool.setModel.

It would generally be helpful (though not needed) if you name the variable returned by the call to initSystem "state" instead of "system" because that's closer to the the actual type of object.

Hope this helps,
-Ayman