Set Model Callbacks with Simulink Block
이전 댓글 표시
Hey Guys
i want to set Model Callbacks of my Simulink Model with a Simulink bock. I want to make a body-Collision Library. To check for Body Collision, i use the InitFcn and StopFcn to detect body collision. If its possible i want to add a block to my library that automatically sets the InitFcn and StopFcn if i place it in a Simulink model.
답변 (1개)
Tejas
2024년 4월 26일
0 개 추천
Hello Marcus,
My understanding from above question is that you want a block, placed inside the Simulink model to establish ‘InitFcn’ and ‘StopFcn’ callbacks.
Try this simple method to accomplish this:
- Begin by creating an empty subsystem block. Position it at the preferred spot within the model.

- Within the ‘InitFcn’ callback of the Subsystem, use ‘set_param’ command to establish ‘InitFcn’ and ‘StopFcn’ callbacks of the model. Provide model name, callback name and the code to be written inside of callback, as an input to ‘set_param’ command. The ‘set_param’ command will then establish these callbacks.
- Below is an example of the code for reference.

Here is a screenshot displaying the ‘InitFcn’ callback, successfully configured using the ‘set_param’ command.

Following, a screenshot illustrates the ‘StopFcn’ callback, also effectively established through the ‘set_param’ command.

For more information on ‘set_param’ command and the Callbacks used, please refer to these documentations:
- ‘set_param’: https://www.mathworks.com/help/releases/R2023b/simulink/slref/set_param.html .
- Callbacks: https://www.mathworks.com/help/releases/R2023b/simulink/ug/model-callbacks.html .
Hope it helps!
카테고리
도움말 센터 및 File Exchange에서 Model, Block, and Port Callbacks에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!