Automate plotting of motion
- Joel Quarnstrom
- Posts: 15
- Joined: Sat Mar 02, 2019 6:18 pm
Automate plotting of motion
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
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 (73.54 KiB) Viewed 399 times
Tags:
- Thomas Uchida
- Posts: 1793
- Joined: Wed May 16, 2012 11:40 am
Re: Automate plotting of motion
There are example scripts in your OpenSim installation directory, under Resources\Code\GUI (e.g., C:\OpenSim4.0\Resources\Code\GUI):I have been able to plot this manually, but I am looking for a way to automate the process.
- 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.
- Joel Quarnstrom
- Posts: 15
- Joined: Sat Mar 02, 2019 6:18 pm
Re: Automate plotting of motion
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?
- Thomas Uchida
- Posts: 1793
- Joined: Wed May 16, 2012 11:40 am
Re: Automate plotting of motion
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--.
- 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--.
- Joel Quarnstrom
- Posts: 15
- Joined: Sat Mar 02, 2019 6:18 pm
Re: Automate plotting of motion
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
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 (69.89 KiB) Viewed 331 times
- Thomas Uchida
- Posts: 1793
- Joined: Wed May 16, 2012 11:40 am
Re: Automate plotting of motion
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
- Joel Quarnstrom
- Posts: 15
- Joined: Sat Mar 02, 2019 6:18 pm
Re: Automate plotting of motion
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
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
- Thomas Uchida
- Posts: 1793
- Joined: Wed May 16, 2012 11:40 am
Re: Automate plotting of motion
Please read the "Scripting" page in the Confluence documentation: https://simtk-confluence.stanford.edu:8 ... /Scriptingis the OpenSim scripting python code?
Please see the example scripts.how do I create a loop that runs through the same code multiple times?
- Joel Quarnstrom
- Posts: 15
- Joined: Sat Mar 02, 2019 6:18 pm
Re: Automate plotting of motion
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?
Also, do you know if it is possible for a script to open a macro enabled excel file and run a macro?
- Joel Quarnstrom
- Posts: 15
- Joined: Sat Mar 02, 2019 6:18 pm
Re: Automate plotting of motion
Or is it possible for a c++ program to open OpenSim and run a script?