Python API: Geometry path and joint center location

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Takuma Inai
Posts: 6
Joined: Sat Oct 26, 2013 12:11 am

Python API: Geometry path and joint center location

Post by Takuma Inai » Fri Jun 23, 2023 6:18 pm

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

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

Re: Python API: Geometry path and joint center location

Post by Ayman Habib » Mon Jun 26, 2023 8:18 am

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

User avatar
Takuma Inai
Posts: 6
Joined: Sat Oct 26, 2013 12:11 am

Re: Python API: Geometry path and joint center location

Post by Takuma Inai » Mon Jun 26, 2023 8:24 pm

Hi, I really appreciate your answer!!
Based on your reply, I am goingt to try it!

Sincerely yours,
Takuma Inai
AIST

POST REPLY