Page 1 of 1

Numbers of Y from osimState and state variables from osimModel

Posted: Thu Apr 27, 2017 1:37 pm
by hkimpara
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

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

Posted: Fri Apr 28, 2017 2:07 am
by mitkof6
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);

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

Posted: Fri Apr 28, 2017 8:54 am
by hkimpara
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

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

Posted: Sun Apr 30, 2017 1:06 am
by mitkof6
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