构建过程Workflow for Real-Time Systems
这building process includes generating code in C or C++ from a model and building an executable program from the generated code. This example can use a generic real-time (GRT) or an embedded real-time (ERT) system target file (STF) for code generation. The resulting standalone program runs on your desktop computer, independent of external timing and events.
Working Folder
此示例使用本地副本slexAircraftExample
模型, stored in its own folder,aircraftexample
。Set up yourworking folderas follows:
In the MATLAB®Current Folder browser, navigate to a folder to which you have write access.
要创建工作文件夹,请输入以下MATLAB命令:
mkdir aircraftexample
Make
aircraftexample
your working folder:cd aircraftexample
打开
slexAircraftExample
模型:slexAircraftExample
该模型出现在Simulink中金宝app®Editor model window.
在模型窗口中,选择File>Save As。Navigate to your working folder,
aircraftexample
。Save a copy of theslexAircraftExample
模型asmyaircraftExample
。
构建文件夹和代码生成文件夹
在制作代码时,代码生成器会创建一个构建文件夹在您的工作文件夹中。构建文件夹名称是
, derived from the name of the source model and the chosen system target file. The build folder stores generated source code and other files created during the build process. Examine the build folder contents at the end of this example.模型
_target
_rtw
When a model contains Model blocks (references to other models), the model build creates special subfolders in yourCode generation folder((Simulink) to organize code for the referenced models. These code generation folders exist alongside product build folders and are namedslprj
。为引用模型生成代码describes navigating code generation folder structures in Model Explorer.
在下面slprj
folder, a subfolder named_sharedutils
包含在模型之间可以共享的生成代码。
Set Model Parameters for Code Generation
To generate code from your model, you must change some of the model configuration parameters. In particular, the generic real-time (GRT) system target file and most other system target files require that the model specifies afixed-step solver.
笔记
这code generator produces code for models, usingvariable-step solvers, for rapid simulation (rsim
)and S-function system target files only.
To set model configuration parameters by using the Configuration Parameters dialog box:
打开
myaircraftExample
模型if it is not already open.From the model window, open the Configuration Parameters dialog box by selectingSimulation>Model Configuration Parameters。
SelectConfiguration Parameters>Solver。输入以下参数值(可以设置一些参数值):
Start time:
0.0
停止时间:
60
Type:
固定步骤
Solver:
ODE5(Dormand-Prince)
Fixed step size (fundamental sample time):
0.1
Treat each discrete rate as a separate task:
离开
这background color of the controls you just changed is tan. The color also appears on fields as a reaction to your choices in other fields. Use this visual feedback to verify that what you set is what you intended. When you apply your changes, the background color reverts to white.
To register your changes, click申请。
保存模型。Simulation parameters persist with the model for use in future sessions.
Configure Build Process
配置模型的构建过程,选择系统目标文件,工具链或模板makefile以及一个make
command.
In these examples and in most applications, you do not need to specify these parameters individually. The examples use the ready-to-run generic real-time target (GRT) configuration. The GRT system target file builds a standalone executable program that runs on your desktop computer.
To select the GRT system target file using the Configuration Parameters dialog box:
With the
myaircraftExample
模型open, selectSimulation>Model Configuration Parameters打开“配置参数”对话框。SelectConfiguration Parameters>代码生成。
为了System target file, enter
grt.tlc
,然后单击申请。这Configuration Parameters>代码生成窗格显示选择System target file((
grt.tlc
),Toolchain((Automatically locate an installed toolchain
), 和Build Configuration((Faster Builds
)。笔记
如果您单击Browse,系统目标文件浏览器打开并在MATLAB路径上显示系统目标文件。一些系统目标文件需要其他产品。下载188bet金宝搏例如,
ert.tlc
requires Embedded Coder®。保存模型。
设置代码生成参数
在第一次从模型生成代码之前,请检查模型的代码生成参数。此主题中的某些步骤不需要您更改参数值。这些步骤似乎可以帮助您熟悉用户界面。当您使用模型参数时,可以将鼠标指针放在参数上,以查看描述其功能的工具提示。
To set code generation parameters using the Configuration Parameters dialog box:
With the
myaircraftExample
模型open, selectSimulation>Model Configuration Parameters打开“配置参数”对话框。Select代码生成>报告>Create code generation report。此操作使软件能够创建和显示代码生成报告
myaircraftExample
模型。Select代码生成>Comments。这options displayed here control the types of comments included in generated code. Leave the options set to their defaults.
Select代码生成>Symbols。这些选项控制生成的代码的外观和感觉。
Select theConfiguration Parameters>代码生成>Advanced parameters标签。以下参数控制构建冗长和调试支持。金宝app这些参数对于所有系统目标文件配置都是共同的。
Verbose build((
RTWVerbose
parameter)Retain .rtw file((
RetainRTWFile
parameter)个人资料TLC((
ProfileTLC
parameter)Start TLC debugger when generating code((
tlcdebug
parameter)生成代码时启动TLC覆盖范围((
TLCCoverage
parameter)启用TLC断言((
tlcassert
parameter)
Leave the options set to their defaults.
SelectConfiguration Parameters>代码生成>界面。
为了theShared code placement参数,选择
共享位置
。这build process places generated code for utilities at a shared location within theslprj
folder in yourCode generation folder(金宝appSimulink)。If it is not already cleared, clear theConfiguration Parameters>代码生成>界面>Advanced parameters>经典呼叫接口parameter.
Click申请and save the model.
构建并运行程序
构建过程生成C代码的模型。It then compiles and links the generated program to create an executable image. To build and run the program:
With the
myaircraftExample
模型open, initiate code generation and the build process for the model by using any of the following options:一些消息关于代码生成和compilation appear in the命令窗口。最初的消息是:
### Starting build procedure for model: myAircraftExample
许多成功消息的内容取决于您的编译器和操作系统。最终消息包括:
### Created executable myAircraftExample.exe ### Successful completion of build procedure for model: myAircraftExample ### Creating HTML report file myAircraftExample_codegen_rpt.html
这code generation folder now contains an executable,
myaircraftExample。exe
(微软®Windows®platforms) ormyaircraftExample
((UNIX®platforms). In addition, the build process has created anslprj
folder and amyaircraftExample_grt_rtw
folder in yourCode generation folder(金宝appSimulink)。笔记
生成代码后
myaircraftExample
模型, the build process displays a code generation report. See报告Generation有关如何创建和使用代码生成报告的更多信息。查看the contents of the working folder after the build, enter the
dir
orls
command:>>dir。myaircraftExample.slx slprj .. myaircraftExample.slx.autosave myaircraftExample.exe myaircraftexample_grt_rtww
To run theexecutable from the Command Window, type
!myaircraftExample
。这呢
character passes the command that follows it to the operating system, which runs the standalonemyaircraftExample
program.>>!myaircraftExample** starting the model ** ** created myAircraftExample.mat **
查看the files created in the build folder, use the
dir
orls
command again. The exact list of files produced varies among MATLAB platforms and versions. Here is a sample list from a Windows platform:>>dirmyaircraftExample_grt_rtw。rt_main.obj myAircraftExample_data.c .. rtmodel.h myAircraftExample_data.obj buildInfo.mat rtw_proj.tmw myAircraftExample_private.h codeInfo.mat myAircraftExample.bat myAircraftExample_ref.rsp defines.txt myAircraftExample.c myAircraftExample_types.h html myAircraftExample.h modelsources.txt myAircraftExample.mk rt_logging.obj myAircraftExample.obj
构建文件夹的内容
这build process creates a build folder and names it
, where模型
_target
_rtw
is the name of the source model and模型
is the system target file selected for the model. In this example, the build folder is namedtarget
myaircraftExample_grt_rtw
。
这构建文件夹includes the following generated files.
File | Description |
---|---|
|
实现模型的独立C代码 |
|
一个包含包含参数定义和状态变量的标题文件 |
|
包含常见的标题文件包括定义 |
|
为了ward declarations of data types used in the code |
|
主标头文件以在静态主程序中包含生成的代码(其名称不更改,并且仅包括 |
您为该报告创建的代码生成报告myaircraftExample
模型displays a link for each of these files. You can click the link explore the file contents.
这构建文件夹contains other files used in the build process. They include:
myaircraftExample.mk
- 用于使用指定工具链构建可执行文件的makefile。Object (
。obj
)filesmyaircraftExample。bat
— Batch control filertw_proj.tmw
— Marker filebuildinfo.mat
— Build information for relocating generated code to another development environmentdefines.txt
- 编译生成代码所需的预处理器定义myaircraftExample_ref.rsp
- 包含作为命令行参数的数据mex
((Windows systems only)
构建文件夹还包含一个子文件夹,html
,其中包含组成代码生成报告的文件。有关更多信息,请参阅报告s for Code Generation。
Customized Makefile Generation
After producing code, the code generator produces a customized makefile,模型
。mk
。生成的makefile指示make
系统实用程序,以根据模型生成和链接源代码,任何必需的线束程序,库或用户提供的模块。代码生成器生成文件模型
。mk
whether you are using the toolchain approach or template makefile approach for build process control. For more information about these approaches, seeChoose Build Approach and Configure Build Process。
如果您使用的是工具链方法,则代码生成器会创建模型
。mk
based on the modelToolchain settings。您可以修改Makefile的生成rtwmakecfg.m
API。有关更多信息,请参阅工具链方法。
如果使用模板makefile方法,则代码生成器会创建模型
。mk
from a system template file,系统
。tmf
((where系统
stands for the selected system target file name). The system template makefile is designed for your system target file. You have the option of modifying the template makefile to specify compilers, compiler options, and additional information used during the creation of the executable. For more information, seeTemplate Makefile Approach。