Real-Time Workshop User's Guide | ![]() ![]() |
Getting Started: Basic Concepts and Tutorials
This section is designed to help you to obtain hands-on experience with the Real-Time Workshop in short order. There are two parts, which we recommend you read in order:
Basic Real-Time Workshop Concepts
Target and Host
A target is an environment -- hardware or operating system -- on which your generated code will run. The process of specifying this environment is called targeting.
The process of generating target-specific code is controlled by a system target file, a template makefile, and a make command. To select a desired target, you can specify these items individually, or you can choose from a wide variety of ready-to-run configurations.
The host is the system you use to run MATLAB, Simulink, and the Real-Time Workshop. Using the build tools on the host, you create code and an executable that runs on your target system.
Available Target Configurations
The Real-Time Workshop supports many target environments. These include ready-to-run configurations and third-party targets. You can also develop your own custom target.
For a complete list of bundled targets, with their associated system target files and template makefiles, see The System Target File Browser.
Code Formats
A code format specifies a framework for code generation suited for specific applications.
When you choose a target configuration, you implicitly choose a code format. If you use the Real-Time Workshop Embedded Coder, for example, the code generated will be in embedded C format. The embedded C code format is a compact format designed for production code generation. Its small code size, memory usage, and simple call structure make it optimal for embedded applications.
Many other targets, such as the generic real-time (GRT) target, use the real-time code format. This format, less compact but more flexible, is optimal for rapid prototyping applications.
For a complete discussion of available code formats, see Chapter 4, Generated Code Formats.
The Generic Real-Time Target
The Real-Time Workshop provides a generic real-time development target. The generic real-time (GRT) target provides an environment for simulating fixed-step models in single or multitasking mode. A program generated with the GRT target runs your model, in simulated time, as a stand-alone program on your workstation.
The GRT target allows you to perform code validation by logging system outputs, states, and simulation time to a data file. The data file can then be loaded into the MATLAB workspace for analysis or comparison with the output of the original model.
The GRT target also provides a starting point for targeting custom hardware. You can modify the GRT harness program, grt_main.c
, to execute code generated from your model at interrupt level under control of a real-time clock.
Target Language Compiler Files
The Real-Time Workshop uses Target Language Compiler files (or TLC files) to translate your Simulink model into code. The Target Language Compiler uses two types of TLC files during the code generation and build process. The system target file, which describes how to generate code for a chosen target, is the entry point for the TLC program that creates the executable. Block target files define how the code looks for each of the Simulink blocks in your model.
System and block target files have the extension .tlc
. By convention, a system target file has a name corresponding to your target. For example, grt.tlc
is the system target file for the generic real-time (GRT) target.
Template Makefiles
The Real-Time Workshop uses template makefiles to build an executable from the generated code.
The Real-Time Workshop build process creates a makefile from the template makefile. Each line from the template makefile is copied into the makefile; tokens encountered during this process are expanded into the makefile.
The name of the makefile created by the build process is model
.mk
. The model
.mk
file is passed to a make utility. The make utility compiles and links an executable from a set of files.
By convention, a template makefile has an extension of .tmf
and a name corresponding to your target and compiler. For example, grt_vc.tmf
is the template makefile for building a generic real-time program under Visual C/C++.
The Build Process
A high-level M-file command controls the Real-Time Workshop build process. The default command, used with most targets, is make_rtw
.When you initiate a build, the Real-Time Workshop invokes make_rtw
.The make_rtw
command, in turn, invokes the Target Language Compiler and other utilities such as make
. The build process consists of the following stages:
make_rtw
compiles the block diagram and generates a model description file, model
.rtw.
make_rtw
invokes the Target Language Compiler to generate target-specific code, processing model
.rtw
as specified by the selected system target file.
make_rtw
creates a makefile, model
.mk
, from the selected template makefile.
make
is invoked. make
compiles and links a program from the generated code, as instructed in the generated makefile.
Automatic Program Building in Chapter 2 gives an overview of the build process. Chapter 3, Code Generation and the Build Process gives full details on code generation and build options and parameters.
Model Parameters and Code Generation
The simulation parameters of your model directly affect code generation and program building. For example, if your model is configured to stop execution after 60 seconds, the program generated from your model will also run for 60 seconds. The Real-Time Workshop also imposes certain requirements and restrictions on the model from which code is generated.
Before you generate code and build an executable, you must verify that you have set the model parameters correctly in the Simulation Parameters dialog box. See Simulation Parameters and Code Generation in Chapter 3 for more information.
This section provides hands-on experience with the code generation, program building, data logging, and code validation capabilities of the Real-Time Workshop.
Tutorial 1: Building a Generic Real-Time Program shows how to generate C code from a Simulink demonstration model and build an executable program.
Tutorial 2: Data Logging explains how to modify the demonstration program to save data in a MATLAB MAT-file, for plotting.
Tutorial 3: Code Validation, demonstrates how to validate the generated program by comparing its output to that of the original model.
Tutorial 4: A First Look at Generated Code examines code generated from a very simple model, illustrating the effect of one of the Real-Time Workshop code generation options.
These tutorials assume basic familiarity with MATLAB and Simulink. You should also read Getting Started: Basic Concepts and Tutorials before proceeding.
The procedures for building, running, and testing your programs are almost identical in UNIX and PC environments. The discussion notes differences where applicable.
Make sure that a MATLAB compatible C compiler is installed on your system before proceeding with these tutorials. See the "Preface" for more information on supported compilers and compiler installation.
The f14 Demonstration Model
Tutorials 1-3 use a demonstration Simulink model, f14.mdl
, from the matlabroot
/toolbox/simulink/simdemos/aerospace
directory. (By default, this directory is on your MATLAB path.) f14
is a model of a flight controller for the longitudinal motion of a Grumman Aerospace F-14 aircraft.
The model simulates the pilot's stick input with a square wave having a frequency of 0.5 (radians per second) and an amplitude of ± 1. The system outputs are the aircraft angle of attack and the G forces experienced by the pilot. The input and outputs are visually monitored by Scope blocks.
![]() | Product Summary | Tutorial 1: Building a Generic Real-Time Program | ![]() |