Creating a TLC file for S-function

33 visualizaciones (últimos 30 días)
Saba Hajhassan
Saba Hajhassan el 17 de Jul. de 2023
Comentada: Anavi Somani el 18 de Jul. de 2023
I have simulink model and inside this simulink model, there is a ''S-Function'' block which reads .m (matlab file). I want to build this simulink model in OPAL RT (real time software) but i get the following error:
__________________________________________________________________________________________________________________
??? Error using tlc_new
Error: File: C:\Program Files\MATLAB\R2019b\rtw\c\tlc\lib\utillib.tlc Line: 1626 Column: 8
%exit directive: Simulink Coder Fatal in block:
"mg_5vocs_2019b_17_07_1_sm_calculation/SM_Calculation/VOC_10/V control/P_sync_8/S-Function", block type "S-Function": MFile S-functions without a corresponding TLC file are not supported.
You can inline your S-function (dis_consensus_68) by creating a TLC file for it.
You can also remap your S-function to C by creating a corresponding C Mex source file and a dis_consensus_68.tlc file in the same directory as the MFile S-function which contains (on the first line):
%% CallAsCMexLevel1
or
%% CallAsCMexLevel2
__________________________________________________________________________________________________________________
I have no idea how to creat s TLC file from the S-function. I do not have good programming skills. Can anyone please help me with this issue? I would appreciate it.

Respuestas (1)

Anavi Somani
Anavi Somani el 18 de Jul. de 2023
  7 comentarios
Saba Hajhassan
Saba Hajhassan el 18 de Jul. de 2023
thanks, its really a very time consuming task. Since I am not good in programming, do you have any other suggestions for me? I would really appreicitate it. Its about my master thesis and i am really short in time.
The S-funkction block reads the .m file which is just some lines.
Do you have any other idea how I can create the TLC file for this code:
function [sys,x0,str,ts] = dis_consensus(t,x,u,flag)
% x_initial=[0,0,0]';
Lc=TreeMatrix_B(3)*TreeMatrix_B(3)';
switch flag,
case 0,
[sys,x0,str,ts]=mdlInitializeSizes(u);
case 3,
sys=mdlOutputs(t,x,u,Lc);
case { 1,2,4,9 } % Unused flags sys = [ ];
otherwise
error(['Unhandled flag = ',num2str(flag)]);
end
function [sys,x0,str,ts]=mdlInitializeSizes(u)
sizes = simsizes;
sizes.NumContStates = 0;
sizes.NumDiscStates = 0;
sizes.NumOutputs = 3;
sizes.NumInputs = 3;
sizes.DirFeedthrough = 1;
sizes.NumSampleTimes = 1;
sys = simsizes(sizes);
x0 = [];
str = [];
ts = [0 0];
function sys=mdlOutputs(t,x,u,Lc)
sys=-1*Lc*u;
Anavi Somani
Anavi Somani el 18 de Jul. de 2023
To create a TLC file for the provided code, you can follow these steps:
1. Open a text editor or an Integrated Development Environment (IDE) that supports TLC file creation.
2. Create a new file and save it with a ".tlc" extension, such as "dis_consensus.tlc".
3. In the TLC file, you need to define the target-specific code that corresponds to the MATLAB code provided. The TLC file is responsible for generating code specific to a target language (e.g., C, C++).
4. Start by defining the TLC file header, which typically includes information about the target language, version, and other relevant details.
5. Define the entry point for the generated code by using the `entry` keyword, followed by the name of the generated function. In this case, the entry point would be the `dis_consensus` function.
6. Within the `dis_consensus` entry point, you can start defining the TLC code that corresponds to the MATLAB code. This involves implementing the necessary TLC constructs to handle the different cases specified in the provided code (flag values 0 and 3).
7. For each case, you will need to define the TLC code that corresponds to the MATLAB code within that case. This includes defining the input and output sizes, initializing variables, and implementing the necessary calculations.
8. Pay attention to any specific requirements or constraints of the target language you are generating code for. This may include syntax differences, data type considerations, or any other language-specific details.
9. Save the TLC file and use it with the appropriate code generation tool or environment to generate the desired code in the target language.
It's recommended to consult the documentation or resources specific to your code generation environment for more detailed guidance.
I hope this helps you get started with creating a TLC file for the provided code.

Iniciar sesión para comentar.

Categorías

Más información sobre Target Language Compiler en Help Center y File Exchange.

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by