Page 1 of 1

Unusual "State Cache entry out of date" error

Posted: Fri May 26, 2023 3:45 am
by modenaxe
Hello,
I am using the OpenSim API in MATLAB to extract the triangle proximity used in OpenSim JAM (https://github.com/opensim-jam-org/opensim-core) (from Smith2018ArticularContactForce) using a method called 'getTargetTriangleProximity' that depends only on State realised at Position stage:

Code: Select all

clear; close all;
import org.opensim.modeling.*
% read the model
osimModel = Model('lenhart2015.osim');
% get the tibio-femoral contact
contact = osimModel.get_ForceSet().get('tf_contact');
% get the Smith2018 contact force
smith_contact = Smith2018ArticularContactForce.safeDownCast(contact);
% initialise model
state = osimModel.initSystem();
% update position to default (all coordinates are zero)
coordset = osimModel.getCoordinateSet();
for nj = 0:coordset.getSize()-1    
    curr_coord = coordset.get(nj);
    disp(['updating coordinate ', char(curr_coord.getName())])
    curr_coord.setValue(state, 0.0);
    % curr_coord.setSpeedValue(state, 0.0)
end
% I want the triangle proximity
smith_contact.getTargetTriangleProximity(state)
however I keep getting a an error related to State that I find difficult to debug:

Code: Select all

Error using compute_smith_proximity
Java exception occurred:
java.lang.RuntimeException: SimTK Exception thrown at State.cpp:974:
  Error detected by Simbody method getCacheEntry: State Cache entry was out of date at Stage Position. This entry depends on version 1 of
  Stage Position but was last updated at version 0.
  (Required condition 'version == m_dependsOnVersionWhenLastComputed' was not met.)
  

	at org.opensim.modeling.opensimSimulationJNI.Smith2018ArticularContactForce_getTargetTriangleProximity(Native Method)

	at org.opensim.modeling.Smith2018ArticularContactForce.getTargetTriangleProximity(Smith2018ArticularContactForce.java:848)
The script is basic and I have tried also computing the state derivatives with ('computeStateVariableDerivatives') in case that could update the cache, but it didn't help. I have seen that someone had similar issues in 2014, but the fix (using the realise() method) seemed too dated to help.

Any advice would be very helpful!

Thank you,

Luca

Re: Unusual "State Cache entry out of date" error

Posted: Mon Jun 26, 2023 1:30 pm
by ongcf
The first thing I'd try is to use Model::realizePosition() (in case the method you're calling isn't calling that first). Unfortunately even though that post you found was quite old, the realizeX() methods can still be needed in some unexpected places. In case calling Model::realizePosition() doesn't help, then it'll be good to see if the same or different error message pops up.