Forward Dynamics Analyses in Matlab
- Aaron Godfrey
- Posts: 55
- Joined: Tue Feb 16, 2016 12:34 pm
Forward Dynamics Analyses in Matlab
I'm having trouble finding a way to run the analyses within the GUI's Forward Dynamics tool. It seems like the primary methods available in the API - the direct ones such as BodyKinematics - might do the trick, but I am having trouble getting it to run, and since I can't get it to run, I also can't determine whether it will work correctly with models containing prescribed motion (as opposed to requiring a loaded .mot).
Within the Matlab API, how can one run the BodyKinematics analysis using Forward Dynamics? What specific command will run that analysis? (setting up tools is pretty straightforward, I'm not worried about that - I'm worried about having the correct method and the code that will make it start, since, for example, BodyKinematics.run() doesn't seem to work.)
Thanks!
Within the Matlab API, how can one run the BodyKinematics analysis using Forward Dynamics? What specific command will run that analysis? (setting up tools is pretty straightforward, I'm not worried about that - I'm worried about having the correct method and the code that will make it start, since, for example, BodyKinematics.run() doesn't seem to work.)
Thanks!
- Ayman Habib
- Posts: 2234
- Joined: Fri Apr 01, 2005 12:24 pm
Re: Forward Dynamics Analyses in Matlab
Hi Aaron,
The ForwardTool dialog of the GUI has "Analyses" tab that you could use to add/customize analyses that are run during Forward run. The "Add" button will show you the list of available Analyses that you can pick from and customize.
Hope this helps.
-Ayman
The ForwardTool dialog of the GUI has "Analyses" tab that you could use to add/customize analyses that are run during Forward run. The "Add" button will show you the list of available Analyses that you can pick from and customize.
Hope this helps.
-Ayman
- Aaron Godfrey
- Posts: 55
- Joined: Tue Feb 16, 2016 12:34 pm
Re: Forward Dynamics Analyses in Matlab
Hi Ayman,
Thanks for the response. I know how to run Forward Dynamics from the GUI. I'm asking how to run it from Matlab, specifically how to add an analysis, without relying on a pre-saved XML file to be loaded into it. There don't seem to be any commands I can find that allow you to add/delete analyses from within Matlab.
Also, is there a way to change the 'prefix' FD setting within Matlab? There doesn't seem to be a call to that (e.g. setPrefix) either.
Thanks,
Aaron
Thanks for the response. I know how to run Forward Dynamics from the GUI. I'm asking how to run it from Matlab, specifically how to add an analysis, without relying on a pre-saved XML file to be loaded into it. There don't seem to be any commands I can find that allow you to add/delete analyses from within Matlab.
Also, is there a way to change the 'prefix' FD setting within Matlab? There doesn't seem to be a call to that (e.g. setPrefix) either.
Thanks,
Aaron
- Thomas Uchida
- Posts: 1773
- Joined: Wed May 16, 2012 11:40 am
Re: Forward Dynamics Analyses in Matlab
Analyses are added to the Model; the method is Model::addAnalysis() (https://simtk.org/api_docs/opensim/api_ ... c0ea8a4fd6). Something like this should work:I know how to run Forward Dynamics from the GUI. I'm asking how to run it from Matlab, specifically how to add an analysis, without relying on a pre-saved XML file to be loaded into it. There don't seem to be any commands I can find that allow you to add/delete analyses from within Matlab.
Code: Select all
import org.opensim.modeling.*
model = Model('myModel.osim');
ma = MuscleAnalysis();
model.addAnalysis(ma);
ft = ForwardTool();
ft.setModel(model);
ft.setInitialTime(0.);
ft.setFinalTime(1.);
ft.run();
The prefix is the name of the ForwardTool object, which can be set as follows:Also, is there a way to change the 'prefix' FD setting within Matlab? There doesn't seem to be a call to that (e.g. setPrefix) either.
Code: Select all
ft = ForwardTool();
ft.setName('forwardToolResults');
- Aaron Godfrey
- Posts: 55
- Joined: Tue Feb 16, 2016 12:34 pm
Re: Forward Dynamics Analyses in Matlab
Exactly what I was looking for. Thanks, Tom!
- Jan Thomas
- Posts: 23
- Joined: Mon Aug 10, 2015 8:39 am
Re: Forward Dynamics Analyses in Matlab
Hi all,
I am trying to run the cmc tool from the following link
https://github.com/jimmyDunne/opensim-m ... iFunctions
I get the following errors when I run it with different directories set as current working folder. Can anyone please help me with this? Thanks in advance!
Jan
I am trying to run the cmc tool from the following link
https://github.com/jimmyDunne/opensim-m ... iFunctions
I get the following errors when I run it with different directories set as current working folder. Can anyone please help me with this? Thanks in advance!
Jan
- Attachments
-
- working folderJPG.JPG (88.33 KiB) Viewed 1359 times
-
- working folder script .JPG (126.51 KiB) Viewed 1359 times
- Aaron Godfrey
- Posts: 55
- Joined: Tue Feb 16, 2016 12:34 pm
Re: Forward Dynamics Analyses in Matlab
Hi Jon,
It looks like you don't have your filename typed in correctly. Typically a "file doesn't exist" error means there's a typo somewhere in your path. I'd double check that first, and make sure the path you've copied in for path2setupfile is valid, and that if that argument takes a file (vs. just a path) that the extension is included.
It could also just be open in some other program that's blocking access. Make sure that whatever you're trying to run isn't open in Excel or Word or anything like that.
Hope that helps!
It looks like you don't have your filename typed in correctly. Typically a "file doesn't exist" error means there's a typo somewhere in your path. I'd double check that first, and make sure the path you've copied in for path2setupfile is valid, and that if that argument takes a file (vs. just a path) that the extension is included.
It could also just be open in some other program that's blocking access. Make sure that whatever you're trying to run isn't open in Excel or Word or anything like that.
Hope that helps!
Re: Forward Dynamics Analyses in Matlab
Hi, Jan.
Your question is unrelated to this thread (Thanks, Aaron for helping). Can you please start a new forum thread where I can help you?
Thanks,
- James.
Your question is unrelated to this thread (Thanks, Aaron for helping). Can you please start a new forum thread where I can help you?
Thanks,
- James.
- Julian Atkinson
- Posts: 52
- Joined: Thu Feb 25, 2016 12:39 am
Re: Forward Dynamics Analyses in Matlab
Hi there
I am trying something similar with the AnalyzeTool.
When I print the setup file (analyzeTool.print) after adding an analysis and setting the model, as shown above, the AnalysisSet in the xml file is totally empty.
Thanks
Julian
I am trying something similar with the AnalyzeTool.
When I print the setup file (analyzeTool.print) after adding an analysis and setting the model, as shown above, the AnalysisSet in the xml file is totally empty.
Thanks
Julian
- Julian Atkinson
- Posts: 52
- Joined: Thu Feb 25, 2016 12:39 am
Re: Forward Dynamics Analyses in Matlab
Update:
So I have found a solution to my Muscle Analysis API problems. It is not the prettiest solution but I am now using the xml_read and xml_write functions to read a template xml file, update the tree in matlab, then print the updated tree as an xml file, then run it using the system function.
This appears to be working, and is a way around all the "Tools" problems I was experiencing.
Cheers,
Julian
So I have found a solution to my Muscle Analysis API problems. It is not the prettiest solution but I am now using the xml_read and xml_write functions to read a template xml file, update the tree in matlab, then print the updated tree as an xml file, then run it using the system function.
This appears to be working, and is a way around all the "Tools" problems I was experiencing.
Cheers,
Julian