OpenSim API to specify the state value

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Jiabiao Yi
Posts: 2
Joined: Mon Mar 21, 2022 7:24 pm

OpenSim API to specify the state value

Post by Jiabiao Yi » Thu Mar 09, 2023 9:17 pm

Hi,
I am trying to run forward dynamics on matlab. I already have all the files that can be used to run forward dynamics on opensim GUI (model, initial state, control history). I fall into trouble when I try to specify the state values. It seems like there is no function to fulfill this directly.
I find two possible ways. One is to use the function 'setStates'. However, the sentence 'State.setStates(state_vector);' doesn't work ('State' is derived from 'State=Model.initSystem();'; 'state_vector' is a vector). The report indicates that 'setStates' is not defined in 'State'. Maybe 'setStates' belongs to other class but not 'State', or this function is just available on C++ but not on matlab. If if's the former, how do I get the class?
The other is to use 'State.updY().set(i, state_value);' ('i' is the position of the state component to change; 'state_value' is a single value). This works but I still have questions. The number derived from 'Nstates=Model.getNumStateVariables();' (in my case, 210) is different from that derived from 'NstateY = State.getNY();' (218). What is the difference between these two? I also find elements such as 'Q', 'U', 'Y' and 'Z' in class 'State', what's the meaning of them? Does 'Y' represent the state?
Thanks for any possible help.

Tags:

User avatar
Carmichael Ong
Posts: 380
Joined: Fri Feb 24, 2012 11:50 am

Re: OpenSim API to specify the state value

Post by Carmichael Ong » Fri Mar 10, 2023 1:13 pm

Often, it is best to use the Coordinate class (https://simtk.org/api_docs/opensim/api_ ... inate.html) and the functions setValue() and setSpeedValue(), as this is less error prone than updating the State object directly.

The State object is in the Simbody layer, so documentation can be found in the Simbody API documentation: https://simtk.org/api_docs/molmodel/api ... l#_details

POST REPLY