This page is for topics related the steps before running the tools in Open Sim such as getting raw data into an Open Sim-friendly format or creating setup files.

Getting Motion Capture Data into OpenSim

Got suggestions for this? Add them here!

Setup Files

Setup files are a great way to organize and iterate your Open Sim work. When viewed with an XML reader they are a useful tool when you're developing a simulation and need to go through several rounds of prototyping, or when you've achieved the results you want and need to keep a record of how you did it. You can load, edit, and save Setup Files in the GUI, but you can also work with them directly in an XML editor such as Notepad++. (Notepad++ can be downloaded for free.)

Batch Creation of Setup Files

If you're doing a lot of similar simulations (e.g. inverse kinematics for 20 trials from the same subject) and have a setup file that applies settings that work well for one, you may want to generate many setup files to apply the same settings consistently. Matlab has some native XML commands that can help you do this quickly.

Here's an example of a very simple inverse kinematics setup file that uses a model specified in another file ../myscaledmodel.osim and a set of IK tasks specified in my_IK_tasks.xml to perform and inverse kinematics calculation on a set of maker data ./trialMarkerData.trc from an initial_time 0 to a final_time 10, and outputs the results to a file called ../IKResults/Trialname.mot.

<?xml version="1.0" encoding="utf-8"?>

<IKTool name="GenericIKToolName">
        <!--Name of the .osim file used to construct a model.-->  
   <model_file> '''../myscaledmodel.osim'''   </model_file>
        <!--Preferred optimizer algorithm (currently support "ipopt" or "cfsqp",
            the latter requiring the osimFSQP library.-->
   <optimizer_algorithm> cfsqp </optimizer_algorithm>
        <!--Task set used to specify IK weights.-->
   <IKTaskSet file='''"my_IK_tasks.xml"'''/>
        <!--Parameters for solving the IK problem for each trial. Each trial
            should get a seperate SimmIKTril block.-->
   <IKTrialSet name="">
         <IKTrial name="Trialnamegoeshere">
                <!--TRC file (.trc) containing the time history of experimental marker
                                <!--Time range over which the IK problem is solved.-->
            <time_range>0 10</time_range>
                <!--Name of the motion file (.mot) to which the results should be written.-->

Let's say you wanted to generate new set up file that changes six things:

(The first two aren't necessary to change the simulation, but are used to automatically name the output files. Renaming them will help organize results.)

Step 1

In Matlab, navigate to the directory where your setup file lives and read in the setup file generic_setup.xml

xmlDoc = xmlread('generic_setup.xml');

Step 2

Create the strings and values for the five things that you'll change in the new xml document.

toolname = 'SpecificIKToolName';

trialname = 'myfirsttrial';

markerfile = 'myfirsttrialmarkers.trc';

initial_time = 1;

final_time = 6.5;

Step 3

Now we'll find some attributes of xmlDoc and change them. There is some trial and error involved here for adjusting this to your specific case. You may have to change the levels involved, but this should work for the structure of the setup file above.

xmlDoc.getElementsByTagName('IKTrial').item(0).getAttributes.item(0).setValue(trialname);  xmlDoc.getElementsByTagName('marker_file').item(0).getFirstChild.setNodeValue(markerfile);
xmlDoc.getElementsByTagName('time_range').item(0).getFirstChild.setNodeValue([num2str(initial_time) ' ' num2str(final_time)]);

If these specific paths return errors, try checking the higher levels by doing things like:




and seeing what is returned. There are some nice auto-complete features of these commands that are helpful for navigating.

Step 4

Write the modified xmlDoc to a new xml setup file called mymodifiedsetup.xml

xmlwrite('mymodifiedsetup.xml', xmlDoc);

These steps can be modified for any type of xml setup file

What Other Topics Should Be Covered Here?

PreProcessing (last edited 2016-05-04 22:06:30 by localhost)