Main Content

Verify If Input and Output of Referenced Model Are Within Bounds

Model reference input or output that are outside the specified bounds can indicate an error in model design. To verify if the model reference inputs and outputs are within the specified range, run a Polyspace® Code Prover™ verification of the generated code.

Prerequisite

Before you run Polyspace Code Prover from Simulink®, you must link your Polyspace and MATLAB® installations. See Integrate Polyspace with MATLAB and Simulink.

This feature applies for code generated by using Embedded Coder®. Polyspace Bug Finder™ does not check the input and output bounds of referenced model.

Open Model for Polyspace Analysis

This model implements a controller and a plant. The subsystem controller contains a reference to the model WhereAreTheErrors.

model = 'psdemo_model_link_sl_cscript';
open_system(model);
% Copyright 2024 The MathWorks, Inc.,

Specify the input In1 of the referenced model to be inside the range [-100 .. 100]. In the MATLAB Command Window, enter:

load_system('WhereAreTheErrors');
set_param('WhereAreTheErrors/In1','OutMin', '-100');
set_param('WhereAreTheErrors/In1','OutMax', '100');

Alternatively, in the Block Parameter dialog box for In1, set the attribute Minimum to -100 and Maximum to 100.

Run Polyspace Code Prover Analysis

Run the Polyspace Code Prover analysis either from the Simulink Editor or from the MATLAB Command Window.

To run the analysis from the Simulink Editor:

  1. From the Apps tab, open the Polyspace Code Verifier app.

  2. In the Polyspace tab, select Code Prover as the mode and select Code Generated as Top Model.

  3. Select Run Analysis.

    Polyspace toolstrip showing MODE as Code Prover, ANALYZE as "Code Generated as Top Model".

To run the Polyspace analysis from the MATLAB Command Window, enter this code at the command prompt:

model = 'psdemo_model_link_sl_cscript';
open_system(model);
slbuild(model);
% Create Polyspace options object
mlopts = pslinkoptions(model); 
% Specify result folder
mlopts.ResultDir ='\cp_result';
% Set analysis to Code Prover mode
mlopts.VerificationMode = 'CodeProver'; 
% Run analysis
pslinkrun(model, mlopts);

Review and Address Input Outside Specified Range

The Polyspace Code Prover results show a red violation of the check Input/Output of model reference out of specified range:

Polyspace Results Details window showing a red violation of the check Input/Output of model reference out of specified range.

This result indicates that the expected range of the first input port of the referenced model WhereAreTheErrors is [-100 .. 100] but the model receives an input signal of 1000.

To address this issue, saturate the input to the referenced model so that the input does not go outside the specified range. To saturate the input the referenced model, use a Saturation block with Upper limit set to 100 and Lower limit set to -100:

Model showing a saturation block between the inputSignal and the referenced model, with Upper limit set to 100 and lower limit set to -100.

After saturating the signal, run another Polyspace Code Prover analysis. The check Input/Output of model reference out of specified range now appears as green.

See Also

|