Dear OpenSim Team,
I have a state output of arm26 Model at each time step from Forward dynamics ( I am coding in cpp). The state output is a vector 16x1
I want to run the InverseDynamicsSolver Tool ( called in cpp) to get the joint torque at each time step .
I set : SimTK::State s ; // declare the argument state of the IDsolver Tool
taw = InverseDynamicsSolver.solve(SimTK::State s) ;
I was wandering how to define the argument s to the Tool , and now when I left it as it is "s" I got no errors. So the state argument should be the array of stateVariableNames or one of the stateVaribleNames. Does this makes sense ? example : taw = InverseDynamicsSolver.solve(SimTK::State r_elbow_flex )
And in case I want to input my own vectors for q, u,z ( continuous Variables) I should in this case use:
SimTK::State::setQ(q_vector) ; //q_vector is my input q vector at each timestep
SimTK::State::setU(u_vector) ;
SimTK::State::setZ (z_vector) ;
SimTK::State::setTime (t_vector) ;
Then use Model.getMultibodySystem().realize( SimTK::State s, Dynamics) here i should leave s as it is ?
Then to get the torque vector , i use torque = InverseDynamicsSolver.solve(SimTK::State s) ;
My question is that the realize method is responsible of updating the state of the system ? and my main issue resides in the definition of (SimTK::State s) argument which now I think this should be left as string s , Does this makes sense ? If someone can clarify to me this issue it will be of great help .
Thanks in advance for any help you can provide,
Sariah,
(SimTK::State &s) argument of InverseDynamicsSolver Tool
- sariah Mghames
- Posts: 23
- Joined: Thu Jun 30, 2016 5:56 am
- Dimitar Stanev
- Posts: 1096
- Joined: Fri Jan 31, 2014 5:14 am
Re: (SimTK::State &s) argument of InverseDynamicsSolver Tool
Hi,
When you build and initialize your model, you get the initial state of the model. You pass this state to different functions and you either alter the state or compute something based on the current one. If the function that your are calling takes the state as non-const reference, that means that it alters its content (e.g. manager.step()). Make sure that you have a single state variable and pass it correctly to the different function calls.
You should do:
Best
The state is not a vector but it is something that keeps track of all the internal variables that describe the state of your model. Also the state is realized into stages, and at each stage some states are updated.The state output is a vector 16x1
The above definition creates a state object which does not contain any information about your model.I set : SimTK::State s ; // declare the argument state of the IDsolver Tool
When you build and initialize your model, you get the initial state of the model. You pass this state to different functions and you either alter the state or compute something based on the current one. If the function that your are calling takes the state as non-const reference, that means that it alters its content (e.g. manager.step()). Make sure that you have a single state variable and pass it correctly to the different function calls.
You should do:
Code: Select all
model.buildSystem(); \\ build the model
State s = model.initializeState(); \\ get the initial state of the model
Yes.And in case I want to input my own vectors for q, u,z ( continuous Variables) I should in this case use:
SimTK::State::setQ(q_vector) ; //q_vector is my input q vector at each timestep
SimTK::State::setU(u_vector) ;
SimTK::State::setZ (z_vector) ;
Code: Select all
s.updQ() = qVector;
Here you set the current time (double).SimTK::State::setTime (t_vector) ;
You can call model.realizeDynamics(s) or .realize[Stage], where s is your state variable.Then use Model.getMultibodySystem().realize( SimTK::State s, Dynamics) here i should leave s as it is ?
Best
- sariah Mghames
- Posts: 23
- Joined: Thu Jun 30, 2016 5:56 am
Re: (SimTK::State &s) argument of InverseDynamicsSolver Tool
Thanks alot, very helpful and clear
So now if I am not wrong, to get joint torques, after realizing the state to the Dynamics stage( Model.realizeDynamics(state) ) , I should call:
SimTK::Vector Torque = state.getZDot() ;
Otherwise I call :
SimTK::Vector Torque = InverseDynamicsSolver.solve(state)
Both give the same output. Does it make sense ?
Regards,
So now if I am not wrong, to get joint torques, after realizing the state to the Dynamics stage( Model.realizeDynamics(state) ) , I should call:
SimTK::Vector Torque = state.getZDot() ;
Otherwise I call :
SimTK::Vector Torque = InverseDynamicsSolver.solve(state)
Both give the same output. Does it make sense ?
Regards,
- Dimitar Stanev
- Posts: 1096
- Joined: Fri Jan 31, 2014 5:14 am
Re: (SimTK::State &s) argument of InverseDynamicsSolver Tool
ZDot are auxiliary state variables, and are not related to joint torques. You should use the solver, providing q, qdot, qddot and the applied forces, thus solving the equation of motion for tau.
https://simtk.org/api_docs/opensim/api_ ... olver.html
I would suggest you to get more familiar with the user guide (algorithms) and the theory behind the simulation engine.
http://simtk-confluence.stanford.edu:80 ... %27s+Guide
https://simtk.org/docman/?group_id=47
Best
https://simtk.org/api_docs/opensim/api_ ... olver.html
I would suggest you to get more familiar with the user guide (algorithms) and the theory behind the simulation engine.
http://simtk-confluence.stanford.edu:80 ... %27s+Guide
https://simtk.org/docman/?group_id=47
Best
- sariah Mghames
- Posts: 23
- Joined: Thu Jun 30, 2016 5:56 am
Re: (SimTK::State &s) argument of InverseDynamicsSolver Tool
Thanks for the help,
I applied the inverseDynamicsSolver on the model ( arm 26 , OpenSim 2.4.0) , but:
when I add to my cpp code:
InverseDynamicsSolver ids(model); // model is already defined and ids is object of type InverseDynamics solver
I got no error while compiling and linking the cpp code
However when I add after : SimTK::Vector torque= ids.solve(state); // assumed udot (acceleration) to be the default
I got: A dynamic link library (DLL) initialization routine failed. The solve function of the InverseDynamicsSolver class is related to the osimSimulation.dll library and that library is correctly added to matlab path ( in matlab path since I am implementing a cpp S-function in the simulink environment of matlab) and to the environment variables path.
I am now wondering if the dll related library of the solve() function has a problem in the initialization because all include files, dll and static libraries are added correctly and in addition the function InverseDynamicsSolver(model) of the class InverseDynamicsSolver() doesn't generate any error.
I am looking for a help in solving such bug. Thanks in advance.
Regards,
I applied the inverseDynamicsSolver on the model ( arm 26 , OpenSim 2.4.0) , but:
when I add to my cpp code:
InverseDynamicsSolver ids(model); // model is already defined and ids is object of type InverseDynamics solver
I got no error while compiling and linking the cpp code
However when I add after : SimTK::Vector torque= ids.solve(state); // assumed udot (acceleration) to be the default
I got: A dynamic link library (DLL) initialization routine failed. The solve function of the InverseDynamicsSolver class is related to the osimSimulation.dll library and that library is correctly added to matlab path ( in matlab path since I am implementing a cpp S-function in the simulink environment of matlab) and to the environment variables path.
I am now wondering if the dll related library of the solve() function has a problem in the initialization because all include files, dll and static libraries are added correctly and in addition the function InverseDynamicsSolver(model) of the class InverseDynamicsSolver() doesn't generate any error.
I am looking for a help in solving such bug. Thanks in advance.
Regards,
- Dimitar Stanev
- Posts: 1096
- Joined: Fri Jan 31, 2014 5:14 am
Re: (SimTK::State &s) argument of InverseDynamicsSolver Tool
Hi,
You can do ids.solve(state, state.getUDot()).
Best
If you assume default acceleration = Vector(0) you perform static analysis!!!However when I add after : SimTK::Vector torque= ids.solve(state); // assumed udot (acceleration) to be the default
You can do ids.solve(state, state.getUDot()).
Make sure to link the static libraries. You can try to make a stand alone c++ project to test your implementation before moving to Matlab s-function. I don't know about version 2.4, but in the new version you generate your project through CMake, and all the dependencies (includes, static libraries) are resolved.I got: A dynamic link library (DLL) initialization routine failed. The solve function of the InverseDynamicsSolver class is related to the osimSimulation.dll library and that library is correctly added to matlab path ( in matlab path since I am implementing a cpp S-function in the simulink environment of matlab) and to the environment variables path.
I am now wondering if the dll related library of the solve() function has a problem in the initialization because all include files, dll and static libraries are added correctly and in addition the function InverseDynamicsSolver(model) of the class InverseDynamicsSolver() doesn't generate any error.
Best