Get joint location in parent / child

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Thomas Geijtenbeek
Posts: 431
Joined: Wed Mar 12, 2014 8:08 am

Get joint location in parent / child

Post by Thomas Geijtenbeek » Wed Dec 07, 2022 4:44 am

I know this question has been asked before, but I haven't been able to find a good answer:

What is the correct approach to get the location of a joint in the parent or child reference frame?

In OpenSim 3, this could be achieved through getLocationInParent() / getLocationInChild(), but these methods have been removed from the OpenSim 4 API.

I suspect I should use getParentFrame() / getChildFrame(), but I can't seem to figure out how to extract the local translation from a PhysicalFrame.

Tags:

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

Re: Get joint location in parent / child

Post by Ayman Habib » Thu Dec 08, 2022 2:39 pm

Hi Thomas,

As you correctly figured out, you can get handles to the frames using the getChildFrame/getParentFrame methods. Then you can use the "Frame" class methods to get the location and orientation of the frame in any other frame or ground as described here
https://simtk.org/api_docs/opensim/api_ ... Frame.html

Hope this helps,
-Ayman

User avatar
Thomas Uchida
Posts: 1778
Joined: Wed May 16, 2012 11:40 am

Re: Get joint location in parent / child

Post by Thomas Uchida » Thu Dec 08, 2022 7:41 pm

There's a section on Frames in the API Guide that might also be helpful: https://simtk.org/api_docs/opensim/api_ ... tml#frames.

User avatar
Thomas Geijtenbeek
Posts: 431
Joined: Wed Mar 12, 2014 8:08 am

Re: Get joint location in parent / child

Post by Thomas Geijtenbeek » Mon Dec 12, 2022 6:38 am

Thank you for the references.

I'm still somewhat confused though; from the API guide, I would expect to get a frame of type PhysicalOffsetFrame, on which I could then call getOffsetTransform() to get the (fixed) offset of the joint frame.

However, the getParent/ChildFrame() methods in Joint return a PhysicalFrame. This seems to only give me the following options to get the joint position in the parent/child body frame:
  1. call findTransformInBaseFrame()
  2. call findStationLocationInAnotherFrame() using the body frame
  3. call getPositionInGround() for both joint and body and transform back to the local frame of the body
All these methods are state-dependent, and appear to involve a bunch of extra work and computations. This seems unnecessary, since the joint frame offsets are constant and do not depend on the state (they are part of the model data structure).

Please let me know if I'm missing something obvious. Otherwise, which approach would you recommend?

User avatar
Nicos Haralabidis
Posts: 188
Joined: Tue Aug 16, 2016 1:46 am

Re: Get joint location in parent / child

Post by Nicos Haralabidis » Tue Dec 13, 2022 3:56 am

Hello,

I had some success with extracting the PhysicalOffsetFrame as follows in Matlab - OpenSim 4.3:

myModel = Model('2D_gait.osim');
hip_joint = myModel.getJointSet().get(1);
pelvis_offset = hip_joint.get_frames(0);
femur_offset = hip_joint.get_frames(1);
pelvis_offset_trans = pelvis_offset.get_translation();
pelvis_offset_rot = pelvis_offset.get_orientation();

Hopefully that is what you were looking for!

Best wishes,

Nicos Haralabidis

User avatar
Thomas Geijtenbeek
Posts: 431
Joined: Wed Mar 12, 2014 8:08 am

Re: Get joint location in parent / child

Post by Thomas Geijtenbeek » Thu Dec 15, 2022 3:57 am

Thank you, that was helpful.

It turns out there is a matching C++ interface to get the PhysicalOffsetFrame:

Code: Select all

auto locationInParent = joint.get_frames( 0 ).get_translation(); // parent?
auto locationInChild = joint.get_frames( 1 ).get_translation(); // child?
It works for my current model, but I'm not sure if it's safe. Index 0 and 1 might not always exist, and they might point to other frames than the child or parent frame.

POST REPLY