Page 1 of 1

states order in State::getY()

Posted: Wed Nov 20, 2019 10:46 pm
by wli45
I'm confused about the states' order when I use State::getY() or similar methods.
I found Y=Q+U+Z, but the states' orders inside Q,U,Z are hard to know. Is there a method to output states' name with the same sequence order of Y?
I tried Component::getStateVariableNames. It can output same states as in Opensim model, but obviously different from getY().
Thanks for reading.

Re: states order in State::getY()

Posted: Thu Nov 21, 2019 3:07 am
by tkuchida
It is generally advisable to get the values of state variables through the OpenSim API. For example, you can ask a Muscle for its fiber length using getFiberLength() (https://simtk.org/api_docs/opensim/api_ ... 61455143e8). It would be helpful to know what you are trying to do.

Re: states order in State::getY()

Posted: Thu Nov 21, 2019 9:36 am
by wli45
tkuchida wrote:
Thu Nov 21, 2019 3:07 am
It is generally advisable to get the values of state variables through the OpenSim API. For example, you can ask a Muscle for its fiber length using getFiberLength() (https://simtk.org/api_docs/opensim/api_ ... 61455143e8). It would be helpful to know what you are trying to do.
Thanks for replying. I was actually trying to get state derivatives, but they were different from what I expected. So I checked states setting, and found they were also different as I expected. The differences were mainly states' order.

Re: states order in State::getY()

Posted: Thu Nov 21, 2019 9:55 am
by tkuchida
Still not sure what you're trying to do, but there are some methods in OpenSim's Component interface that might be helpful:
- getStateIndex(), https://simtk.org/api_docs/opensim/api_ ... e65c5a1b5a
- getStateVariableSystemIndex(), https://simtk.org/api_docs/opensim/api_ ... 7d5938284d
- getDiscreteVariableIndex(), https://simtk.org/api_docs/opensim/api_ ... 1bc698cd88
- etc.
You could also interpret Y by changing states using OpenSim methods and seeing which entries in Y change, but there's no guarantee that the order/indices of state variables will remain the same between software releases. Some additional information can be found in the Simbody documentation, https://github.com/simbody/simbody/tree ... imbody/doc.

Re: states order in State::getY()

Posted: Thu Nov 21, 2019 10:25 am
by wli45
tkuchida wrote:
Thu Nov 21, 2019 9:55 am
Still not sure what you're trying to do, but there are some methods in OpenSim's Component interface that might be helpful:
Yes, it helps. I solved my problem. Thanks.