Page 1 of 1

trouble running getRecordValues in matlab

Posted: Fri May 28, 2021 8:47 am
by affdk
Hi,

I tried something like the following code in matlab and faced an error (matlab environment has been configured before and I could run a number of other methods):

import org.opensim.modeling.*
EnvModel = Model('Modelfile');
state = EnvModel.initSystem(); % I also tried with initializeState with the same error message
force = EnvModel.getForceSet.get(0);
values = force.getRecordValues(state);

Then I get the following error:

Java exception occurred:
java.lang.RuntimeException: SimTK Exception thrown at GeneralContactSubsystem.cpp:131:
Expected stage to be at least Dynamics in GeneralContactSubsystemImpl::getContacts() but current stage was Velocity

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

at org.opensim.modeling.Force.getRecordValues(Force.java:121)

Any hint on what could be wrong?

Best regards,
Afshin

Re: trouble running getRecordValues in matlab

Posted: Fri May 28, 2021 9:25 am
by aymanh
Hi Afshin,

When you call initSystem, the state is realized only to a specific stage (Position), so quantities that depend on position can be extracted directly, computing and reporting force values requires realization to a higher stage so you'll need to call the proper realize...() method first. This is documented in the doxygen documentation of OpenSim::Model class here
https://simtk.org/api_docs/opensim/api_ ... Model.html

Hope this helps,
-Ayman