Page 1 of 1
Get joint location in parent / child
Posted: Wed Dec 07, 2022 4:44 am
by tgeijten
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.
Re: Get joint location in parent / child
Posted: Thu Dec 08, 2022 2:39 pm
by aymanh
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
Re: Get joint location in parent / child
Posted: Thu Dec 08, 2022 7:41 pm
by tkuchida
There's a section on Frames in the API Guide that might also be helpful:
https://simtk.org/api_docs/opensim/api_ ... tml#frames.
Re: Get joint location in parent / child
Posted: Mon Dec 12, 2022 6:38 am
by tgeijten
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:
- call findTransformInBaseFrame()
- call findStationLocationInAnotherFrame() using the body frame
- 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?
Re: Get joint location in parent / child
Posted: Tue Dec 13, 2022 3:56 am
by nicos1993
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
Re: Get joint location in parent / child
Posted: Thu Dec 15, 2022 3:57 am
by tgeijten
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.