Discussion:
How to use tlc wrapper for rtw - S-function
(too old to reply)
Joachim
2009-07-10 13:35:03 UTC
Permalink
Hi,

I have a ready-written MATLAB m-function and want to implement it in a Simulink model.

I've read many tutorials and the MATLAB help about it, but I don't get it to do what I want it to do. ;)

The m-function uses the fmincon function from the optimization toolbox.
How can I implement this in an S-Function which I can build with the Real-Time Workshop?
If I understood the help, I have to write a Level 2 M-File and have to create a *.tlc file for it. Creating a fully inlined function works (I tested a very simple Input = Output - no "special" function), but when I want to use the "wrapper" method, I'm failing with creating the correct call for my function and to "let MATLAB know about it".

Is it possible to do what I want to do (implementing a MATLAB toolbox function in an RTW)?
If it is, how does it work and could you give me a brief example of a similar problem? It hasn't to be the fmincon, any non-standard function (not sin, cos etc.), e.g. the interp1 would help me to understand what I have to do.
If it doesn't work, please let me know... then I would have to create my own "fmincon" or use another function which source code is available.. but even then I have to "wrap" the function and I have no clue how to do this.

Greetings,
Joachim
Phil Goddard
2009-07-10 14:22:02 UTC
Permalink
The purpose of TLC is to tell the RTW build process how to convert a block into equivalent c-code.

It's not essential to have a TLC file for a c-code S-function because it's already in c.
You do need a TLC file for m-code (or Fortran) S-functions because you need to tell RTW what the c-code equivalent of the m-code is.

Hence to use fminunc (or any other MATLAB code) in an S-function that you want to use with RTW you need have c-code for that function.

You're going to need to find/write a c-code optimization routine the minics fminunc, or use it instead of fminunc.

Phil.

Loading...