How can I connect 2 generated code from 2 different Simulink models?

6 vues (au cours des 30 derniers jours)
Hello, I have 2 Simulink models, one is a PI controller, and one is a spring-mass-damper system. I converted them into 2 different C++ files with Generic Real-Time Target. Now I want to connect both of them but I don't know how. I tried to create one new project in Codeblocks and include all .cpp and .h files but the results are different from simulation. Does anyone have experience on this?

Réponse acceptée

Ankitha Kollegal Arjun
Ankitha Kollegal Arjun le 19 Avr 2017
Hello Trinh,
The following steps might be helpful in combining the code generated from two models and creating a single application:
1. For each model, go to "Configuration Parameters -> Code Generation -> Interface -> Software environment" and for "Shared code placement", select "Shared location".
This setting instructs the Real-Time Workshop to place common files in the "slprj" folder instead of the 'model_rtw' folder (All the utility functions used by both the models will be in the same directory, namely the _sharedutil directory in the slprj folder).
2. Build all the relevant models in the same directory where the "slprj" folder was created for the first model.
3. Copy all the files necessary for both models into one directory. 'packNGo' is useful for this purpose (Use packNGo function on each model, to get all the files that are necessary for the build process).
More information about this function can be found here:
4. Modify the makefile and the main program. The following templates can be used as a starting point:
a. Main template: MATLAB_ROOT/rtw/c/grt/classic_main.c
b. Make template: MATLAB_ROOT/rtw/c/grt_malloc/grt_msvc.tmf
Save the modified version as a single combine_main.c and combine_msvc.mk
Note: There should be comments with the word "Customize" for all the changes made .
Essentially, since there are going to be clashing defines, modify them to use separate names: i.e. NCSTATES1, NCSTATES2, etc.
5. Modify the BAT file
You can use nmake to compile and link using msvc, and those make commands are usually located in the model.bat file in the generated code folder. Copy one of the batch file and create a combine.bat
5. Run the batch file to compile and link:
>> !combine.bat
Go up a level, and you should see combine.exe.
--
Thanks,
Ankitha

Plus de réponses (0)

Catégories

En savoir plus sur Simulink Coder dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by