I would like to do "mixed" dynamics through the OpenSim API, where I prescribe the motion of all DOFs in my model EXCEPT for the motion of the pelvis "root" segment, which I want to numerically integrate using my own fixed-step integration method (so I know a priori all time points where the state derivatives will be needed). However, I can't figure out how to do it.
From what I can see on-line, the function below will give me the state derivatives for the 6 pelvis DOFs:
https://simtk.org/api_docs/opensim/api_ ... 3dc9c41d17
However, from what I can tell, the only way to input the q, u, and udot values at each instant in time for the prescribed coordinates is through the use of a prescribed function defined as part of the model itself:
https://simtk.org/api_docs/opensim/api_ ... 7fd0c5f78d
I am going to do my numerical integration outside of OpenSim and thus do not want to use OpenSim prescribed functions. For any time instant, I want to be able to give my model the q, u, and udot values for the prescribed coordinates along with the state for the pelvis (and all applied loads) and then have the state derivative function return the state derivatives for the 6 pelvis DOFs along with the inverse dynamic moments for the prescribed DOFs.
Is there some way to do a "mixed" dynamics solution like this with existing OpenSim API functionality? Sherm seemed to think that there was a way to input q, u, and udot values for prescribed coordinates at a single point in time, but after looking through the OpenSim API on-line documentation, it is not clear to me that it is possible.
Thanks for any insight that anyone can provide on this question.
B.J.
"Mixed" Dynamics through OpenSim API
- Michael Sherman
- Posts: 807
- Joined: Fri Apr 01, 2005 6:05 pm
Re: "Mixed" Dynamics through OpenSim API
Happy New Year, BJ!
I can't answer your question directly but have a comment and question for while you are waiting for a knowledgeable response. It is always possible (in C++ at least) to get (from the OpenSim Model) access to the underlying Simbody System that OpenSim has constructed on your behalf. That may provide a loophole that would let you do what you want.
What language are you using to access the OpenSim API? If it is Matlab or Python not all APIs are available; the same loophole might not work there.
Regards,
Sherm
I can't answer your question directly but have a comment and question for while you are waiting for a knowledgeable response. It is always possible (in C++ at least) to get (from the OpenSim Model) access to the underlying Simbody System that OpenSim has constructed on your behalf. That may provide a loophole that would let you do what you want.
What language are you using to access the OpenSim API? If it is Matlab or Python not all APIs are available; the same loophole might not work there.
Regards,
Sherm
- B.J. Fregly
- Posts: 51
- Joined: Wed Mar 12, 2008 6:55 am
Re: "Mixed" Dynamics through OpenSim API
Hi Sherm,
Happy new year to you as well!
We are calling OpenSim functionality through Matlab but we are not using the OpenSim Matlab API. Instead, we are writing our own mex functions in C++ to provide the interface between Matlab and OpenSim and then doing all OpenSim API calls in C++.
So as a worst case scenario, the approach you mentioned (figuring out how to call Simbody functionality in C++) should be an option for us if there is no easy way to do what we want with existing OpenSim C++ API functions. I did not realize that we could call Simbody functions directly, so thanks for sharing that insight.
We'll see what the "experts" have to say about whether an OpenSim C++ API function can do the job as well.
Best regards,
B.J.
Happy new year to you as well!
We are calling OpenSim functionality through Matlab but we are not using the OpenSim Matlab API. Instead, we are writing our own mex functions in C++ to provide the interface between Matlab and OpenSim and then doing all OpenSim API calls in C++.
So as a worst case scenario, the approach you mentioned (figuring out how to call Simbody functionality in C++) should be an option for us if there is no easy way to do what we want with existing OpenSim C++ API functions. I did not realize that we could call Simbody functions directly, so thanks for sharing that insight.
We'll see what the "experts" have to say about whether an OpenSim C++ API function can do the job as well.
Best regards,
B.J.
- Joseph Ewing
- Posts: 7
- Joined: Fri Feb 24, 2012 11:47 am
Re: "Mixed" Dynamics through OpenSim API
BJ,
We are doing similar type things here at OSU. I am not certain this will get you where you need to go, but you can update positions and velocities of a state vector using these calls:
osimState.updQ().set(i-1,positions(i));
osimState.updU().set(i-1,velocities(i));
this is after you have realized a state in opensim. There is a similar call for udot as well as muscle states. You should then be able to use
osimModel.computeStateVariableDerivatives(osimState);
To get your derivative vector.
Joe
We are doing similar type things here at OSU. I am not certain this will get you where you need to go, but you can update positions and velocities of a state vector using these calls:
osimState.updQ().set(i-1,positions(i));
osimState.updU().set(i-1,velocities(i));
this is after you have realized a state in opensim. There is a similar call for udot as well as muscle states. You should then be able to use
osimModel.computeStateVariableDerivatives(osimState);
To get your derivative vector.
Joe