Page 1 of 1
plugin help
Posted: Tue May 05, 2009 9:04 am
by dwwagner
Hi all,
I have been learning about the Opensim plugin features and have been able to follow the instructions on how to build and run (and then edit) the AnalysisTemplate plugin. However, I would like to be able to incorporate some of the values that can be calculated in the muscleAnalysis (in the Analyze tool). I haven't been able to successfully create a muscleAnalysis object and have it run within my plugin.
In the header file I have added the following line:
MuscleAnalysis _my_MuscleAnalysis;
I added the following lines to the plugin constructor
_my_MuscleAnalysis = MuscleAnalysis(aModel);
_my_MuscleAnalysis.setModel(aModel);
_my_MuscleAnalysis.setMuscles(_bodyNames);
_my_MuscleAnalysis.setCoordinates(_bodyNames); //where _bodyNames is an Array of strings with the first value set to 'all'
And then I tried to add the following lines to the begin, step, and end functions (respectively)
_my_MuscleAnalysis.begin(aStep,aDT,aT,aX,aY,aYP,aDYDT,aClientData);
_my_MuscleAnalysis.step(aXPrev,aYPrev,aYPPrev,aStep,aDT,aT,aX,aY,aYP,aDYDT,aClientData);
_my_MuscleAnalysis.end(aStep,aDT,aT,aX,aY,aYP,aDYDT,aClientData);
Everything compiles, but when I call the plugin through the analyze tool, I get the following error:
'Tool execution failed or canceled by user. Output files were not written'
If I comment out the .begin call, I do not get the error, but nothing happens when I make try to printResults on the _my_MuscleAnalysis.
Any ideas would be much appreciated. Thank you in advance.
-David
RE: plugin help
Posted: Tue May 05, 2009 9:21 am
by aymanh
Hi David,
I'm not sure what value you have for _bodyNames but the line
_my_MuscleAnalysis.setMuscles(_bodyNames);
doesn't look right (you should be using "muscle" names rather than "body" names.
And I'm also not clear what do you mean by add the lines _my_MuscleAnalysis.begin(.....);
You shouldn't be adding the lines you should be implementing or modifying the implementation of these methods and they should get automatically called at the proper times if you setup your Tool correctly.
Finally if you believe a specific line is causing the problem then add some print statements to zone in on it.
BTW: what version of visual studio are you using?
RE: plugin help
Posted: Tue May 05, 2009 1:25 pm
by dwwagner
Hi Ayman,
I am using Visual C++ 2008 Express Edition.
I don't think I am setting tool up correctly. I am fairly new to C++ so I may be getting some issues confused. I understand that in building the AnalysisTemplate_plugin, the begin(), step(), and end() functions will get automatically called when I run the analysis. What I don't understand is how to have Opensim evaluate an instantiated muscleAnalysis within the AnalysisTemplate_plugin (presumably by also calling the associated begin(), step() and end() functions documented in muscleAnalysis.h) without explicitly adding it...
As for adding some print statements, I have added them but don't see any output. Do I have to do something more than adding printf("Hello World!");??
Thanks for your help.
Best,
David
RE: plugin help
Posted: Wed May 06, 2009 1:43 pm
by aymanh
David,
The analysis has to be added to the "Tool". Either using the Tools/Analyze../Analyses(tab) in the GUI, then add your analysis from the popup list of the Add button, or by adding it to the XML setup file used to run a forward simulation.
For printing, you may want to write to a file just in case..
Good Luck,
-Ayman
RE: plugin help
Posted: Thu May 07, 2009 9:16 am
by dwwagner
Hi Ayman,
Thanks for the reply. Let me try phrasing my question in another way, because I have had no problem adding my plugin to the Analyze "Tool" and running it.
My question is that if someone else has created a plugin (otherPlugin) where I don't have access to the source code, is it possible to have my plugin (myPlugin) run the otherPlugin so I can get at the data that is calculated during the otherPlugin call. Another way for me to do this would be to add the otherplugin to the analyze tool and have myplugin access the data calculated in the otherplugin after each time step is solved for. Hope this makes sense and you can give me some direction.
I got the printing to a file to work, so that should help with debugging some of the other issues.
Thank you in advance,
David
RE: plugin help
Posted: Thu May 07, 2009 1:54 pm
by aymanh
Hi David,
You asked
>is it possible to have (myPlugin) run the otherPlugin so I can get at the data that is calculated during the (otherPlugin) call.
The problem is that there's no vehicle to pass the data calculated in "otherPlugin" back to "myPlugin". The plugin could be just recording values to a file and not computing anything.
In the general case you'd need to communicate the results you want using a file (or Storage objects).
You probably can get your original code to work by calling
__my_MuscleAnalysis.setModel(_model);
before the first call to "begin" but you still have to deal with how to pass "data" back.
Hope this helps,
-Ayman
RE: plugin help
Posted: Thu May 07, 2009 2:09 pm
by dwwagner
Hi Ayman,
Thanks for the help so far. I think I am making progress. I have been able to replicate the results of including muscleAnalysis in the Analyze tool by instantiating a muscleAnalysis object in the .begin() call (and setting the muscles and model) and then adding _myMuscleAnalysis.step() calls to myPlugin.step(), _myMuscleAnalysis.end() calls to myPlugin.end(), and _myMuscleAnalysis.printResults() calls to myPlugin.printResults().
I hope to be able to get at the data I care about from the _myMuscleAnalysis by using the provided get functions (i.e. getForceStorage). I will post if I am able to get this to work.
Maybe I am going about this backward. But lets say I wanted to write an analysis plugin that outputs all the forces in each muscle multiplied by the number 5 (or some other variable I have in my plugin...I just like 5 for now). My thought was that I could just use the code that has already been written that calculates/outputs the muscle forces (i.e. muscleAnalysis). If I can't (or if this was not the intention), then I would need to write my own functions that would do this...which would seem to be a waste of some of the great code that has already been implemented by the Opensim team.
Best,
David
RE: plugin help
Posted: Mon May 11, 2009 6:21 pm
by dwwagner
Hi again,
Some more questions....
1. Is there any place that I can see the source code for the muscleAnalysis Analysis? (The reason being I think the answers to my following questions would be in there).
2. Is there an 'easy' way to loop through all the muscles in the model? Right now I am looping through all the _model->getActuators(), and then using an if statement to check if the AbstractActuator isA "Thelen2003Muscle". If it is, I am dynamically casting a pointer to the AbstractActuator to be the Thelen2003Muscle. Any additional guidance on this would be most appreciated.
3. Similar question regarding the contact points (origin, insertion, via, and wrapped) associated with each muscle. Is there an easy way to loop through those points (assuming I have a reference to a muscle object)?
Thank you in advance.
Best,
David
RE: plugin help
Posted: Tue Mar 15, 2011 10:19 am
by nelaraby
Hi,
I am trying to do the developer's guide tutorial on the AnalysisTemplate plugin, but I get the following error message:
Build started: Project: Libraries - myAnalysisPlugin, Configuration: Release Win32 ------
1>Compiling...
1>RegisterTypes_osimPlugin.cpp
1>..\plugin\RegisterTypes_osimPlugin.cpp(30) : fatal error C1083: Cannot open include file: 'OpenSim/Common/Object.h': No such file or directory
1>MyAnalysis.cpp
1>..\plugin\MyAnalysis.cpp(35) : fatal error C1083: Cannot open include file: 'OpenSim/Simulation/Model/Model.h': No such file or directory
I would really appreciate it if you tell me how to fix that error.
Thank you,
Nashwa
RE: plugin help
Posted: Wed Mar 16, 2011 12:54 pm
by aymanh
Hi Nashwa,
You only need to include <OpenSim/OpenSim.h> and that in turns includes all other OpenSim internal headers.
Hope this helps,
-Ayman