Seth on Simulink

November 26th, 2008

Where’s the Code?

Today’s post is courtesy of my first guest blogger Tom Erkkinen, my colleague from the MathWorks office in Novi, Michigan!

Ever try to compile code generated by Real-Time Workshop on a computer without MATLAB installed and have it build the first time? If yes, great for you!

Now for the rest of us mere mortals, I’d like to introduce packNGo, a handy utility for porting generated code to new platforms.

Introduction

packNGo collects the generated code, locates all files needed to build the code, and packs it into a single zip file. It even includes those hard to find dependency files deep within your MATLAB installation directory. You can then go to a different computer, unzip, and build. Presto! No more link errors from missing headers.

Generate code, 
and pack the source into a zip file, move the zip file to another system, 
unpack the code and build.

Usage

packNGo is based on the BuildInfo API, which offers a programmatic way to interrogate and control the code generation, compilation, and build processes. You invoke packNGo by establishing a post processing code generation step, or hook point, using the set_param command. Once established, a zip file is generated during the code generation process in a flat or hierarchical structure.

I prefer the hierarchy because it clearly separates the code generated in my build directory (sDirFiles.zip) from the files in my MATLAB installation directory (mlrFiles.zip).

Example

The following commands generate and package code for a demo provided with Real-Time Workshop Embedded Coder, rtwdemo_cppencap. Note that this demo highlights C++ class generation in Release R2008b.

>> rtwdemo_cppencap;
>> set_param(bdroot,'PostCodeGenCommand',...
     'packNGo(buildInfo, {''packType'' ''hierarchical''})');
>> rtwbuild(bdroot);

The zip file produced is shown below.

Zip files created by Real-Time Workshop packNgo

Now you can go to your Hardware-in-the-Loop lab, system simulator, or real-time prototyping platform and build.

Caveats

packNGo operates on source files, such as *.c, *.cpp, *.h files but not other files such as compiler and link directives, or makefiles. Unnecessary files may be included but each release has fewer and fewer of these. Source code for S-functions is included in the zip package.

I hope you enjoyed my quick introduction to this handy but not well known feature.   Please read our documentation or leave a comment for more about packNGo.

3 Responses to “Where’s the Code?”

  1. Chitlesh GOORAH replied on :

    Hello Seth, Thanks for the tip. I am curious whether with the packNGo function the zip file is platform independent. In other words will the files under the zip file be compiled under Linux or Mac ?

    As I can see the mlrFiles.zip contains matlab dependency files. Could you please give us some details about the licensing conflicts that a company will have if the rtwdemo_cppencap.zip file is to be sold to another company?

  2. tom erkkinen replied on :

    The zip file is just a standard zip, so you can unpack it from MATLAB or any zip utility on any platform.

  3. Guy Rouleau replied on :

    @ Chitlesh, The files are not all platform independent. The C-code is, but the auto-generated makefile is based on the TMF-file selected during the build process. If you want to generate code on a windows platform and use it on a UNIX platform, you have to modify the “grt_unix.tmf” template make file for your machine. Guidelines to compile generated code on a computer without MATLAB for releases before the existence of “packNGo” can be found at this address:

    http://www.mathworks.com/support/solutions/data/1-19EH0.html

    The modifications to the template makefile described in this page are valid for the current release.

Leave a Reply

Wrap code fragments inside <pre> tags, like this:

<pre class="code">
a = magic(3);
sum(a)
</pre>

If you have a "<" character in your code, either follow it with a space or replace it with "&lt;" (including the semicolon).


Seth Popinchalk is an Application Engineer for The MathWorks. He writes here about Simulink and other MathWorks tools used in Model-Based Design.
  • Mohamamd: Hi Suth, I try to simulate a load tap-changing transformer in simulink but its control part has to be...
  • Han Geerligs: Hello Guy, thanks for the clarificaton and link. However in the documentation I am missing the...
  • Guy: @Han, you probably already know, but I think it is good to share with everyone. To zoom in use the key...
  • Han Geerligs: Hi Seth, Once again I’d like to point out that my biggest accelerator is using mouse and keyboard...
  • XaL: Hi, thanks for the tips. As someone wrote in http://blogs.mathwor ks.com/seth/2009/03/ 13/new-%C2%A0rele...
  • Uba osy: Hi, in the introductory example for fuzzy logic toolbox it was noted that using non fuzzy means, you could...
  • Prashant: How can I have same example but instead AC(1 to 10V 50 or 60Hz) and DC(0.5 to 10 V) then adding AC+DC but...
  • adrian chavarro: Great tool, for educational and sicentific, simulation. I would like to know where can i place a...
  • Ashish Sadanandan: @wei, I was talking about the case where the compiler would perform the ‘model_Xdim...
  • wei: @Ashish, I agree with your observation on compiler optimization but fail to see why Han’s code would be...

These postings are the author's and don't necessarily represent the opinions of The MathWorks.