getMultibodySystem().realize in python [SOLVED]

The 2018 Fall Virtual Workshop will bring together a group of international scholars and OpenSim experts to help each other advance their research using modeling and simulation. This forum is a place to accelerate OpenSim based projects while also buildin
POST REPLY
User avatar
Benjamin Michaud
Posts: 31
Joined: Mon May 03, 2010 6:35 am

getMultibodySystem().realize in python [SOLVED]

Post by Benjamin Michaud » Mon Oct 22, 2018 12:03 pm

Hello!

I am rewriting the Static Optimization in Python. At some point (at the beginning of a new frame), I need to update the model according to the Q of the state. In a naive approach, I decided that I would create an "osim.State" and populate it with the required Q (something like that:

self.model = osim.Model(model_path)
self.state = osim.State()
self.Q = self.state.getQ() # Get a reference to the Q into that state
self.Q.resize(n_dof_of_the_model)
for i in range(n_dof_of_the_model):
self.Q.set(i, desired_values)

thereafter, I would have called:
self.model.getMultibodySystem().realize(self.state, DESIRED_KINEMATIC_FLAG)

But two problems arose. The first one is "realize" is not callable from the swig API. The second is (when the first will be solved) the FLAGS are not interfaced either.

So my question is: Is there a better way to update the kinematics of a model to a desired pose?

Thanks
Last edited by Benjamin Michaud on Tue Oct 23, 2018 8:37 am, edited 1 time in total.

User avatar
Ayman Habib
Posts: 2235
Joined: Fri Apr 01, 2005 12:24 pm

Re: getMultibodySystem().realize in python

Post by Ayman Habib » Mon Oct 22, 2018 1:50 pm

Hi Benjamin,

Thanks for taking this on, it will be extremely helpful to everybody using python to perform post-hoc analysis.

I'd highly recommend you check the python script under opensim-core (tBindings/Python/tests/test_states_trajectory.py) as it creates a stateTrajectory object and steps through it.

Please let us know if you run into problem locating it.

Best regards,
-Ayman

User avatar
Christopher Dembia
Posts: 506
Joined: Fri Oct 12, 2012 4:09 pm

Re: getMultibodySystem().realize in python

Post by Christopher Dembia » Mon Oct 22, 2018 3:12 pm

Also, it's a good idea to use upQ() if you plan on editing the reference. Also, you should not resize the vectors stored within the State.

User avatar
Benjamin Michaud
Posts: 31
Joined: Mon May 03, 2010 6:35 am

Re: getMultibodySystem().realize in python

Post by Benjamin Michaud » Tue Oct 23, 2018 8:05 am

Thanks for your answer.

I was actually on the right track, but I got SegFaults. I thought I was doing things wrong and then started to resize and all. But it turns out, this was related to the other topic I opened which is now solved with a fresh environment.

I'll have a look at the examples! Thank again :)

User avatar
Benjamin Michaud
Posts: 31
Joined: Mon May 03, 2010 6:35 am

Re: getMultibodySystem().realize in python

Post by Benjamin Michaud » Tue Oct 23, 2018 8:37 am

Hello all!

For those who may get to this thread in the future (as it is not specifically done in the tests suggested earlier), there is actually an interface to realize:

Code: Select all

model = osim.Model(model_path)
state = self.model.initSystem()
Q = state.getQ()
{modify Q as needed}
model.realizePosition(state)
Thanks for your help

POST REPLY