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.
OpenSim API to specify the state value
- Jiabiao Yi
- Posts: 2
- Joined: Mon Mar 21, 2022 7:24 pm
- Carmichael Ong
- Posts: 401
- Joined: Fri Feb 24, 2012 11:50 am
Re: OpenSim API to specify the state value
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
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