Page 1 of 1

Interfacing MATLAB Simulink with OpenSim

Posted: Tue Apr 12, 2022 3:07 pm
by jeevanj
I am trying to get the MEX interface working which is available in the following link which may enables designing custom controllers for OpenSim model in MATLAB Simulink environment.

https://simtk.org/projects/opensimmatlab

However, different errors comes for different combinations of software versions (Visual Studio, MATLAB, CMake, OpenSim, SimBody).

If any of you succeeded in this regard, please kindly let me know with what software version combination it worked properly.

Also any other directions to how OpenSim could be connected with MATLAB Simulink is highly appreciated.

Re: Interfacing MATLAB Simulink with OpenSim

Posted: Tue Apr 12, 2022 8:37 pm
by nicos1993
Hello Jeevan,

A long time ago I used the MEX functionality in Matlab 2017b together with OpenSim 3.3. The function I have attached (see below) should compile a *.cpp source file. You may need to modify the location of where I point to the dynamic link libraries! I hope that helps!

function compileMEX(cppFileName)

% Input
% cppFileName - .cpp Filename as a string

% Function for compiling Matlab mex function with OpenSim Compatibility
eval(['mex ',cppFileName,' -L''c:\OpenSim 3.3\sdk\lib'' -losimCommon -losimSimulation -losimAnalyses -losimActuators -losimTools -lOpenSim_SimTKcommon -lOpenSim_SimTKmath -lOpenSim_SimTKsimbody -losimJavaJNI -losimLepton -losimSimmFileWriter -I''C:\OpenSim 3.3\sdk\include'' -I''C:/OpenSim 3.3/sdk/include/SimTK/include'' -DWIN32 -D_WINDOWS -DNDEBUG'])

end

Best wishes,

Nicos Haralabidis

Re: Interfacing MATLAB Simulink with OpenSim

Posted: Tue Apr 12, 2022 8:46 pm
by nicos1993
You will likely also need to use and install Microsoft Visual Studio 2015 such that the compiler matches the one used for OpenSim 3.3...

Re: Interfacing MATLAB Simulink with OpenSim

Posted: Mon Apr 25, 2022 1:57 pm
by jeevanj
Thank you for your reply. I will try this in the way you had specified.