Page 1 of 1

API: Animate a model with IK results

Posted: Mon Jul 22, 2019 12:15 am
by mel_asfa
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

Re: API: Animate a model with IK results

Posted: Tue Jul 23, 2019 7:21 am
by mitkof6
The following example is in C++, but can be adapted in Python. You have to initialize the simbody visualizer:

Code: Select all

Model model(modelFile);
model.setUseVisualizer(true)
auto& state = model.initSystem()
auto& visualizer = model.updVisualizer().updSimbodyVisualizer()
Then you have to loop through the data from IK, update the state and visualizer:

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));
}

Re: API: Animate a model with IK results

Posted: Mon Aug 05, 2019 12:07 pm
by bebe
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!