OpenSim API to specify the state value
Posted: 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.
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.