Forward Dynamics Analyses in Matlab

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
User avatar
Aaron Godfrey
Posts: 55
Joined: Tue Feb 16, 2016 12:34 pm

Forward Dynamics Analyses in Matlab

Post by Aaron Godfrey » Wed Feb 08, 2017 7:30 am

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!

User avatar
Ayman Habib
Posts: 2234
Joined: Fri Apr 01, 2005 12:24 pm

Re: Forward Dynamics Analyses in Matlab

Post by Ayman Habib » Wed Feb 08, 2017 2:57 pm

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

User avatar
Aaron Godfrey
Posts: 55
Joined: Tue Feb 16, 2016 12:34 pm

Re: Forward Dynamics Analyses in Matlab

Post by Aaron Godfrey » Thu Feb 09, 2017 4:40 am

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

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

Re: Forward Dynamics Analyses in Matlab

Post by Thomas Uchida » Sat Feb 11, 2017 2:08 am

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');

User avatar
Aaron Godfrey
Posts: 55
Joined: Tue Feb 16, 2016 12:34 pm

Re: Forward Dynamics Analyses in Matlab

Post by Aaron Godfrey » Mon Feb 13, 2017 4:59 am

Exactly what I was looking for. Thanks, Tom!

User avatar
Jan Thomas
Posts: 23
Joined: Mon Aug 10, 2015 8:39 am

Re: Forward Dynamics Analyses in Matlab

Post by Jan Thomas » Mon Feb 13, 2017 11:29 pm

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
Attachments
working folderJPG.JPG
working folderJPG.JPG (88.33 KiB) Viewed 1359 times
working folder script .JPG
working folder script .JPG (126.51 KiB) Viewed 1359 times

User avatar
Aaron Godfrey
Posts: 55
Joined: Tue Feb 16, 2016 12:34 pm

Re: Forward Dynamics Analyses in Matlab

Post by Aaron Godfrey » Tue Feb 14, 2017 4:41 am

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!

User avatar
jimmy d
Posts: 1375
Joined: Thu Oct 04, 2007 11:51 pm

Re: Forward Dynamics Analyses in Matlab

Post by jimmy d » Tue Feb 14, 2017 12:19 pm

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.

User avatar
Julian Atkinson
Posts: 52
Joined: Thu Feb 25, 2016 12:39 am

Re: Forward Dynamics Analyses in Matlab

Post by Julian Atkinson » Fri Feb 17, 2017 4:35 am

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

User avatar
Julian Atkinson
Posts: 52
Joined: Thu Feb 25, 2016 12:39 am

Re: Forward Dynamics Analyses in Matlab

Post by Julian Atkinson » Wed Feb 22, 2017 1:02 am

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

POST REPLY