How to get orientation of body in Matlab?

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Evan Dooley
Posts: 25
Joined: Fri Sep 27, 2019 8:36 am

How to get orientation of body in Matlab?

Post by Evan Dooley » Wed Jun 02, 2021 10:00 am

Hello,

I am trying to get the rotation of a body frame, either relative to the global frame, or to another body frame, using Matlab.

I have been able to get the global positions of the bodies, and convert them to Matlab arrays, using this method:

Code: Select all

%% get global body position
hand_L_pos = osimVec3ToArray(HAND_L.getPositionInGround(start)); % take in current state
hand_R_pos = osimVec3ToArray(HAND_R.getPositionInGround(start)); % give global position
handle_L_pos = osimVec3ToArray(HANDLE_L.getPositionInGround(start));
handle_R_pos = osimVec3ToArray(HANDLE_R.getPositionInGround(start));
However, using a similar command for rotation defined in the methodsview "body.getRotationInGround(state)" gives an object of type
SWIGTYPE_p_SimTK__Rotation_T_SimTK__Real_t
Is there a way to convert this to a usable form in Matlab? Or is there another method that I could use to get the body rotation/orientation?

I am trying to define the initial offset between the two bodies and the orientation matters in this case. Any thoughts/recommendations/advice would be greatly appreciated.

Thanks for your help,
Evan

Tags:

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

Re: How to get orientation of body in Matlab?

Post by Ayman Habib » Wed Jun 02, 2021 10:26 am

Hi Evan,

You can use

Code: Select all

getTransformInGround()
call, and then extract the Rotation part from the Transform. The tools we use to expose the C++ methods to Matlab appear to be have missed this call (likely due to missing a Template expansion). Please file a bug and we'll look into it.

Best regards,
-Ayman

User avatar
Evan Dooley
Posts: 25
Joined: Fri Sep 27, 2019 8:36 am

Re: How to get orientation of body in Matlab?

Post by Evan Dooley » Wed Jun 02, 2021 2:20 pm

Hi Ayman,

Thanks for the speedy response.

I reported the bug and have tried your suggestion.

Code: Select all

% handle L
x = HANDLE_L.getTransformInGround(start);
y = x.R;
handle_L_rot = y.convertRotationToBodyFixedXYZ(); 
This gives me the X,Y,Z rotation angles from ground to each body, which is great. I think I need to get one rotation in terms of the parent body for the bushing I'm creating and was wondering if there's a way to get the rotation out/into a Matlab array?

I can take the rotation to a Mat33 object (y.toMat33), but I cannot convert this to a Matlab array. Am I just missing something in the documentation?

Any advice for this issue?

Thanks for all your help,
Evan

POST REPLY