API: Animate a model with IK results

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Mélissandre Asfazadourian
Posts: 6
Joined: Tue Jun 11, 2019 2:13 am

API: Animate a model with IK results

Post by Mélissandre Asfazadourian » Mon Jul 22, 2019 12:15 am

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

Tags:

User avatar
Dimitar Stanev
Posts: 1096
Joined: Fri Jan 31, 2014 5:14 am

Re: API: Animate a model with IK results

Post by Dimitar Stanev » Tue Jul 23, 2019 7:21 am

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

User avatar
behnoosh parsa
Posts: 2
Joined: Sun Aug 28, 2011 9:26 am

Re: API: Animate a model with IK results

Post by behnoosh parsa » Mon Aug 05, 2019 12:07 pm

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!

POST REPLY