文档

Rapid Prototyping Model Functions

Rapid prototyping code defines the following functions that interface with the main program (main.cormain.cpp):

  • Model():这model registration function. This function initializes the work areas (for example, allocating and setting pointers to various data structures) used by the model. The model registration function calls theMdlInitializeSizesandMdlInitializeSampleTimes功能。这两个功能与S功能非常相似mdlInitializeSizesandmdlInitializeSampleTimesmethods.

  • mdlstart((void):在模型注册功能之后MdlInitializeSizesandMdlInitializeSampleTimes执行,主程序通过调用开始执行mdlstart。此例程在启动时被称为一次。

    这F你nctionmdlstart有四个基本部分:

    • Code to initialize the states for each block in the root model that has states. A subroutine call is made to the “initialize states” routines of conditionally executed subsystems.

    • 由模型中每个块的一次性初始化(启动)函数生成的代码。

    • 代码,使街区根模型中have enable methods, and the blocks inside triggered or function-call subsystems residing in the root model. Simulink®块可以具有启用和禁用方法。启用方法在块开始执行之前就调用,并且在块停止执行之后,该禁用方法被调用。

    • Code for each block in the model whose output value is constant. The block code appears in themdlstartF你nction only if the block parameters are not tunable in the generated code and if the code generator cannot eliminate the block code through constant folding.

  • MdlOutputs(int_T tid)MdlOutputs更新块的输出。这tid(任务标识符)参数标识了根据其示例时间执行块何时执行块的任务。在主要时间和次要步骤中,主计划调用了此例程。主要时间步骤是主程序正在采取实际时间步骤(也就是说,是时候执行特定任务了)。如果您的模型包含连续状态,则将采取次要时间步骤。次要时间步骤是求解器生成集成阶段的时间,即主要输出之间的点。这些集成阶段用于计算用于推进连续状态的衍生物。

  • MdlUpdate(int_T tid)MdlUpdate更新在工作向量中保存的状态和工作向量状态信息(即既不是连续也不是离散的状态)。这tid(任务标识符)参数标识了一个任务,该任务依次指示哪些样本时间处于活动状态,从而使您只能有条件地更新活动块的状态。大专业之后,该界面调用了此例程MdlOutputs已执行。求解器也被称为model_Derivativesis called in minor steps by the solver during its integration stages. All blocks that have continuous states have an identical number of derivatives. These blocks are required to compute the derivatives so that the solvers can integrate the states.

  • MdlTerminate(void)MdlTerminateContains any block shutdown code.MdlTerminate作为实时程序终止的一部分,由接口调用。

这Contents of the above functions are directly related to the blocks in your model. A Simulink block can be generalized to the following set of equations.

y = F 0 (( t ,,,, X C ,,,, X d ,,,,

输出y是连续状态的函数XC,离散状态Xd和输入。每个块在一个部分中编写其特定方程式MdlOutputs

X d + 1 = F (( t ,,,, X d ,,,,

离散状态Xdare a function of the current state and input. Each block that has a discrete state updates its state inMdlUpdate

X - = F d (( t ,,,, X C ,,,,

衍生物Xare a function of the current input. Each block that has continuous states provides its derivatives to the solver (for example,ode5) 在model_Derivatives。衍生物are used by the solver to integrate the continuous state to produce the next value.

输出,y,,,,is generally written to the block I/O structure. Root-level Outport blocks write to the external outputs structure. The continuous and discrete states are stored in the states structure. The input,,可以源自另一个块的输出,该输出位于块I/O结构中,外部输入(位于外部输入结构)或状态。这些结构在model。h归档Simulink Coder™软件生成。

这next example shows the general contents of the rapid prototyping style of C code written to themodel。CFile.

该图显示了描述快速原型生成代码的执行的流程图。

快速原型执行流程图

Each block places code in specificMdlroutines according to the algorithm that it is implementing. Blocks have input, output, parameters, and states, as well as other general items. For example, in general, block inputs and outputs are written to a block I/O structure (model_B)。Block inputs can also come from the external input structure (model_U)or the state structure when connected to a state port of an integrator (model_X),或地面(rtground)如果没有连接或接地。块输出也可以转到外部输出结构(model_Y)。该图显示了这些项目之间的一般映射。

生成代码的数据视图

以下列表定义了前图中显示的结构:

  • Block I/O structure (model_B):该结构由持续的块输出信号组成。块输出信号的数量是模型中非虚拟块的数据输出端口的宽度之和。如果激活块I/O优化,则Simulink和金宝appSimulink Coderproducts reduce the size of themodel_B结构

    • Reusing the entries in themodel_Bstructure

    • Making other entries local variables

    How Generated Code Stores Internal Signal, State, and Parameter DataFor more information on these optimizations.

    Structure field names are determined either by the block's output signal name (when present) or by the block name and port number when the output signal is left unlabeled.

  • Block states structures: The continuous states structure (model_X)Contains the continuous state information for blocks in your model that have continuous states. Discrete states are stored in a data structure called thedwork矢量((model_ dwork)

  • 块参数结构(model_P):参数结构包含可以在执行过程中更改的块参数(例如,增益块的参数)。

  • 外部输入结构(model_U):这external inputs structure consists of the root-level Inport block signals. Field names are determined by either the block's output signal name, when present, or by the Inport block's name when the output signal is left unlabeled.

  • External outputs structure (model_Y):外部输出结构由根级外口块组成。字段名称由模型中的根级输出块名称确定。

  • Real work, integer work, and pointer work structures (model_RWork,,,,model_IWork,,,,model_pwork):块可能需要真实,整数或指针工作区域。例如,内存块为每个信号使用一个真实的工作元素。这些领域用于保存内部状态或类似信息。

Related Topics