Page 1 of 1

Matlab API - 'model.setStateVariableValue()' unable to find coordinate name

Posted: Thu Dec 06, 2018 5:46 pm
by mobius_ww
I found 'model.setStateVariable()' was updated to 'model.setStateVariableValue()' in OpenSim API 4.0. However, I had the following error when trying to use 'model.setStateVariableValue()', while same setup worked for previous version 'model.setStateVariable()'. I am wondering if the newer version has some modificatoin to the model coordinate name?

Code: Select all

Java exception occurred:
java.lang.RuntimeException: Component::setStateVariable: ERR- state named 'pelvis_tx' not found in Visual3d of type Model.


	at org.opensim.modeling.opensimCommonJNI.Component_setStateVariableValue(Native Method)

	at org.opensim.modeling.Component.setStateVariableValue(Component.java:214)
	
Thank you!

Re: Matlab API - 'model.setStateVariableValue()' unable to find coordinate name

Posted: Thu Dec 06, 2018 6:13 pm
by chrisdembia
Use getStateVariableNames() to see the new names of state variables. It'll be something like `/jointset/pelvis_ground/pelvis_tx/value`.

Re: Matlab API - 'model.setStateVariableValue()' unable to find coordinate name

Posted: Sun Dec 09, 2018 4:35 pm
by mobius_ww
chrisdembia wrote:
Thu Dec 06, 2018 6:13 pm
Use getStateVariableNames() to see the new names of state variables. It'll be something like `/jointset/pelvis_ground/pelvis_tx/value`.
Thank you for your reply. However, the return of the getStateVariableNames() is something like, 'org.opensim.modeling.ArrayStr@5bbc9f97', which also did not work.

Alternatively, I used 'my_coor_set.get('pelvis_tx').setValue(myState, 0.0)', but Matlab crashed (sreenshot attached)...

Re: Matlab API - 'model.setStateVariableValue()' unable to find coordinate name

Posted: Sun Dec 09, 2018 8:29 pm
by tkuchida
However, the return of the getStateVariableNames() is something like, 'org.opensim.modeling.ArrayStr@5bbc9f97', which also did not work.
You can print each element of the array:

Code: Select all

svn = model.getStateVariableNames();
for i = 1:svn.getSize()
    svn.get(i-1)
end

Re: Matlab API - 'model.setStateVariableValue()' unable to find coordinate name

Posted: Tue Dec 18, 2018 10:43 pm
by mobius_ww
Thank you Thomas!

In addtion to my previous post on Matlab crash, I found that it was caused by 'InverseDynamicsTool.run()'. It seems after 'InverseDynamicsTool.run()', calling any OpeSim API (e.g. 'model.setStateVariableValue()', 'model.equilibrateMuscles(state)', etc) would result in a Matlab crash...