文档

构建过程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:

  1. In the MATLAB®Current Folder browser, navigate to a folder to which you have write access.

  2. 要创建工作文件夹,请输入以下MATLAB命令:

    mkdir aircraftexample
  3. Makeaircraftexampleyour working folder:

    cd aircraftexample
  4. 打开slexAircraftExample模型:

    slexAircraftExample

    该模型出现在Simulink中金宝app®Editor model window.

  5. 在模型窗口中,选择File>Save As。Navigate to your working folder,aircraftexample。Save a copy of theslexAircraftExample模型asmyaircraftExample

构建文件夹和代码生成文件夹

在制作代码时,代码生成器会创建一个构建文件夹在您的工作文件夹中。构建文件夹名称是模型_target_rtw, 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.

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.

在下面slprjfolder, 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:

  1. 打开myaircraftExample模型if it is not already open.

  2. From the model window, open the Configuration Parameters dialog box by selectingSimulation>Model Configuration Parameters

  3. SelectConfiguration Parameters>Solver。输入以下参数值(可以设置一些参数值):

    • Start time0.0

    • 停止时间60

    • Type固定步骤

    • SolverODE5(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.

  4. To register your changes, click申请

  5. 保存模型。Simulation parameters persist with the model for use in future sessions.

Configure Build Process

配置模型的构建过程,选择系统目标文件,工具链或模板makefile以及一个makecommand.

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:

  1. With themyaircraftExample模型open, selectSimulation>Model Configuration Parameters打开“配置参数”对话框。

  2. SelectConfiguration Parameters>代码生成

  3. 为了System target file, entergrt.tlc,然后单击申请

    Configuration Parameters>代码生成窗格显示选择System target file((grt.tlc),Toolchain((Automatically locate an installed toolchain), 和Build Configuration((Faster Builds)。

    笔记

    如果您单击Browse,系统目标文件浏览器打开并在MATLAB路径上显示系统目标文件。一些系统目标文件需要其他产品。下载188bet金宝搏例如,ert.tlcrequires Embedded Coder®

  4. 保存模型。

设置代码生成参数

在第一次从模型生成代码之前,请检查模型的代码生成参数。此主题中的某些步骤不需要您更改参数值。这些步骤似乎可以帮助您熟悉用户界面。当您使用模型参数时,可以将鼠标指针放在参数上,以查看描述其功能的工具提示。

To set code generation parameters using the Configuration Parameters dialog box:

  1. With themyaircraftExample模型open, selectSimulation>Model Configuration Parameters打开“配置参数”对话框。

  2. Select代码生成>报告>Create code generation report。此操作使软件能够创建和显示代码生成报告myaircraftExample模型。

  3. Select代码生成>Comments。这options displayed here control the types of comments included in generated code. Leave the options set to their defaults.

  4. Select代码生成>Symbols。这些选项控制生成的代码的外观和感觉。

  5. Select theConfiguration Parameters>代码生成>Advanced parameters标签。以下参数控制构建冗长和调试支持。金宝app这些参数对于所有系统目标文件配置都是共同的。

    • Verbose build((RTWVerboseparameter)

    • Retain .rtw file((RetainRTWFileparameter)

    • 个人资料TLC((ProfileTLCparameter)

    • Start TLC debugger when generating code((tlcdebugparameter)

    • 生成代码时启动TLC覆盖范围((TLCCoverageparameter)

    • 启用TLC断言((tlcassertparameter)

    Leave the options set to their defaults.

  6. SelectConfiguration Parameters>代码生成>界面

    • 为了theShared code placement参数,选择共享位置。这build process places generated code for utilities at a shared location within theslprjfolder in yourCode generation folder(金宝appSimulink)。

    • If it is not already cleared, clear theConfiguration Parameters>代码生成>界面>Advanced parameters>经典呼叫接口parameter.

  7. 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:

  1. With themyaircraftExample模型open, initiate code generation and the build process for the model by using any of the following options:

    • Click theBuild Model按钮。

    • Ctrl+B

    • SelectCode>C/C++ Code>Build Model

    • 调用rtwbuildcommand from the MATLAB command line.

    • 调用slbuildcommand from the MATLAB command line.

    一些消息关于代码生成和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 anslprjfolder and amyaircraftExample_grt_rtwfolder in yourCode generation folder(金宝appSimulink)。

    笔记

    生成代码后myaircraftExample模型, the build process displays a code generation report. See报告Generation有关如何创建和使用代码生成报告的更多信息。

  2. 查看the contents of the working folder after the build, enter thedirorlscommand:

    >>dir。myaircraftExample.slx slprj .. myaircraftExample.slx.autosave myaircraftExample.exe myaircraftexample_grt_rtww
  3. To run theexecutable from the Command Window, type!myaircraftExample。这character passes the command that follows it to the operating system, which runs the standalonemyaircraftExampleprogram.

    >>!myaircraftExample** starting the model ** ** created myAircraftExample.mat **
  4. 查看the files created in the build folder, use thedirorlscommand 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模型_target_rtw, where模型is the name of the source model andtargetis the system target file selected for the model. In this example, the build folder is namedmyaircraftExample_grt_rtw

这构建文件夹includes the following generated files.

File Description

myaircraftExample。c

实现模型的独立C代码

myaircraftExample。h

一个包含包含参数定义和状态变量的标题文件

myaircraftExample_private.h

包含常见的标题文件包括定义

myaircraftExample_types.h

为了ward declarations of data types used in the code

rtmodel.h

主标头文件以在静态主程序中包含生成的代码(其名称不更改,并且仅包括myaircraftExample。h

您为该报告创建的代码生成报告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)files

  • myaircraftExample。bat— Batch control file

  • rtw_proj.tmw— Marker file

  • buildinfo.mat— Build information for relocating generated code to another development environment

  • defines.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系统实用程序,以根据模型生成和链接源代码,任何必需的线束程序,库或用户提供的模块。代码生成器生成文件模型。mkwhether 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

如果您使用的是工具链方法,则代码生成器会创建模型。mkbased on the modelToolchain settings。您可以修改Makefile的生成rtwmakecfg.mAPI。有关更多信息,请参阅工具链方法

如果使用模板makefile方法,则代码生成器会创建模型。mkfrom 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

Related Topics

Was this topic helpful?