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
getMultibodySystem().realize in python [SOLVED]
- Benjamin Michaud
- Posts: 31
- Joined: Mon May 03, 2010 6:35 am
getMultibodySystem().realize in python [SOLVED]
Last edited by Benjamin Michaud on Tue Oct 23, 2018 8:37 am, edited 1 time in total.
- Ayman Habib
- Posts: 2248
- Joined: Fri Apr 01, 2005 12:24 pm
Re: getMultibodySystem().realize in python
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
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
- Christopher Dembia
- Posts: 506
- Joined: Fri Oct 12, 2012 4:09 pm
Re: getMultibodySystem().realize in python
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.
- Benjamin Michaud
- Posts: 31
- Joined: Mon May 03, 2010 6:35 am
Re: getMultibodySystem().realize in python
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
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
- Benjamin Michaud
- Posts: 31
- Joined: Mon May 03, 2010 6:35 am
Re: getMultibodySystem().realize in python
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:
Thanks for your help
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)