Main Content

Configure Deployment Types for Model Hierarchy

When you develop a complex system by using Model-Based Design, models have different requirements for the resulting code to run on the target platform. A deployment type indicates how the generated code for a model interacts with the platform and code generated from other models. The deployment type also indicates the role of a model in the system and determines the composition rules for using the model in a hierarchy with other models. You can set the deployment type of each model in a system by using the Embedded Coder app or the code mappings programmatic interface. The deployment types are:

  • Component — The top model from which the code generator produces code. The code generator produces a standalone algorithm that runs on the target platform. The component code exposes its interface to other components in the system and to platform services.

  • Subcomponent — A model reference that a component model uses. The generated code entry points are symbolically scoped to the parent component and are not exposed to the platform.

  • Automatic — Embedded Coder determines the deployment type based on the model hierarchy context.

  • Simulation only — A model intended for simulation only. For example, for a plant model that you use for testing a component model, set the deployment type to simulation only.

Embedded Coder uses the deployment type of a model to determine whether or not to generate code for the model and, if the model is for code generation, how to map elements of the model to code interfaces for the platform. This example shows you how to configure the deployment types for several models in a system and generate code to run on the target platform.

Set Up Test Harness and Model Hierarchy

The model rtwdemo_roll_harness is a harness model that generates test inputs for the component model rtwdemo_roll. The harness model is for simulation only. You generate code for the model rtwdemo_roll. For this example, you add a referenced model to the rtwdemo_roll model to represent a subcomponent in the generated code.

  1. Open the model rtwdemo_roll_harness. At the command line, enter rtwdemo_roll_harness.

  2. View the component model rtwdemo_roll by double-clicking the Model block.

  3. Convert the subsystem BasicRollMode to a referenced model. Right-click the Subsystem block and click Subsystem & Model Reference > Convert to > Referenced Model. Click Convert.

Model rtwdemo_roll with model reference to BasicRollMode model.

The model hierarchy now contains these models:

  • rtwdemo_roll_harness — The test harness that generates inputs for rtwdemo_roll. You simulate this model. You do not generate code from this model.

  • rtwdemo_roll — The component model from which the code generator generates code for the target platform.

  • BasicRollMode — A subcomponent for which the code generator produces code in the context of the component model rtwdemo_roll.

To generate code according to this hierarchy, configure the deployment types for these models.

Specify Deployment Types for the Models

You specify the deployment types of the models in one of these ways:

  • For each model, on the C Code tab, select the deployment type from the deployment type options. Select the Simulation only option from the Output menu or select a deployment type from the Deployment Type menu.

  • Configure the models in a hierarchy by using the deployment configuration tool.

  • Use the code mappings programmatic interface.

For this example, use the deployment configuration tool and set the deployment types for the whole model hierarchy.

  1. With the rtwdemo_roll_harness model open, open the Embedded Coder app.

  2. On the C Code tab, in the Prepare section, click the Automatic button. This button shows the deployment type for the model that is in the canvas. Automatic indicates that Embedded Coder determines the deployment type based on the model context.

    Deployment Type drop-down with Automatic selected. The cursor is pointing to the item Set Up Deployment Type for Model Hierarchy.

  3. From the Deployment Type menu, select Set Up Deployment Type for Model Hierarchy.

  4. In the Set up deployment type for model hierarchy dialog box, expand the rtwdemo_roll_harness and rtwdemo_roll models to see the model hierarchy.

  5. Specify the rtwdemo_roll_harness model as simulation only. In the row for the model, clear the check box for the Deployable column. This configures the model for simulation only. The code generator does not produce code from this model.

  6. Specify the rtwdemo_roll model as a component. In the row for the model, in the Deployment Type column, double-click the box and from the drop-down select Component. This configures the model for top-level model code generation.

  7. Because rtwdemo_roll is a component model, the BasicRollMode model is automatically configured as a subcomponent. For this model, the code generator produces subcomponent code, which is scoped to the component code for rtwdemo_roll.

    Deployment hierarchy tool showing model hierarchy under rtwdemo_roll_harness. Top model rtwdemo_roll_harness is not deployable, rtwdemo_roll is a component, and BasicRollMode is a subcomponent.

  8. Click OK. On the C Code tab, the Code for component field shows the component model for which you generate code.

Generate and Inspect Code

Generate code for the models. On the C Code tab, click Build. The Code view displays the generated code next to the model. To view code for a specific model, navigate to the model in the canvas. The Code view is updated to show the code for the currently displayed model. If you navigate to a simulation only model, such as rtwdemo_roll_harness, the Code view continues to show code from the component model.

View the code for the component model rtwdemo_roll. This code snippet shows some of the component interface that is generated for the model.

#include "rtwdemo_roll.h"
#include <math.h>
#include "rtwtypes.h"
#include "BasicRollMode.h"

/* Block signals and states (default storage) */
DW rtDW;

/* External inputs (root inport signals with default storage) */
ExtU rtU;

/* External outputs (root outports fed by signals with default storage) */
ExtY rtY;

/* Model step function */
void rtwdemo_roll_step(void)
{
  /* local block i/o variables */
  real32_T rtb_BasicRollMode;
  real32_T rtb_FixPtUnitDelay1;

  /* Outputs for Atomic SubSystem: '<Root>/RollAngleReference' */
  /* UnitDelay: '<S3>/FixPt Unit Delay1' */
  rtb_FixPtUnitDelay1 = rtDW.FixPtUnitDelay1_DSTATE;

View the code for the subcomponent model BasicRollMode. This code snippet shows some of the subcomponent interface that is generated for the model.

#include "BasicRollMode.h"
#include "rtwtypes.h"

/* Disable for referenced model: 'BasicRollMode' */
void BasicRollMode_Disable(BasicRollMode_DW_f *localDW)
{
  /* Disable for DiscreteIntegrator: '<Root>/Integrator' */
  localDW->Integrator_DSTATE = localDW->Integrator;
}

/* Output and update for referenced model: 'BasicRollMode' */
void BasicRollMode(const real32_T *rtu_Disp_Cmd, const real32_T *rtu_Disp_FB,
                   const real32_T *rtu_Rate_FB, const boolean_T *rtu_Engaged,
                   real32_T *rty_Surf_Cmd, BasicRollMode_DW_f *localDW)
{
  real32_T rtb_Sum;
  real32_T u0;
  boolean_T rtb_NotEngaged;

To further customize the interface of the generated code, use the Code Mappings editor to map model element categories and individual model elements to code definitions. The Code Mappings editor shows code definitions that are available to the model based on the deployment type.

See Also

Related Topics