跳到主要内容

Prerequisites for Matlab 2015 or 2018 Models for integration into the Sim4Sys toolchain

CREATING A NEW MODEL (OPTIONAL)

Run the script "new_simulink_model.sh" (available here), and fill in the model name.

This script allows you to create a new folder with different files:

  • Model_name.slx: Simulated model.
  • Model name.png: Model image.
  • after_generation.sh: Lets you run multiple scripts (below). This is the only script to run manually.
    • get_files.sh: update the compileable files (Matlab 2015).
    • check.sh: check the correct construction of the model (Matlab 2015).
    • transform.sh: allows you to modify . h and . cpp so that they can be compiled with other simulink models (Matlab 2018).
    • new_get_files.sh: update the compileable files (Matlab 2018).
    • new_check.sh: check the correct model construction (Matlab 2018).
  • .gitignore: lets you not pollute the git server.

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

CODE GENERATION

Code Generation

Change class name

In Code Generation/Interface: click on:

Configure C++ Class Interface

Name of the class "modelName" + "Modelclass".

Configure C++ Class Interface Windows

Generate the code

警告

It is mandatory to place yourself in the folder containing the model you want to create in C++ under matlab.

Click on "Generate Code":

Generate Code

MOVE THE GENERIC FILES

Once the generation is done, you must run the "get_files.sh" script which allows you to update the compileable files (.cpp and .h).

MODEL IMAGE

Update the template image that will be displayed in the plugin and DLL. This image «modelName.png» is saved at the same level as the model (.slx).

CHECKING

The "check.sh" script checks:

  • The model name
  • Presence of the image
  • Good construction of comments
  • Match comments to Matlab signals

UPDATE VCXPROJ FILE

TODO: improve the current script

COMPILATION OF THE LIBRARY

Compilation of all matlab functions (release, debug and animation)

TODO: improve the current script

UPDATING THE BOOKSTORE

TODO: make a script to update automatically in «C: Program Files (x86) Cil4sys lib matlab_lib_demo».

Move: • in the lib folder: the libraries generated • img folder: images of models • The h. of each function at the root

Generation Code ( 2015 AND 2018)

Target Selection

Change the System target file : ert.tlc

System target file

Choose C++ Language (2015 ET 2018)

Choose C++ Language

Check

Generate code only

In Generation Code/Interface Check (2018)

  1. Shared code placement (matlab 2018) For shared code investment choose "Shared location"

In Generation Code/Interface Check (2015)

variable-size signals

In Solver choose Fixex-step type

Solver

Uncheck « Generate makefile »

Generate makefile

Configuration Parameter (MATLAB 2015)

Click on List

List Parameters list