Automate plotting of motion

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
User avatar
Joel Quarnstrom
Posts: 15
Joined: Sat Mar 02, 2019 6:18 pm

Automate plotting of motion

Post by Joel Quarnstrom » Wed Jun 19, 2019 2:24 pm

Hello,

I am very new to OpenSim and object oriented programming in general. I am trying to write a script in the GUI to plot muscle tendon length for the Biceps Long Head muscle vs results. I have a model and motion file. I have been able to plot this manually, but I am looking for a way to automate the process.

The main thing I am trying to figure out is how to utilize the results of a motion file in the GUI scripting, and plot it against a muscle.

I attached a screen shot of the plot that I am trying to recreate through a script.

Thank you,
Joel
Attachments
Opensim capture.JPG
Opensim capture.JPG (73.54 KiB) Viewed 400 times

Tags:

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

Re: Automate plotting of motion

Post by Thomas Uchida » Wed Jun 19, 2019 6:54 pm

I have been able to plot this manually, but I am looking for a way to automate the process.
There are example scripts in your OpenSim installation directory, under Resources\Code\GUI (e.g., C:\OpenSim4.0\Resources\Code\GUI):
- plotMuscleFiberLengthAgainstFile.py
- plotMuscleMomentArmAgainstMotion.py
If you haven't already, you can install these example files (models, scripts, etc.) by typing installResources() in the Scripting Shell. The scripts can also be viewed here: https://github.com/opensim-org/opensim- ... im/Scripts.

User avatar
Joel Quarnstrom
Posts: 15
Joined: Sat Mar 02, 2019 6:18 pm

Re: Automate plotting of motion

Post by Joel Quarnstrom » Thu Jun 20, 2019 11:49 am

I have been looking through those documents, but I am unsure how to use results with those commands. Do you know how to reference the results of a motion with the plotting commands?

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

Re: Automate plotting of motion

Post by Thomas Uchida » Thu Jun 20, 2019 2:44 pm

Please see the "Scripting in the GUI" page in the Confluence documentation (https://simtk-confluence.stanford.edu:8 ... in+the+GUI). There are links to the following doc pages under the "Interacting with the GUI (including the Plotter)" heading:
- https://simtk.org/api_docs/opensim/gui_ ... otter.html
- https://simtk.org/api_docs/opensim/gui_ ... e/gui.html
The last link lists getCurrentMotion() here: https://simtk.org/api_docs/opensim/gui_ ... ntMotion--.

User avatar
Joel Quarnstrom
Posts: 15
Joined: Sat Mar 02, 2019 6:18 pm

Re: Automate plotting of motion

Post by Joel Quarnstrom » Fri Jun 21, 2019 2:29 pm

I looked at those links and had some success, I was able to create a plot of a muscle fiber-length against a joint angle, but I was unable to plot the fiber-length against the results. Here is my code, and a screen shot of the plot.
Here is my code:


loadModel("D:\Oklahoma State University\Research on Stroke device\OpenSim\My Stuff\Fourbarmodel.osim");

plotterPanel = createPlotterPanel("Plot Example")

motionfilePath = "D:\Oklahoma State University\Research on Stroke device\OpenSim\My Stuff\Arm motion 6-17-2019.mot";
motSrc = addMotionSource(plotterPanel, motionfilePath)

motiondata = addDataSource(plotterPanel, motionfilePath)

Motion = loadMotion(motionfilePath)

currentmotion = getCurrentMotion()

Curve = addAnalysisCurve(plotterPanel, "fiber-length" , "BIClong", "elbow_flexion")



The I also changed the last line to:

Curve = addAnalysisCurve(plotterPanel, "fiber-length" , "BIClong", "Results(Deg.)")

But it didn't produce a graph at all.

Do you know how to use the results from a motion with the addAnalysisCurve function?

Thank you,
Joel
Attachments
Opensim capture2.JPG
Opensim capture2.JPG (69.89 KiB) Viewed 332 times

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

Re: Automate plotting of motion

Post by Thomas Uchida » Fri Jun 21, 2019 4:48 pm

Have you tried addCurve()? It's listed below addAnalysisCurve() in the documentation: https://simtk.org/api_docs/opensim/gui_ ... otter.html. Please see runTutorialOne.py (line 118) for an example: https://github.com/opensim-org/opensim- ... ne.py#L118

User avatar
Joel Quarnstrom
Posts: 15
Joined: Sat Mar 02, 2019 6:18 pm

Re: Automate plotting of motion

Post by Joel Quarnstrom » Tue Jun 25, 2019 3:50 pm

Thank you for your help.

Another question, is the OpenSim scripting python code? Also, how do I create a loop that runs through the same code multiple times?

Thank you,
Joel Quarnstrom

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

Re: Automate plotting of motion

Post by Thomas Uchida » Tue Jun 25, 2019 4:58 pm

is the OpenSim scripting python code?
Please read the "Scripting" page in the Confluence documentation: https://simtk-confluence.stanford.edu:8 ... /Scripting
how do I create a loop that runs through the same code multiple times?
Please see the example scripts.

User avatar
Joel Quarnstrom
Posts: 15
Joined: Sat Mar 02, 2019 6:18 pm

Re: Automate plotting of motion

Post by Joel Quarnstrom » Wed Jun 26, 2019 2:35 pm

Thank you, that documentation was helpful.

Also, do you know if it is possible for a script to open a macro enabled excel file and run a macro?

User avatar
Joel Quarnstrom
Posts: 15
Joined: Sat Mar 02, 2019 6:18 pm

Re: Automate plotting of motion

Post by Joel Quarnstrom » Fri Jun 28, 2019 1:08 pm

Or is it possible for a c++ program to open OpenSim and run a script?

POST REPLY