Page 1 of 1

Python API: Geometry path and joint center location

Posted: Fri Jun 23, 2023 6:18 pm
by takuma171
Hi, I am trying to use Python API to get geometry muscle point and joint center in "global coordinate system".

Recently, I could get optimal fiber length, tendon slack length, maximum isometric force, pennation angle, musculotendon length, and moment arm from 'gait2392_simbody.osim'.

Also, I think that I want to get geometry muscle point and joint center in "global coordinate system" in various generalized coordinates.

=============
model = opensim.Model('gait2392_simbody.osim')
state = model.initSystem()

list_coordinates = ['lumbar_extension',
'hip_flexion_l',
'knee_angle_l',
'ankle_angle_l',
'hip_flexion_r',
'knee_angle_r',
'ankle_angle_r']

values_coordinate = np.array([0,0,0,0,0,0,0]) # Angle: Trunk, left hip, knee, ankle, right hip, knee, ankle, e.g., all zero
for i_coordinate, _name_coordinate in enumerate(list_coordinates):
# Set posture
model.updCoordinateSet().get(_name_coordinate).setValue(state,np.deg2rad(values_coordinate[i_coordinate]))

_muscle = model.getMuscles().get('psoas_r')
_points = _muscle.getGeometryPath().getPathPointSet()
n_points = _points.getSize()
_point = _points.get(0) # e.g., first point
_vec = _point.getLocation(state)

============

Would you modify the code or tell me how to get geometry muscle point and joint center in "global coordinate system" in various generalized coordinates?

Sincerely yours,

Takuma Inai
Advanced Industrial Science and Technology

Re: Python API: Geometry path and joint center location

Posted: Mon Jun 26, 2023 8:18 am
by aymanh
Hello,

First I would recommend replacing

Code: Select all

model.updCoordinateSet()
with

Code: Select all

model.getCoordinateSet()
as your code doesn't change the coordinate objects themselves but the values of the state variables maintained by the coordinates, these live in the state object. Using upd methods could have undesirable side effects if you're not actually modifying or intending to modify the model objects.

Typically, calculations are done in local coordinate system (e.g. of the Body/Frame that a PathPoint is attached to) however there are general utilities to convert these positions to global frame as described in the Frame class documentation here https://simtk.org/api_docs/opensim/api_ ... Frame.html
for example

Code: Select all

getPositionInGround
. Bodies and Ground are types of Frames.

Hope this helps,
-Ayman

Re: Python API: Geometry path and joint center location

Posted: Mon Jun 26, 2023 8:24 pm
by takuma171
Hi, I really appreciate your answer!!
Based on your reply, I am goingt to try it!

Sincerely yours,
Takuma Inai
AIST