Aller au contenu principal

Prerequisites for Matlab 2021 Models for integration into the Sim4Sys toolchain

TYPING OF INPUT AND OUTPUT

Input/Output
  1. Sizing and typing of input ports (Double click/Signal attributes):
  • Simple value
    • choose the type
      • Float: choose double
      • Integer, Enumeration: choose int16
      • Boolean: choose boolean
    • Select the port dimension [1;1]
  • Vector
    • Do not choose type (leave Inherit: auto)
    • Select port size [X;Y]
      • Y: the maximum number of elements in the vector
      • X: element size
  1. Outputs
  • Single value (same as input)
  • Currently untreated vector

VECTOR MANAGEMENT

The difference in vector management between Matlab and C++ requires a strict process.

As you saw earlier, you must define a maximum size that allows you to size the array (matlab) corresponding to the vector. If it is an entry, the values not filled will be set to NaN. At the output, the values not filled in must also be set to NaN.

Vector dimension

First you have to chose the “Embedded Coder Apps” in the “APPS” tab of Simulink

Simulink APPS

Then in the new “C++ Code” tab, chose “Embedded C++ Code” with the first button.

Simulink CPP coder

With the same button, click on “Select System Target File” and chose “ert.tlc” with “Create Visual C/C++” as description.

Simulink ert tlc

After that, click on the “Code Interface” button and chose “Class Name & Namespace”

Simulink class name

Verify that in “C++ Class Name” you have the structure “modelName” and “ModelClass” attached. “C++ Class Namespace” must stay empty.

Then with the same “Code Interface” button, chose “Code Mappings”

Simulink code mapping

Check that your inputs and outputs are public or change them if not.

After that you can check the global settings by clicking on the “Settings” button

Simulink settings

First go to the “Solver” tab

Simulink fixed step

Check that you have “Fixed-step” in the “Solver Selection” “Type” combobox or change it if not.

Then go to the “Code Generation” tab

Simulink code generation step

Here check the option “Generate code only” and uncheck “Generate makefile”

Then go to the “Interface” tab

Simulink variable size

Check the “variable-size signals” option

Then go to the “Identifiers” tab

Simulink identifiers

Check that all the options have the settings like in the previous picture.

You can now click on “OK” to close the “Settings” panel.

You can generate the code by clicking on the “Generate Code” button

Simulink generate code

Chose “Generate Code”.

Once the code succesfully generated, you have to create a C++ project on Papyrus and import inside of it all the generated code. It is necessary to build a library containing the new Matlab project.

If you have already other Matlab projects, just past the new generated C++ code with the other Matlab projects code and rebuild it. If not you can create a new Project in designer

new cpp project

And then

cygwin

Copy the generated code in this project.

If you need a .lib library you can change this setting by right clicking on the project in Papyrus and make the following modification

properties papyrus

Once the new library succesfully generated, you have to copy it in "ExtraLibs/matlab/lib” and its code in “ExtraLibs/matlab/include”.

Check that the code generated from your UML project have the reference to the matlab library.

Matlab lib

If you are already using other Matlabs, the references should be already there. If not you can add them.