Page 1 of 2

Forward Dynamics Analyses in Matlab

Posted: Wed Feb 08, 2017 7:30 am
by godfreap
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!

Re: Forward Dynamics Analyses in Matlab

Posted: Wed Feb 08, 2017 2:57 pm
by aymanh
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

Re: Forward Dynamics Analyses in Matlab

Posted: Thu Feb 09, 2017 4:40 am
by godfreap
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

Re: Forward Dynamics Analyses in Matlab

Posted: Sat Feb 11, 2017 2:08 am
by tkuchida
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.
Analyses are added to the Model; the method is Model::addAnalysis() (https://simtk.org/api_docs/opensim/api_ ... c0ea8a4fd6). Something like this should work:

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();
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.
The prefix is the name of the ForwardTool object, which can be set as follows:

Code: Select all

ft = ForwardTool();
ft.setName('forwardToolResults');

Re: Forward Dynamics Analyses in Matlab

Posted: Mon Feb 13, 2017 4:59 am
by godfreap
Exactly what I was looking for. Thanks, Tom!

Re: Forward Dynamics Analyses in Matlab

Posted: Mon Feb 13, 2017 11:29 pm
by janthomas15
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

Re: Forward Dynamics Analyses in Matlab

Posted: Tue Feb 14, 2017 4:41 am
by godfreap
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!

Re: Forward Dynamics Analyses in Matlab

Posted: Tue Feb 14, 2017 12:19 pm
by jimmy
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.

Re: Forward Dynamics Analyses in Matlab

Posted: Fri Feb 17, 2017 4:35 am
by julian_atkinson
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

Re: Forward Dynamics Analyses in Matlab

Posted: Wed Feb 22, 2017 1:02 am
by julian_atkinson
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