NaN state values from state .sto file

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Joris Verhagen
Posts: 6
Joined: Tue Sep 15, 2020 12:55 am

NaN state values from state .sto file

Post by Joris Verhagen » Wed Jun 16, 2021 12:25 pm

Hello everyone,
I'm working on a problem that requires me to set the state of a model for every row in a .sto state file. To that end I'm creating a StateTrajectory() object and then realizeAccelerations of the model;

Code: Select all

OpenSim::Model model(modelPath);
    model.initSystem();

    // load in state data and create 'StatesTrajectory' object which can be
    // indexed to extract the correct state.
    OpenSim::Storage storage(statesPath);
    OpenSim::StatesTrajectory stateTrajectory =
            OpenSim::StatesTrajectory::createFromStatesStorage(model,storage);
    SimTK::State state;

    for(int i=0; i<stateTrajectory.getSize(); i++){
        state = stateTrajectory[i];
        std::cout << "Q:" << std::endl;
        state.getQ().dump();
        std::cout << "---NEW ITERATION---" << std::endl;
    }


    int nRows = stateTrajectory.getSize();
    std::cout << "Detected " << nRows << " states!" << std::endl;
    for(int i=0; i<nRows; i++){
        // The state of this iteration
        state = stateTrajectory[i];
        state.setTime(0.0);
        // Set the model to the correct state
        model.realizeAcceleration(state);
        
        // OTHER CODE
The problem is that after loading a state from the stateTrajectory, the q row contains NaN values.
The .sto state file is attached and does not seem to have any glaring problems. The model file is working.

Code: Select all

<Vector name=q size=39>
0.070386039999999997
-0.14616630999999999
0.059225710000000001
0.028397269999999999
1.0103145899999999
-0.22515103
0.21716084999999999
0.22423939000000001
-0.076024019999999998
-0.13515421999999999
-0.26453270000000001
-0.16344834999999999
-0.17244311000000001
0.17887336000000001
-0.071199520000000002
0.24554582999999999
0.24554582999999999
0.82330634000000003
0.82330634000000003
-0.18445331000000001
-0.18795624999999999
-0.24812118999999999
0.0060301900000000004
-0.17551496
-0.22645839000000001
0.00147401
-0.31521786000000002
0.51667315000000003
0.54912039000000001
NaN
NaN
0.53777010999999997
0.53066696000000002
NaN
NaN
NaN
NaN
NaN
NaN
If I load in the model and the state storage file in the OpenSim GUI nothing seems the matter. I'm not sure how to obtain the relevant name of the NaN values (it could give me a hint if these would indicate certain coordinates).

All in all, does anyone know why these NaN values appear and what I need to do to solve it? Ignoring it is not an option because in the rest of the code I compute the CoM of the pelvis and feet for which the feet is now also a SimTK::Vec3 ~[nan,nan,nan]...

Thanks in advance!
(files too large, please see https://we.tl/t-SbXgDox5kE (weTransfer link))

Tags:

User avatar
Joris Verhagen
Posts: 6
Joined: Tue Sep 15, 2020 12:55 am

Re: NaN state values from state .sto file

Post by Joris Verhagen » Tue Jun 22, 2021 7:30 am

Fixed!

Apparently the GUI load motion method and the C++ method are not totally equal (at least in the way I did them).
I've added;

Code: Select all

OpenSim::Storage storage(statesPath);
    OpenSim::StatesTrajectory stateTrajectory =
            OpenSim::StatesTrajectory::createFromStatesStorage(model,storage,false,false,true);
These booleans can be read in the documentation. The last one seems to ensure that the state adheres to any constraints;
https://simtk.org/api_docs/opensim/api_ ... 16808dde64

Hope this helps someone else!

POST REPLY