Build the Simulink model

After completing the settings, you can build the model.
The template of Code Generation generally adopts the Function-Call Generator module. (There is also direct use of build This Subsystem to generate code directly for the subsystem, which is not recommended here) as follows: The Model
generated files
are set according to the description in the previous article, and the .c and .h files named after the subsystem name will be generated, and rtwtypes. h. As follows:
write picture description here
Model.c is the source file of the function.
Model.h is the declaration file
rtwtypes.h is the data bit type definition file (this file is the interface definition between the generated code and standard C) The interface
function
generated by the function interface is named the name of the subsystem part in the Function-Call Generator (above ) and the model system name with a suffix respectively, as follows:

extern void Model_initialize(void);
extern void AdddFunc(vcoid);
extern void Model_terminate(void);
);

Among them, Model_initialize is used for initialization calls,
AddFunc is used for periodic calls, and
Model_terminate is used for calls after the function life cycle ends.
Variable interface
The method of variable transmission is generally carried out in the form of global variables. If the signal variable is not defined (defined on the signal line), function
the interface variable specifically generated in the model exists in the form of a structure:

/* External inputs (root inport signals with auto storage) */
typedef struct {
  real_T a;                            /* '<Root>/a' */
  real_T a1;                           /* '<Root>/a1' */
} ExtU_Model_T;

/* External outputs (root outports fed by signals with auto storage) */
typedef struct {
  real_T b;                            /* '<Root>/b' */
} ExtY_Model_T;

It can be achieved in the following two ways

1 Name on the signal, by modifying the properties of
Signal
the signal line 2 Name the signal line,
write picture description here
as above, check Signal name must ..., then define in the Model Explorer Click
1, modify the name and dataType of 2, and select the variable at 3
write picture description here
storage type.
Note that the variables defined here need to be saved, and the data needs to be loaded into the Workspace before running the model each time. It can be saved in .mat and .m formats: .mat can be saved with the save command; .m can be completed by right-clicking.
Note : The model can refer to the resources I uploaded

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325833491&siteId=291194637