Real-Time Workshop | ![]() ![]() |
Tutorial 1: Building a Generic Real-Time Program
This tutorial walks through the process of generating C code and building an executable program from the demonstration model. The resultant stand-alone program runs on your workstation, independent of external timing and events.
Working and Build Directories
It is convenient to work with a local copy of the f14
model, stored in its own directory, f14example
. This discussion assumes that the f14example
directory resides on drive d:
. Set up your working directory as follows:
Be aware that during code generation, Real-Time Workshop creates a build directory within your working directory. The build directory name is model_target_rtw
, derived from the name of the source model and the chosen target. The build directory stores generated source code and other files created during the build process. We examine the build directory and its contents at the end of this tutorial.
Setting Program Parameters
To generate code correctly from the f14rtw
model, you must change some of the simulation parameters. In particular, note that generic real-time (GRT) and most other targets require that the model specify a fixed-step solver.
Note Real-Time Workshop can generate code for models using variable-step solvers for Rapid Simulation (rsim) and S-function targets only. A Simulink license is checked out when rsim targets execute. See Licensing Protocols for Simulink Solvers in Executables of the Real-Time Workshop documentation for details. |
To set parameters, use the Simulation Parameters dialog box as follows:
0.0
Solver options: set Type to Fixed-step
. Select the ode5 (Dormand-Prince)
solver algorithm.
The Solver pane with the correct parameter settings is shown below.
Selecting the Target Configuration
To specify the desired target configuration, you choose a system target file, a template makefile, and a make
command.
In these tutorials, you do not need to specify these parameters individually. Instead, you use the ready-to-run generic real-time target configuration. The GRT target is designed to build a stand-alone executable program that runs on your workstation.
Target configuration
from the Category menu, as shown below.
make
command.
Generic Real-Time Target
(as shown above) and then click OK.
grt.tlc)
, template makefile (grt_default_tmf
), and make
command (make_rtw
), as shown below.
General code generation options
from the Category menu. The options displayed here are common to all target configurations. Make sure that all options are set to their defaults, as shown below.
GRT code generation options
from the Category menu. The options displayed here are specific to the GRT target. Make sure that all options are set to their defaults, as below.
TLC debugging
from the Category menu. Make sure that all options in this category are cleared.
Target configuration
from the Category menu. Make sure that the Generate code only option is not selected.
Building and Running the Program
The Real-Time Workshop build process generates C code from the model, and then compiles and links the generated program. To build and run the program:
f14rtw.exe
(on PC), or f14rtw
(on UNIX). In addition, a build directory, f14rtw_grt_rtw, has been created.
dir
command from the MATLAB command window.
f14rtw
program.
Contents of the Build Directory
The build process creates a build directory and names it model_target_rtw
, concatenating the name of the source model and the chosen target. In this example, the build directory is named f14rtw_grt_rtw.
f14rtw_grt_rtw contains these generated source code files:
f14rtw.c
-- the stand-alone C code that implements the model.
f14rtw_data.c
-- initial parameter values used by the model.
f14rtw.h
-- an include header file containing definitions of parameter and state variables
f14rtw_types.h
-- forward declarations of data types used in the code.
f14rtw_private.h
-- a header file containing common include definitions
rtmodel.h
-- a master header file for including generated code in the static main program (its name never changes, and it simply includes f14rtw.h
).
The build directory also contains other files used in the build process, such as the object (.obj
) files and the generated makefile (f14rtw.mk
).
![]() | Quick Start Tutorials | Tutorial 2: Data Logging | ![]() |