Hello,
I am new to using API commands in Python. I am trying to use the kinematics class to find the joints angular velocities, however I am having some difficulties to implement it in python?
I would appreciate if you have some hints or code examples.
Thanks,
Kinematics in python
- Benjamin Michaud
- Posts: 31
- Joined: Mon May 03, 2010 6:35 am
Re: Kinematics in python
Hello,
We have the same problem, from this piece of code we get up to loading coordinate states from a file, but we can't figure out how to derivate it properly
This code returns vectors of zeros for QDot
Thanks for your help!
We have the same problem, from this piece of code we get up to loading coordinate states from a file, but we can't figure out how to derivate it properly
Code: Select all
model = osim.Model(model_path)
state = model.initSystem()
working_state = model.updWorkingState()
# Read the data
data_storage = osim.Storage(Qfile)
for irow in range(data_storage.getSize()):
# Store Q in state
state.setTime(data_storage.getStateVector(irow).getTime())
state.setQ(data_storage.getStateVector(irow).getData().getAsVector())
model.computeStateVariableDerivatives(state)
QDot = state.getQDot()
print(QDot.toString())
Thanks for your help!
- Christopher Dembia
- Posts: 506
- Joined: Fri Oct 12, 2012 4:09 pm
Re: Kinematics in python
The columns in the Storage file may not be in the same order as the coordinates in the state's Q.
- Benjamin Michaud
- Posts: 31
- Joined: Mon May 03, 2010 6:35 am
Re: Kinematics in python
Hi Najoua,
We have just figure out how!
So after loading a mot file, you have to compute spline for each coordinate, idealy filter it and then evaluate values at each time. That would look something like this :
Regards
We have just figure out how!
So after loading a mot file, you have to compute spline for each coordinate, idealy filter it and then evaluate values at each time. That would look something like this :
Code: Select all
# Prepare a model
model = osim.Model(model_path)
state = model.initSystem()
working_state = model.updWorkingState()
# Read the data
data_storage = osim.Storage(Qfile)
model.getSimbodyEngine().convertDegreesToRadians(data_storage)
data_storage.lowpassIIR(10)
coord_function = osim.GCVSplineSet(5, data_storage)
# At each frame
for i in range(data_storage.getSize()):
Q = []
QDot = []
QDDot = []
for q in range(data_storage.getStateVector(i).getSize()):
Q.append(coord_function.evaluate(q, 0, data_storage.getStateVector(i).getTime()))
QDot.append(coord_function.evaluate(q, 1, data_storage.getStateVector(i).getTime()))
QDDot.append(coord_function.evaluate(q, 2, data_storage.getStateVector(i).getTime()))