Call a MEX function from Simulink

조회 수: 4 (최근 30일)
Martijn
Martijn 2012년 5월 21일
Dear all,
I have a .mex64 function that was build from C++ libraries (IPOPT solver) and is able to solve an optimzation problem (NLP constraint).
I can call this function from an .m file easily, but how should I do it in Simulink? An S-function will build a mex file, but I already have this MEX file.
The final goal is to run the optimization in real-time (Model Predictive Control) on a XPC target machine.
  댓글 수: 1
Martijn
Martijn 2012년 5월 21일
Using a simple mex file function I get the following error:
"Only MATLAB files are supported for code generation. Unsupported file extension 'mexw64' [...]"

댓글을 달려면 로그인하십시오.

답변 (1개)

Titus Edelhofer
Titus Edelhofer 2012년 5월 21일
Hi Martijn,
for the xPC Target you will need to have the source code of IPOPT solver available. You can write your S-function and for compilation add all source files for IPOPT. Should work, but I guess your solver code (and therefore the resulting S-function) will be fairly large ...
Titus
  댓글 수: 3
Titus Edelhofer
Titus Edelhofer 2012년 5월 21일
You just add the sources to your call to mex:
mex mysfunction.c ipopt1.c ipopt2.c ipopt3.c
Titus
Kaustubha Govind
Kaustubha Govind 2012년 5월 22일
Not sure if your MEX-function is written as an S-function (MEX-functions have one entry-point, named mexFunction; while S-functions have multiple entry-points like mdlInitializeSizes, mdlStart, mdlOutputs, mdlTerminate, etc.). Please be sure to follow the doc examples on S-functions.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Simulink Coder에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by