Quantcast

Simulink Coder

Configuring a Model via the Command Line

Real-Time Workshop® and Real-Time Workshop Embedded Coder® provide numerous configuration options for tailoring the generated code. Code generation options are accessed through the Simulink® Configuration Parameters, also referred to as the model's configuration set.

You will make configuration decisions and tradeoffs depending on how you use and interact with the generated code. In short, you will choose a configuration that best matches your needs for debugging, traceability, code efficiency, and safety precaution. Features, scripts, and documentation facilitate your creation of an ideal model configuration set for your application.

Although Real-Time Workshop provides a push-button facility to quickly configure and check a model for specified objectives, it is common to automate the model configuration procedure using a MATLAB script. The instructions in this demonstration illustrate:

  • Concepts of working with configuration parameters
  • Documentation to understand the code generation options
  • Tools and scripts to automate the configuration of a model

With these basic skills you are well on your way to setting up an ideal automated configuration scheme for your project.

Contents

Configuration Parameter Workflows

There are many workflows for Configuration Parameters that include persistence within a single model or persistence across multiple models. Depending on your needs, you may wish to work with configuration sets as copies or references. This example demonstrates the basic steps for working directly with the active configuration set of a model. For a comprehensive description of configuration set features and workflows, please see the Configuration Sets section of the Simulink documentation.

Configuration Set Basics

Configuration Wizard blocks automatically configure a model for code generation. Several goal-oriented configurations are available, and you can customize them to better suit your goals for the generated code. Automating the configuration of a model is very beneficial as it reduces manual steps and improves consistency between builds.

You can execute the following commands to open a model:

model='rtwdemo_configwizard';
open_system(model)

Next, you can execute the following command to obtain the model's active configuration set:

cs = getActiveConfigSet(model);

Real-Time Workshop exposes a subset of the code generation options. If you are using Real-Time Workshop, you can execute the following command to select the Generic Real-Time (GRT) target:

switchTarget(cs,'grt.tlc',[]);

Real-Time Workshop Embedded Coder exposes the complete set of code generation options. If you are using Real-Time Workshop Embedded Coder, you can execute the following command to select the Embedded Real-Time (ERT) target:

switchTarget(cs,'ert.tlc',[]);

To automate configuration of models that will be built for both GRT- and ERT-based targets, you will find the configuration set IsERTTarget attribute useful. You can execute the following command to determine if the model is configured for an ERT target:

isERT = strcmp(get_param(cs,'IsERTTarget'),'on');

You can interact with code generation options via the model or the configuration set. You can execute the following commands to get and set options indirectly via the model:

inlineParams = get_param(model,'InlineParams');  % Get InlineParams
set_param(model,'InlineParams',inlineParams)     % Set InlineParams

You can combine the above commands and execute the following to get and set options directly via the configuration set.

if isERT
    lifespan = get_param(cs,'LifeSpan');  % Get LifeSpan
    set_param(cs,'LifeSpan',lifespan)     % Set LifeSpan
end

Configuration Option Summary

You can find the full list of code generation options, including information on tradeoffs for debugging, traceability, code efficiency, and safety precaution, at the following links:

Example Configuration Script

Real-Time Workshop provides an example configuration script that you can use as a starting point for your application. If you have the Real-Time Workshop or Real-Time Workshop Embedded Coder software, you can view the full list of relevant GRT and ERT code generation options in rtwconfiguremodel.m.

Configuration Wizard Blocks

Real-Time Workshop Embedded Coder provides a set of Configuration Wizard blocks that automate configuration of a model for a specific goal. The predefined blocks provide configuration for:

  • ERT optimized for fixed point
  • ERT optimized for floating point
  • GRT optimized for fixed/floating point
  • GRT debug settings for fixed/floating point
  • Custom (you provide the script)

Just drop the block into a model and double-click to configure the model. See Simulink model rtwdemo_configwizard for an interactive demonstration of these blocks.

Please see the Configuration Wizard section of the Real-Time Workshop Embedded Coder documentation for more information (login required).