Follow Markers

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Aaron Godfrey
Posts: 55
Joined: Tue Feb 16, 2016 12:34 pm

Follow Markers

Post by Aaron Godfrey » Mon Mar 14, 2016 10:50 am

Hello All,
I am trying to create a volume sweep of a model's movement, and that requires me to have the position of every marker at every time step in the .mot file. However, as far as I have seen, you can't obtain a record of marker positions - only bodies. (I thought I had found a way to find marker positions earlier, but it turned out to only be returning body positions instead.)

Are there any commands - preferably in Matlab - to fetch a particular marker's position at a given time? My impression thus far is that the API is only good for accessing a static model, where you can't really load a motion or step through it in the way I'd imagine is necessary for this analysis (similar to how you can analyze an AVI in Matlab frame-by-frame). If this isn't possible, what are some other possibilities for obtaining a volume sweep of a particular motion? Are there any addons or plugins that can do this?

Thanks!

User avatar
Brad Humphreys
Posts: 79
Joined: Thu Feb 03, 2011 11:32 am

Re: Follow Markers

Post by Brad Humphreys » Mon Mar 14, 2016 1:47 pm

Here is a MATLAB code snippet (easily made into a function) that gets marker locations via the API. Set the coords (q) and it creates a matrix with marker locations (markerLoc) in the ground body CS:

Code: Select all

% Set the angles of the coordinates (rad).  In Arm26, there are 2 coords:
q=[0 0];

% Load Library
import org.opensim.modeling.*;

% Open a Model by name
osimModelName='arm26.osim';
osimModel = Model(osimModelName);

% Initialize the system and get the initial state
osimState = osimModel.initSystem();

% Get the number of coords and markers
nCoords=osimModel.getCoordinateSet().getSize();
nMarkers=osimModel.getMarkerSet().getSize();

%Get all of the names of the markers
for i=0:nMarkers-1;
    markerNames{i+1}=char(osimModel.getMarkerSet.get(i));
end

%Loop through the coords and set values
for i=1:nCoords
    osimModel.getCoordinateSet().get(i-1).setValue(osimState,q(i));
end

%Realize the model
osimModel.equilibrateMuscles(osimState)

%Get the simbody engine
simbodyEngine = osimModel.getSimbodyEngine();

%Get the ground body
groundBody=simbodyEngine.getGroundBody();

pout=Vec3;  %Make a dummy vector for updating

%Now loop through all of the markers and get their location
for k=0:nMarkers-1
    marker=osimModel.getMarkerSet().get(k);  %Get marker
    mpos=marker.getOffset();                    %Get offset
    body=osimModel.getBodySet().get(marker.getBodyName());  %Get the body
    %Let Simbody do the hardwork
    simbodyEngine.transformPosition(osimState,body,mpos,groundBody,pout) 
    
    %Write to a matrix where each row is a marker 
    markerLoc(k+1,1)=pout.get(0);
    markerLoc(k+1,2)=pout.get(1);
    markerLoc(k+1,3)=pout.get(2);
end

User avatar
Aaron Godfrey
Posts: 55
Joined: Tue Feb 16, 2016 12:34 pm

Re: Follow Markers

Post by Aaron Godfrey » Tue Mar 15, 2016 5:24 am

Thanks!
Minor improvement: it looks like q is tied to nCoords, which is defined on Line 15. The code can be generalized by commenting out line 2 (q = [0 0]) and inserting at line 16:

Code: Select all

q = zeros(1, nCoords);
This, of course, assuming that anyone else stumbling upon this page also wants to set all coordinate angles to zero.

POST REPLY