Numbers of Y from osimState and state variables from osimModel

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Hide Kimpara
Posts: 135
Joined: Mon Sep 19, 2016 5:12 am

Numbers of Y from osimState and state variables from osimModel

Post by Hide Kimpara » Thu Apr 27, 2017 1:37 pm

Dear specialists of OpenSim,

I am Hide Kimpara at WPI.

I have a trouble in forward analysis using Matlab scripts.

I modified a MATLAB code of Dynamic Walker example and apply the code to other sample models, such as bouncingblock.
https://github.com/opensim-org/opensim- ... SimPlant.m

Now I got an error in the "IntegrateOpenSimPlant.m" because the number of "OutputData.nColumns" which may be equal to size(osimState.getY()) was greater than size of "osimModel.getStateVariableNames()".
Then I realized 18 of size(osimState.getY()) in case of BouncingBlock.osim model, while number of state variables from osimModel "osimModel.getNumStateVariables()" was only 16. So Y variables from osimState have state variables from osimModel plus other two variables.
I found using of FreeJoint and BushingForce creates additional Y variables for osimState. So, Y may contain variables as "xRotation, yRotation, zRotation, xTranslation, yTranslation, zTranslation, somethingfromFreeJoint, somethingfromBushingForce, xRotation_u, ....
However, I did not know what variables have been added on.

I have three questions:
(1) What functions add further Y variables in osimState? And what do those mean for?
(2) In case of models with additional Y variables, how can I change MATLAB code of Dynamic Walker example?
(3) I wish to export sto formated output files for states and control variables from Dynamic Walker example. Are there any examples in OpenSim related web pages?

Best regards,
Hide

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

Re: Numbers of Y from osimState and state variables from osimModel

Post by Dimitar Stanev » Fri Apr 28, 2017 2:07 am

The Y variable of the state contains {Q, U, Z} variables, where Z are auxiliary state variables that may not be directly related to a meaningful state variables. Probably it is best to use getU and getQ. Please refere to the manual for more details regarding the state variables:

https://simtk.org/api_docs/simbody/3.5/ ... ml#details

This is how I get the state after simulating the system (C++, but can be easily translated to Matlab):

Code: Select all

    //manager
    OpenSim::Manager manager(model, integrator);
    manager.setInitialTime(t0);
    manager.setFinalTime(tf);

    //integrate
    time_t t = startClock("Integrating...");
    manager.integrate(s);
    stopClock("Finish integration", t);

    //state results
    storage = OpenSim::Storage(manager.getStateStorage());
    storage.setColumnLabels(manager.getStateStorage().getColumnLabels());
    model.updSimbodyEngine().convertRadiansToDegrees(storage);

User avatar
Hide Kimpara
Posts: 135
Joined: Mon Sep 19, 2016 5:12 am

Re: Numbers of Y from osimState and state variables from osimModel

Post by Hide Kimpara » Fri Apr 28, 2017 8:54 am

Dear Dimitar,

Thank you for your clear feedback. Now I realized variable Y consists of variables Q, U, and Z.
This is very good help for me.

When I check those variables with BouncingBlock example model, number of Q variable was greater than that of U variable. This means Q variable has another state variables instead of xR, yR, zR, xT, yT, zT of FreeJoint.
But OpenSim's forward tool can express state history data with 8 variables from Q and 8 variables from U.

I wished to use OpenSim's manager functions. However, due to something, I failed to do that. MATLAB crashed just after running integration frequently.
Also I got similar crash termination when I use ForceReporter with osimState.

So, manually, I can skip 9th variable of Q, then I may be able to create similar sto files what forward tool can provide us.
Can I have contact force and joint force records without simulation manager?

Thank you
Hide

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

Re: Numbers of Y from osimState and state variables from osimModel

Post by Dimitar Stanev » Sun Apr 30, 2017 1:06 am

Hi,
I wished to use OpenSim's manager functions. However, due to something, I failed to do that. MATLAB crashed just after running integration frequently.
Also I got similar crash termination when I use ForceReporter with osimState.
You can post the code if you want.
Can I have contact force and joint force records without simulation manager?
Joint Forces: http://simtk-confluence.stanford.edu:80 ... s+Analysis

The easiness way is to use ForceReporter, otherwise you have to access the forces itself programmatically.

https://simtk.org/api_docs/simbody/3.5/ ... Force.html

POST REPLY