Define global variables for MATLAB function usage within Simulink for Embedded Code

조회 수: 7 (최근 30일)
Hello,
I'm trying to create a global variable in my Simulink model, that will be visible within all MATLAB function blocks. I used the Simulink.Signal class with all properties defined. Inside the function, the 'global varName' is included, as well as variable is defined as Data Store Memory. The following error occurs:
Found unsupported global datainitialization class dor global variable 'varName'
Code generation does not supportimporting handle classes from MATLAB
As Simulink.Signal is handle class, I assume i can't use it to generate code from model to run in on HW.
Is there a way to define one, let's say Data Dictionary, to store all variables that I will use within all submodel of my main model and define which are global? I do not want to define them every time I create a new submodel and i want to enable visibility of variables within the MATLAB functions, without putting them as input every time (what I normally practise).
I also tried to use enum class, and that approach is visible in MATLAB functions, but sometimes there is a need to define two parameters of the same value (I would like to use structures instead of enums). Next problem occurs while using same 'Multiplier' field in 2 enums with different names. Simulink cannot generate code while using this approach.
classdef CurrentProtectionThresholds < int16
enumeration
Multiplier (100)
DischargeWarningThr (-1000)
DischargeErrorThr (-1200)
ChargeWarningThr (250)
ChargeErrorThr (300)
ImmunityLow (-50)
ImmunityHigh (50)
end
end
Thanks for help.

답변 (1개)

Mark McBroom
Mark McBroom 2023년 3월 30일
  댓글 수: 1
Grzegorz Diaczek
Grzegorz Diaczek 2023년 3월 30일
Hello Mark,
I was following the Simulink.Signal approach and I'm quite sure I covered all steps. But here, there was no problem with no global variable inside the function, but the error about not supported code generation of Simulink.Signal variable. As I mentioned, I want to use this model to generate C code and deploy it on my HW (ESP32). MATLAB function block is being used within the Stateflow Chart. Regarding the Data Store Memory option, I have multiple variables used in my model and i do not want to initialize every new using Simulink Blocks. Also, I want to use one variable file within all my models, as my main model is based on 10 submodels.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Event Functions에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by