Page 1 of 1

plugin in Matlab

Posted: Mon Feb 22, 2016 8:03 am
by bjdekruif
Hello all,

Thanks for reading this post. I wrote a plugin for a controller and would like to use the model with this controller from within Matlab. The plugin works when I use it in OpenSim, but I cannot get the model to work in Matlab. I get stuck in the first step in which I try to load the plugin in Matlab.

There is already some information on this topic:
http://simtk-confluence.stanford.edu:80 ... ng+Plugins
https://simtk.org/forums/viewtopic.php? ... tlab#p8878
https://simtk.org/forums/viewtopic.php? ... ary#p11969

However, this doesn't help me to get it to work. I have copied the files MyController.dll to the plugin directory of Opensim. Then I added the path to the plugin directory to librarypath.txt, and tried to load the dll with:

Code: Select all

loadlibrary('MyController.dll','C:\Users\bas\Documents\OSanalysis\controllerPlugin\MyController.h','includepath','C:\Program Files\OpenSim 3.3\sdk\include\')
As a result I get some warnings and errors:

Code: Select all

Warning: Function input has the same name as a MATLAB builtin. We suggest you rename the function to avoid
a potential name conflict. 
> In loadlibrary>@()cd(savedir)
  In onCleanup/delete (line 60)
  In loadlibrary 
Warning: Function version has the same name as a MATLAB builtin. We suggest you rename the function to
avoid a potential name conflict. 
> In loadlibrary>@()cd(savedir)
  In onCleanup/delete (line 60)
  In loadlibrary 
Error using loadlibrary
Failed to preprocess the input file.
 Output from preprocessor is:MyController.h
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\INCLUDE\xtgmath.h(214) : warning C4602: #pragma
pop_macro : 'new' no previous #pragma push_macro for this identifier
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\INCLUDE\eh.h(27) : fatal error C1189: #error :
"eh.h is only for C++!"
Is there a way to circumvent these issues?
I hope somebody can help me get it to work. Thanks for all your time
Bas

Re: plugin in Matlab

Posted: Mon Feb 22, 2016 10:19 am
by chrisdembia
Try using Model.LoadOpenSimLibrary("<full-path-to-DLL file>") instead.

Re: plugin in Matlab

Posted: Tue Feb 23, 2016 2:11 am
by bjdekruif
Great!

This is working. Thank you very much.
Might it be an idea to add this to the documentation at the top link in the first post?
It works much easier than the loadlibrary().

Keep up the good work.
Bas