How to change contents of blocks in multiple instances of referenced model in Simulink?

2 ビュー (過去 30 日間)
I am representing a certain robot using a Simulink model which contains Matlab function blocks, integrator blocks, etc., and intend to use this model in a main model. In the main model, I need to have multiple instances of the robot model to represent multiple robots interacting. I have found out that this is possible using referenced models.
However, each of these robots is different. Within each robot model, the architecture does not change, but the contents of the blocks do change to represent the different robots. These changes are not only parameters, but also the contents of the Matlab functions themselves. I generate these functions at the beginning of the simulation using initFcn callback, but I am unaware of how I can update the contents of each referenced model according to the generated functions.
Apologies if the question is confusing, it is not a trivial problem. Thank you in advance for the help!

採用された回答

Sai
Sai 2022 年 10 月 13 日
I understand that you created many sub Simulink models which you will eventually use in main Simulink model as reference model and you are trying to change the contents of blocks correspondingly.
I hope the following explanation resolves the issue.
  • Open the main Simulink model
  • Double click the reference model, which you want to change or update
  • Navigate to Modelling tab and then Model Properties of Model Settings as shown in below image
  • Click on callbacks and then you can add the corresponding files by clicking on different callbacks as shown in below image.
The above process can be repeated for any reference model.

その他の回答 (1 件)

Mark McBroom
Mark McBroom 2022 年 10 月 15 日
編集済み: Mark McBroom 2022 年 10 月 15 日
It is possible to have referenced models use different parameter values by setting them up as parameter arguments. However, it is not possible for different isntances of the reference model to have different code in a MATLAB function.
One possible workaround would be to add a switch statement to your MATLAB code that runs different code based on a pameter ( for example, ModelID)... and then make ModelID a model parameter. This will allow you to give each instance of your referenced model and different ModelID and therefore execute differnt MATLAB code in the MATLAB Function Block.

カテゴリ

Help Center および File ExchangeGet Started with Simulink についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by