matlab -> RealTime workshop -> Qnx

Hello,

This seems like a recurrent question but so far I have not found a satifying
answer.
Is it possible to export simulink matlab models into Qnx using the realtime
matlab workshop?
Is someone out there doing so?

Thanks…

Carlos.

Carlos…

Yes, this is possible. We do it all of the time:

  1. generate the RTW code from Simulink
  2. wrap the RTW code within a resource manager (with interrupts and the
    like)
  3. compile against the libraries provided by the MathWorks (they come
    along with Matlab/SIMULINK)

You may have to edit some of the libraries that MathWorks offers, but
this is rather trivial (it is time consuming however). An alternative
is to create a .so library with the MathWorks provided libraries. Also
be aware that there is a world of difference between the RTW code
generated by the grt tools and the code generated by the ert tools. The
former, the grt tools, generate code that is very much linked with
SIMULINK libraries, and are a bear (but possible, we have done it!) to
compile. The ert generated code compiles off the box against the
MathWorks libraries.

Hope this helps some.

Regards…

Miguel.



Carlos Beltran wrote:

Hello,

This seems like a recurrent question but so far I have not found a satifying
answer.
Is it possible to export simulink matlab models into Qnx using the realtime
matlab workshop?
Is someone out there doing so?

Thanks…

Carlos.

hello,

I’m interested in this topic too. Its very important to me and my work, so
maybe you know where to find additional information on that?

Yes, this is possible. We do it all of the time:



2. wrap the RTW code within a resource manager (with interrupts and the
like)

I’m a litle bit beginner to QNX. what do you mean saying so? how to wrap
code within resource manager?
Thanks for any additional info.

Best regards,
Darius

Hi Darius and Carlos…

RTW code embedded in QNX is possible:

  1. learn about QNX, shared libraries, resource managers, etc
  2. learn about SIMULINK
  3. learn about RTW
  4. generate RTW windows examples first, and learn from those (i.e.
    follow some tutorials).
  5. Look at the example main program that RTW generates.
  6. adapt the example main() program from RTW to Eclipse + CDT tools in
    Windows, Linux or to QNX Momentics IDE directly.
  7. learn how to generate libraries with what SIMULINK has to offer.


    In SIMULINK, create a simple 2+2=4 example, generate the RTW code using
    ert tools, look at the sample main() program, then port the code to QNX.
    Make your code increasingly more complex, building up from previous
    success. Iterate.

What I have done is rather simple. I took all of the libraries in source
code from the Matlab distribution and made a shared library in QNX with
them. You will get errors, and then you go and modify the libraries as
necessary until every thing compiles well. Notice that you can create
the libraries independent of any RTW code. You do this independently of
every thing else. I would say that this is a first step. Once you have
compiled the libraries successfully, then you are ready for the next
step. Notice that most of the problems come when you try to port the
SIMULINK macros. They have a lot of macros, and the biggest problem for
me was that they have macros that span multiple lines like this:

aMacroFunctionHere = some(macros)
continue_in_the_next_line + for(no(reason(at(all))));

What I had to do was delete the ‘’ and make the macro span only one
line like this:

aMacroFunctionHere = some(macros) continue_in_the_next_line +
for(no(reason(at(all))))

There are hundreds of those, and this takes time (there may be a better
way to do this, but I would not know how). This is why I was saying
before that getting the MathWorks libraries to compile is a rather
trivial but time consuming exercise. Lamentably, due to MathWorks
license terms, I cannot provide my compiled libraries to a third party,
but I can tell you what you can do.

The second step would be to let RTW generate code using the ert tools.
You should let RTW generate a sample main() code as well. Then, try to
port this main() code to QNX, and link against the shared libraries that
you have from the first step. You can do this with the main() example
provided by RTW, or you can port that main() example into a resource
manager framework specific to QNX. This is up to you.

While you are doing this, you may have questions, and these are the
questions that you ask on the NG for every one’s benefit. As an
in-between step, you may want to see if you are successful in the
Windows or Linux platform, but frankly, I feel more conformable in QNX
than in Windows or Linux (but this is just me).

In summary, there are three steps that you can do in parallel:

  1. get familiar with RTW + ert tools
  2. try to get the shared libraries going
  3. get familiar + port results in QNX (i.e. compile the RTW generated
    main() function in QNX).
  4. get familiar + wrap RTW main() in a resource manager framework (optional)

Notice that when you generate code in RTW, you must be careful with a
few things. When you tell :

  1. every thing must be discrete (i.e. filters, control feedback laws,
    etc), NO CONTINUOUS TIME EVER.
  2. you must not have any kind of algebraic loops.
  3. you break an algebraic loop by inserting a pure delay.
  4. it is best if you refrain from using multitasking (i.e. use single
    tasking only).
  5. do not let RTW ert tools optimize any code. In this way you can see
    what is going on, otherwise, RTW will optimize your code beyond recognition.
  6. use fixed step, and the step size is dictated by your
    digital/discrete requirements, naturally.
  7. ask RTW to generate as many comments as possible (it is free + useful).
  8. I forget…

With regard to the shared libraries and QNX, you may want to try to
generate the shared libraries one step at the time. You may even want to
create several shared libraries at the time, or you may want to follow a
divide+conquer style where you increment your success one addition at a
time. The libraries that you may want to consider are found in:

matlab/rtw/c/ert
matlab/rtw/c/grt
matlab/rtw/c/libsrc
matlab/rtw/c/src
matlab/rtw/ext_mode
matlab/simulink/src
matlab/simulink/include

Compile all of those as shared libraries in QNX. You know that these
will work because Matlab runs in Linux as well, and if it runs in Linux,
it will run in QNX. When you generate code in ert and link against
these libraries in QNX, if you get errors, then you go back, find and
add to what you already have (according to which error you get), so on
and so forth until you have every thing you need in the shared
libraries. When you get here, if you have problems, ask questions in the NG.

The suggestion regarding wrapping code in a resource manager comes from
the following issue. RTW code generates discrete code, but you must
implement a timing scheme in the RTOS of choice, in this case QNX. In
QNX, the best way to approach this is via a resource manager. However,
this is not a must. You can always adapt the RTW generated main()
example program to QNX, and implement a timer in there. The QNX docs say
how to go about doing this sort of things, and RK books also say how to
do many QNX things (http://www.parse.com/).

Finally, if you do not have Matlab/SIMULINK release 14, try to get it.
You may actually enjoy doing these things with the latest release from
MathWorks and QNX 3.0 Momentics IDE.

It seems to me that you need to get experience with Matlab/SIMULINK, ert
tools, QNX environment, etc. These are all very useful things, but they
will test your stamina. Good news is that you can divide and conquer,
and you can approach these independent challenges in parallel. You must
do your part. I may have forgotten a few details, but for now, I think
that you have some homework to do! :slight_smile:

Best Regards…

Miguel.



Darius wrote:

hello,

I’m interested in this topic too. Its very important to me and my work, so
maybe you know where to find additional information on that?


Yes, this is possible. We do it all of the time:



2. wrap the RTW code within a resource manager (with interrupts and the
like)


I’m a litle bit beginner to QNX. what do you mean saying so? how to wrap
code within resource manager?
Thanks for any additional info.

Best regards,
Darius

The Opal-RT product does exactly what I think you’re describing, providing
a QNX x86-based runtime and all of the linkages to a Matlab/Simulink
development environment. See more at the following link:

http://www.opal-rt.ca

Mark Shepard




Miguel Simon wrote:

Hi Darius and Carlos…

RTW code embedded in QNX is possible:

  1. learn about QNX, shared libraries, resource managers, etc
  2. learn about SIMULINK
  3. learn about RTW
  4. generate RTW windows examples first, and learn from those (i.e.
    follow some tutorials).
  5. Look at the example main program that RTW generates.
  6. adapt the example main() program from RTW to Eclipse + CDT tools in
    Windows, Linux or to QNX Momentics IDE directly.
  7. learn how to generate libraries with what SIMULINK has to offer.



    In SIMULINK, create a simple 2+2=4 example, generate the RTW code using
    ert tools, look at the sample main() program, then port the code to QNX.
    Make your code increasingly more complex, building up from previous
    success. Iterate.

What I have done is rather simple. I took all of the libraries in source
code from the Matlab distribution and made a shared library in QNX with
them. You will get errors, and then you go and modify the libraries as
necessary until every thing compiles well. Notice that you can create
the libraries independent of any RTW code. You do this independently of
every thing else. I would say that this is a first step. Once you have
compiled the libraries successfully, then you are ready for the next
step. Notice that most of the problems come when you try to port the
SIMULINK macros. They have a lot of macros, and the biggest problem for
me was that they have macros that span multiple lines like this:

aMacroFunctionHere = some(macros)
continue_in_the_next_line + for(no(reason(at(all))));

What I had to do was delete the ‘’ and make the macro span only one
line like this:

aMacroFunctionHere = some(macros) continue_in_the_next_line +
for(no(reason(at(all))))

There are hundreds of those, and this takes time (there may be a better
way to do this, but I would not know how). This is why I was saying
before that getting the MathWorks libraries to compile is a rather
trivial but time consuming exercise. Lamentably, due to MathWorks
license terms, I cannot provide my compiled libraries to a third party,
but I can tell you what you can do.

The second step would be to let RTW generate code using the ert tools.
You should let RTW generate a sample main() code as well. Then, try to
port this main() code to QNX, and link against the shared libraries that
you have from the first step. You can do this with the main() example
provided by RTW, or you can port that main() example into a resource
manager framework specific to QNX. This is up to you.

While you are doing this, you may have questions, and these are the
questions that you ask on the NG for every one’s benefit. As an
in-between step, you may want to see if you are successful in the
Windows or Linux platform, but frankly, I feel more conformable in QNX
than in Windows or Linux (but this is just me).

In summary, there are three steps that you can do in parallel:

  1. get familiar with RTW + ert tools
  2. try to get the shared libraries going
  3. get familiar + port results in QNX (i.e. compile the RTW generated
    main() function in QNX).
  4. get familiar + wrap RTW main() in a resource manager framework (optional)

Notice that when you generate code in RTW, you must be careful with a
few things. When you tell :

  1. every thing must be discrete (i.e. filters, control feedback laws,
    etc), NO CONTINUOUS TIME EVER.
  2. you must not have any kind of algebraic loops.
  3. you break an algebraic loop by inserting a pure delay.
  4. it is best if you refrain from using multitasking (i.e. use single
    tasking only).
  5. do not let RTW ert tools optimize any code. In this way you can see
    what is going on, otherwise, RTW will optimize your code beyond recognition.
  6. use fixed step, and the step size is dictated by your
    digital/discrete requirements, naturally.
  7. ask RTW to generate as many comments as possible (it is free + useful).
  8. I forget…

With regard to the shared libraries and QNX, you may want to try to
generate the shared libraries one step at the time. You may even want to
create several shared libraries at the time, or you may want to follow a
divide+conquer style where you increment your success one addition at a
time. The libraries that you may want to consider are found in:

matlab/rtw/c/ert
matlab/rtw/c/grt
matlab/rtw/c/libsrc
matlab/rtw/c/src
matlab/rtw/ext_mode
matlab/simulink/src
matlab/simulink/include

Compile all of those as shared libraries in QNX. You know that these
will work because Matlab runs in Linux as well, and if it runs in Linux,
it will run in QNX. When you generate code in ert and link against
these libraries in QNX, if you get errors, then you go back, find and
add to what you already have (according to which error you get), so on
and so forth until you have every thing you need in the shared
libraries. When you get here, if you have problems, ask questions in the NG.

The suggestion regarding wrapping code in a resource manager comes from
the following issue. RTW code generates discrete code, but you must
implement a timing scheme in the RTOS of choice, in this case QNX. In
QNX, the best way to approach this is via a resource manager. However,
this is not a must. You can always adapt the RTW generated main()
example program to QNX, and implement a timer in there. The QNX docs say
how to go about doing this sort of things, and RK books also say how to
do many QNX things (> http://www.parse.com/> ).

Finally, if you do not have Matlab/SIMULINK release 14, try to get it.
You may actually enjoy doing these things with the latest release from
MathWorks and QNX 3.0 Momentics IDE.

It seems to me that you need to get experience with Matlab/SIMULINK, ert
tools, QNX environment, etc. These are all very useful things, but they
will test your stamina. Good news is that you can divide and conquer,
and you can approach these independent challenges in parallel. You must
do your part. I may have forgotten a few details, but for now, I think
that you have some homework to do! > :slight_smile:

Best Regards…

Miguel.



Darius wrote:
hello,

I’m interested in this topic too. Its very important to me and my work, so
maybe you know where to find additional information on that?


Yes, this is possible. We do it all of the time:



2. wrap the RTW code within a resource manager (with interrupts and the
like)


I’m a litle bit beginner to QNX. what do you mean saying so? how to wrap
code within resource manager?
Thanks for any additional info.

Best regards,
Darius