Transform location wrt bodyframe to location wrt ground

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Lars Boers
Posts: 14
Joined: Thu Sep 06, 2018 2:23 am

Transform location wrt bodyframe to location wrt ground

Post by Lars Boers » Thu Jul 18, 2019 12:31 pm

Hi guys,

I was looking in the API references and I was wondering, is there a function that transforms a location (coordinates/ offsets of for example contact spheres/ markers) wrt a (parent) frame to a location wrt the ground (reference) frame? I want to iteratively calculate positions of objects in both the parent frame and ground frame at the same time for specific states within Matlab, and was wondering if there was an easy way to do this!

Regards,

Lars

Tags:

User avatar
jimmy d
Posts: 1375
Joined: Thu Oct 04, 2007 11:51 pm

Re: Transform location wrt bodyframe to location wrt ground

Post by jimmy d » Fri Jul 19, 2019 7:25 am

The frames (which Body is a type of frame) have methods to convert to different frames or to find transforms between frames.

Code: Select all

import org.opensim.modeling.*

model = Model('subject01_simbody.osim');
state = model.initSystem();

% Get some different frames
ground = model.getGround();
femur = model.getBodySet().get('femur_r');
tibia = model.getBodySet().get('tibia_r');

% Get a marker connected to the femur frame
marker = model.getMarkerSet().get(8).get_location();

% Convert location, velocity, and acceleration in the Ground
model.realizeAcceleration(state)
marker_ground = femur.findStationLocationInGround(state, marker);
marker_ground_v = femur.findStationVelocityInGround(state, marker);
marker_ground_a = femur.findStationAccelerationInGround(state, marker);

% Convert location, velocity, and acceleration in the tibia
marker_tibia = femur.findStationLocationInAnotherFrame(state, marker, tibia);

Code: Select all

% Get frame, position, velocity and acceleration in ground
femur_position = femur.getPositionInGround(state);
femur_rotation = femur.getRotationInGround(state);
femur_linear_vel = femur.getLinearVelocityInGround(state);
femur_linear_acc = femur.getLinearAccelerationInGround(state);
femur_angular_vel = femur.getAngularAccelerationInGround(state);
femur_angular_acc = femur.getAngularVelocityInGround(state);

% Get the Transform (translation and rotation) between two frames
T = femur.findTransformBetween(state, tibia);
% Get that translation
translation = T.p();
% Get the Rotation
rotation = T.R();

% Rotation in a Matlab matrix
rot = [rotation.get(0,0) rotation.get(0,1) rotation.get(0,2);...
       rotation.get(1,0) rotation.get(1,1) rotation.get(1,2);...
       rotation.get(2,0) rotation.get(2,1) rotation.get(2,2)];


POST REPLY