Muscle attachment co-ordinates vs time?

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
User avatar
Karen Fitzgerald
Posts: 24
Joined: Mon Sep 08, 2014 6:03 am

Muscle attachment co-ordinates vs time?

Post by Karen Fitzgerald » Tue Feb 06, 2018 10:56 am

Hi there,

I was wondering if somebody could tell me if there is a way to view/extract muscle attachment co-ordinates as they change in time after I perform inverse kinematics to create a .mot file?
i.e. the xyz location relative to ground/a body etc...

Thanks!
1.001.jpeg
1.001.jpeg (115.34 KiB) Viewed 489 times

User avatar
Dimitar Stanev
Posts: 1096
Joined: Fri Jan 31, 2014 5:14 am

Re: Muscle attachment co-ordinates vs time?

Post by Dimitar Stanev » Wed Feb 07, 2018 2:53 am

This is not possible with the GUI. You can attach a marker for each point and report the marker position, however this requires laborious work. I suggest you to use Matlab or Python and get the points programmatically. Or you can implement your own plugin, where you will record the muscle points at each step (there is an example in the SDK folder).

https://simtk-confluence.stanford.edu:8 ... ng+Plugins

Programmatically, you have to access each muscle, then you get the GeometryPath and then the PathPointSet.

https://simtk.org/api_docs/opensim/api_ ... 05bbc0a7ab
https://simtk.org/api_docs/opensim/api_ ... yPath.html

User avatar
Karen Fitzgerald
Posts: 24
Joined: Mon Sep 08, 2014 6:03 am

Re: Muscle attachment co-ordinates vs time?

Post by Karen Fitzgerald » Wed Feb 07, 2018 7:09 am

Hi Dimitar,

Thanks for your reply. I have a few more questions for you if thats ok. I'm pretty new to coding with opensim so they might seem obvious to you but I'm unclear how to do it.

I tried getting the location of the muscle attachment programmatically like you suggested just using a script (see attached). This is fine for the default model position. Now my question is how do I get this for each time step of my inverse kinematics .mot? And can I choose to print the location in different co-ordinate systems (i.e. local/global xyz co-ordinate system).

Perhaps I need the plugin you suggested to do this. If so which example in the SDK folder would you suggest is the best place to start.

Thanks for the help!
Attachments
myScript.txt
(2.12 KiB) Downloaded 25 times

User avatar
Dimitar Stanev
Posts: 1096
Joined: Fri Jan 31, 2014 5:14 am

Re: Muscle attachment co-ordinates vs time?

Post by Dimitar Stanev » Thu Feb 08, 2018 2:12 am

Initialize the model and get the state:

Code: Select all

state = model.initSystem()
Iterate over time and coordinates and update the model pose from ik. Then realize the model to position stage and get the path points

Code: Select all

for t in time:
    for i, q in enumerate(coordinates(t)):
        model.updCoordinateSet().get(i).setValue(state, q)

    model.realizePosition(state)
    path_points = model.getMuscles().get(0).getGemoetryPath().getCurrentPath(state)

User avatar
Karen Fitzgerald
Posts: 24
Joined: Mon Sep 08, 2014 6:03 am

Re: Muscle attachment co-ordinates vs time?

Post by Karen Fitzgerald » Thu Feb 08, 2018 8:25 am

Hi Dimitar,

The logic you have suggested makes total sense to me however unfortunately I have been unable to get this to work. I don't really understand how you set the time t or what q is in your code example.
For the time do I need to extract it from a .mot file?

I moved to a matlab script as it is easier to use. I think your code is in Python which might be why I'm struggling to understand?

Here's what I have so far trying to implement what you suggested however I'm finding it difficult to find information on what arguments I need to use etc so your help is invaluable.

Thanks,

Karen
musclePathPoints.txt
(1.4 KiB) Downloaded 10 times

User avatar
Dimitar Stanev
Posts: 1096
Joined: Fri Jan 31, 2014 5:14 am

Re: Muscle attachment co-ordinates vs time?

Post by Dimitar Stanev » Thu Feb 08, 2018 10:23 am

The code that I posted is a pseudo-code, with the actual API calls that you must call. You can iterate over your motion file. Each row of the motion file (from IK) contains the coordinate values at a particular time instance. Access those coordinates and update the corresponding coordinates of the model. Make sure to call the getCurrentPath providing the state of the model in your code.

https://simtk.org/api_docs/opensim/api_ ... orage.html

q: value of the coordinate at time t
i: is the index corresponding to model coordinate

User avatar
Karen Fitzgerald
Posts: 24
Joined: Mon Sep 08, 2014 6:03 am

Re: Muscle attachment co-ordinates vs time?

Post by Karen Fitzgerald » Thu Feb 08, 2018 12:24 pm

Hi thanks for the reply.

So I understand what I am trying to do i.e the pseudo-code however it is the implementation that is tripping me up.

i.e "Access those coordinates and update the corresponding coordinates of the model."

I cannot find an example that does this in the available matlab example scripts. And I'm finding the doxygen documentation hard to follow, especially the arguments to pass the different functions. Is there somewhere else I can look for suitable examples?

Sorry for all the questions but I'm a total novice really.

Thank you so much for all the help.

User avatar
Karen Fitzgerald
Posts: 24
Joined: Mon Sep 08, 2014 6:03 am

Re: Muscle attachment co-ordinates vs time?

Post by Karen Fitzgerald » Thu Feb 08, 2018 12:39 pm

I think the code belwo is right up until:

Code: Select all

model.updCoordinateSet().get(i).setValue(state, coordvalue);
Matlab gives an error for setValue(state, cooordavlue), think I'm passing it the wrong arguments?

Code: Select all

% musclePathPoints.m                                                        
% Author: Karen Fitzgerald, University College Dublin

import org.opensim.modeling.*

% Read in osim model
modelFile = strcat('testData\myModel',filesep,'scaledModel.osim');
%Create the OpenSim model from a .osim file
model = Model(modelFile);
state = model.initSystem;

  
[Mot_In, motpath] = uigetfile('.mot', 'Please select a motion file');

motfilepath = strcat('testData\myModel\mot\',filesep,'walk.mot');
motfilepath = [motpath Mot_In];


% Create the coordinate storage object from the input .mot file
motSto=Storage(motfilepath);

nMotSto=motSto.getSize();

coords = osimModel.getCoordinateSet();
nCoords = coords.getSize();


    
    for i=0:nCoords-1
        
        Time=ArrayDouble();
        coordvalue = ArrayDouble();
        
        % Get the coordinate set from the model
        currentcoord = coords.get(i);

        % Get the Time stamps and Coordinate values
        motSto.getTimeColumn(Time);
        motSto.getDataColumn(currentcoord.getName(),coordvalue); 
        
        model.updCoordinateSet().get(i).setValue(state, coordvalue);
    end

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

Re: Muscle attachment co-ordinates vs time?

Post by Thomas Uchida » Thu Feb 08, 2018 11:59 pm

I think the code belwo is right up until: model.updCoordinateSet().get(i).setValue(state, coordvalue);
coordvalue is the wrong type (it's an ArrayDouble and you must pass in a double). Please see the API documentation for the Coordinate::setValue() method here: https://simtk.org/api_docs/opensim/api_ ... 0004213229.

User avatar
Karen Fitzgerald
Posts: 24
Joined: Mon Sep 08, 2014 6:03 am

Re: Muscle attachment co-ordinates vs time?

Post by Karen Fitzgerald » Fri Feb 09, 2018 5:00 am

Hi Tom,

Thanks for the reply. I fixed that and think I have the co-ordinate values updating correctly. However when I try to

Code: Select all

model.realizePosition(state)
which I'm guessing updates the model to new co-ordinate position I get a "Unidentified function or variable" error in matlab. I'm guessing I'm passing it the wrong argument but not sure what I should be passing it.

I'm nearly there I think just can't get the last bit of code (commented out at the bottom), which updates model and reads the current location of the path points to work.

Thanks everyone for your help.

Code: Select all

% musclePathPoints.m                                                        
% Author: Karen Fitzgerald, University College Dublin

import org.opensim.modeling.*

% Read in osim model
modelFile = strcat('testData\myModel',filesep,'scaledModel.osim');
%Create the OpenSim model from a .osim file
model = Model(modelFile);
state = model.initSystem;

  
[Mot_In, motpath] = uigetfile('.mot', 'Please select a motion file');

motfilepath = strcat('testData\myModel\mot\',filesep,'walk.mot');
motfilepath = [motpath Mot_In];


% Create the coordinate storage object from the input .mot file
motSto=Storage(motfilepath);

nMotSto=motSto.getSize();
timeStep=motSto.getMinTimeStep();

coords = osimModel.getCoordinateSet();
nCoords = coords.getSize();


for j = 0:nCoords-1 
        
        coordvalue = ArrayDouble();
        currentcoord = coords.get(j);
        motSto.getDataColumn(currentcoord.getName(),coordvalue);
        q = coordvalue.getitem(0);
        disp(q)
            
            for i=0:nCoords-1
                model.updCoordinateSet().get(i).setValue(state, q);         
            end
            
end

%model.realizePosition(state);


     path_points = model.getMuscles().get("rect_fem_r")

%Get a handle to the pathPoints for muscle
%    path_points = model.getMuscles().get("rect_fem_r").getGemoetryPath().getCurrentPath(state)
       
%     %Get location of this point
%    %recFemPathPoint1 = pathPoints.get("rect_fem_r-P1").getLocation();
%     
%    disp(path_points)


POST REPLY