In MATLAB, osimModel.realizeAcceleration with no effect (OpenSim 4.0)

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
User avatar
Jack Zhao
Posts: 94
Joined: Thu Jul 24, 2014 7:15 am

In MATLAB, osimModel.realizeAcceleration with no effect (OpenSim 4.0)

Post by Jack Zhao » Thu Feb 08, 2018 12:29 am

Dear All:
I'm trying to get the accelerations from a model with a StatesTrajectory object created from a .sto file through MATLAB. The sto file is generated from StatesReporter Analyze Tool in OpenSim GUI (see the attachment). The code is as below:

Code: Select all

import org.opensim.modeling.*
osimModel = Model('subject01_scaled.osim');
osimModel.initSystem();

StatSto = Storage('s01_scaled_StatesReporter_states.sto');
states = StatesTrajectory.createFromStatesStorage(osimModel,StatSto);
nStats = states.getSize();
for n=0:nStats-1
  s = states.get(n);
  osimModel.realizeAcceleration(s);
                                         
  s.getUDot()                               %%%Output the accelerations  
end
While the results are "[nan nan nan nan nan nan nan nan nan nan nan nan nan nan..." output by MATLAB (means "values with no meaning").

It would be strongly appreciated if anyone knows the reason why the accelerations cannot be calculated(realized) !

Best regards
Jack
Attachments
s01_scaled_StatesReporter_states.zip
(21.4 KiB) Downloaded 36 times

User avatar
Dimitar Stanev
Posts: 1096
Joined: Fri Jan 31, 2014 5:14 am

Re: In MATLAB, osimModel.realizeAcceleration with no effect (OpenSim 4.0)

Post by Dimitar Stanev » Thu Feb 08, 2018 2:28 am

I think you need to update the model internal variables form the state and then to realize the model.

https://simtk.org/api_docs/opensim/api_ ... 247e3f50d3

or if you are using newer version:

Code: Select all

model.setStateVariableValues(s, stateValues)
http://myosin.sourceforge.net/1865/clas ... b146973f5e

Make sure to correspond the state variables correctly.

Best

User avatar
Christopher Dembia
Posts: 506
Joined: Fri Oct 12, 2012 4:09 pm

Re: In MATLAB, osimModel.realizeAcceleration with no effect (OpenSim 4.0)

Post by Christopher Dembia » Thu Feb 08, 2018 9:34 am

createFromStatesStorage() fills in NaNs for missing states; could that be the issue?

User avatar
Jack Zhao
Posts: 94
Joined: Thu Jul 24, 2014 7:15 am

Re: In MATLAB, osimModel.realizeAcceleration with no effect (OpenSim 4.0)

Post by Jack Zhao » Thu Feb 08, 2018 10:38 am

mitkof6 wrote: if you are using newer version:

Code: Select all

model.setStateVariableValues(s, stateValues)
http://myosin.sourceforge.net/1865/clas ... b146973f5e

Make sure to correspond the state variables correctly.

Best
Dear Dimitar:
Thanks a lot!
Do you mean that the data should be taken out from the states in the StatesTrajectory object (created from the sto file), and filled into the
corresponding states referred from the model, through SetStateVariableValues(s,statevalues) ?
If so, how to get the state (whose data are to be set) from the model? (through which function)

Best regards
Jack
Last edited by Jack Zhao on Thu Feb 08, 2018 11:17 am, edited 1 time in total.

User avatar
Jack Zhao
Posts: 94
Joined: Thu Jul 24, 2014 7:15 am

Re: In MATLAB, osimModel.realizeAcceleration with no effect (OpenSim 4.0)

Post by Jack Zhao » Thu Feb 08, 2018 10:47 am

chrisdembia wrote:createFromStatesStorage() fills in NaNs for missing states; could that be the issue?
Dear Christopher:
After the 'realizeAcceleration' is performed, the accelerations in the model states are still NaNs. It indicates distinctly that the acceleration stage is not achieved. While I checked the q and u (positions and velocities) in the model object, their values are normal, exactly from the StatesTrajectory object created from the sto file. The issue is why the acceleration stage is not realized since the function has already been performed ?

Best regards
Jack

User avatar
Christopher Dembia
Posts: 506
Joined: Fri Oct 12, 2012 4:09 pm

Re: In MATLAB, osimModel.realizeAcceleration with no effect (OpenSim 4.0)

Post by Christopher Dembia » Thu Feb 08, 2018 11:47 am

What are the accelerations before you call realizeAcceleration()? I don't think the NaNs mean the accelerations were not computed. If that were the case, you'd probably get an error message. I think what's more likely is that some quantity is actually NaN, and that's propagating to the accelerations. It's good that you checked the values of the states before realizeAcceleration(), though.

User avatar
Jack Zhao
Posts: 94
Joined: Thu Jul 24, 2014 7:15 am

Re: In MATLAB, osimModel.realizeAcceleration with no effect (OpenSim 4.0)

Post by Jack Zhao » Thu Feb 08, 2018 10:42 pm

chrisdembia wrote:What are the accelerations before you call realizeAcceleration()? I don't think the NaNs mean the accelerations were not computed. If that were the case, you'd probably get an error message. I think what's more likely is that some quantity is actually NaN, and that's propagating to the accelerations. It's good that you checked the values of the states before realizeAcceleration(), though.
Dear Christopher :
Thanks a lot, and accordingly I found the following code generates Q with NAN, but U are normal:

Code: Select all

states = StatesTrajectory.createFromStatesStorage(osimModel,'s01_scaled_StatesReporter_states.sto');
for n=0:states.getSize()-1

  s = states.get(n);
  s.getQ()
  s.getU() 

end
In the MATLAB command window, it output like:

ans =

~[nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan]

ans =

~[0.193585 -0.566526 0.0335651 -0.167048 -0.744389 0.0058127 0.675978 0.788143 -0.762187 4.21848 -1.43364 -0.551058 -0.895295 0.928303 1.01911 -4.47533 -10.5055 2.43254 -0.544398 0.612323 0.416521 0.207642 1.01416 0.320432 3.1371 -0.614394 -3.59929 0 0 -0.32236 1.50121 0 0 0 0 0 0]

ans =

~[nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan]

ans =

~[0.118693 -0.63917 0.0594721 -0.21194 -0.795369 -0.0001005 1.06513 0.834706 -0.9328 4.58705 -1.60006 -0.54615 -0.887643 1.00835 1.14491 -5.85765 -10.2584 2.81592 -0.622451 0.749665 0.590353 0.301464 1.03006 0.951919 3.07022 -1.08118 -4.22099 0 0 -0.422619 1.62628 0 0 0 0 0 0]

...

Why is this happening ?

Regards
Jack

User avatar
Christopher Dembia
Posts: 506
Joined: Fri Oct 12, 2012 4:09 pm

Re: In MATLAB, osimModel.realizeAcceleration with no effect (OpenSim 4.0)

Post by Christopher Dembia » Thu Feb 08, 2018 11:35 pm

Hmm I don't know. Do you have the same issue if you use a model and states storage file from OpenSim's examples (e.g., the models folder in the OpenSim 3.3 installation)?

User avatar
Jack Zhao
Posts: 94
Joined: Thu Jul 24, 2014 7:15 am

Re: In MATLAB, osimModel.realizeAcceleration with no effect (OpenSim 4.0)

Post by Jack Zhao » Fri Feb 09, 2018 1:15 am

chrisdembia wrote:Hmm I don't know. Do you have the same issue if you use a model and states storage file from OpenSim's examples (e.g., the models folder in the OpenSim 3.3 installation)?
Dear Christopher:
The model is scaled gait2392 with the 3.3 version, and the .sto file was also generated through StatesReporter tool in OpenSim 3.3. However, the code to getQ and getU is based on the OpenSim 4.0 API framework. Do you mean there might be some problems of incompatibility ?


Best regards
Jack

User avatar
Christopher Dembia
Posts: 506
Joined: Fri Oct 12, 2012 4:09 pm

Re: In MATLAB, osimModel.realizeAcceleration with no effect (OpenSim 4.0)

Post by Christopher Dembia » Fri Feb 09, 2018 1:53 am

I just wasn't sure how much you edited your model, etc. Can you try using a states file that already comes with OpenSim?

POST REPLY