Hi!
I have Inverse Kinematics results into a .mot file and I would to use them in order to animate my model in the API. I read all the documentation and topics that could help me but nothing did. I know somebody already opened this kind of topic last year but never had a clear answer.
I know that I can load my results into the Opensim GUI but I want to do it in the API. I am using Python and I don't know how to relate my .mot file and my model to see it move.
A little help would be great!
Thanks in advance
API: Animate a model with IK results
- Mélissandre Asfazadourian
- Posts: 6
- Joined: Tue Jun 11, 2019 2:13 am
- Dimitar Stanev
- Posts: 1096
- Joined: Fri Jan 31, 2014 5:14 am
Re: API: Animate a model with IK results
The following example is in C++, but can be adapted in Python. You have to initialize the simbody visualizer:
Then you have to loop through the data from IK, update the state and visualizer:
Code: Select all
Model model(modelFile);
model.setUseVisualizer(true)
auto& state = model.initSystem()
auto& visualizer = model.updVisualizer().updSimbodyVisualizer()
Code: Select all
// loop through ik storage
for (int i = 0; i < ikQ.getSize(); ++i) {
// read storage entry
auto stateVector = ikQ.getStateVector(i);
double t = stateVector->getTime();
auto q = Vector(stateVector->getSize(), &stateVector->getData()[0]);
state.updQ() = q;
visualizer.report(state);
this_thread::sleep_for(chrono::milliseconds(10));
}
- behnoosh parsa
- Posts: 2
- Joined: Sun Aug 28, 2011 9:26 am
Re: API: Animate a model with IK results
Hi,
I have trouble implementing these two lines in Python:
auto q = Vector(stateVector->getSize(), &stateVector->getData()[0]);
state.updQ() = q;
Could you please help me?
Is the a documentation for python users for openSim?
Thank you!
I have trouble implementing these two lines in Python:
auto q = Vector(stateVector->getSize(), &stateVector->getData()[0]);
state.updQ() = q;
Could you please help me?
Is the a documentation for python users for openSim?
Thank you!