hello sir, i use level 1 S-Function in my simulink model. I need s function to wait for 2 sec, then collects the measurements. How i can do that ?

댓글 수: 4

Walter Roberson
Walter Roberson 2018년 8월 26일
Delaying 2 seconds is easy enough: pause(2)
The part about collecting measurements depends upon how the measurements are to be collected. Measurements of what? As you are using Simulink typically measurements would be collected by Simulink block, not by S function.
Kh zaa
Kh zaa 2018년 8월 26일
measurements from simulink are collected and, then, entered to S Function as input. S- function performs an controller. but i need s function to wait 2 second to avoid the transient values of measurements and then perform the controller.
Aquatris
Aquatris 2018년 8월 27일
You can use a switch block. The two inputs to the switch can be "constant 0" and the actual signal. Then you will attach "clock" block to the decider and set the switch block to give constant 0 as output if t < 2 and actual signal if t > 2.
Kh zaa
Kh zaa 2018년 9월 5일
dear Aquatris, my model is very complex with more than 350 measurements. i need to make delay inside S function. thanks

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2018년 8월 27일

0 개 추천

Aquatris's solution is the correct one in many cases.
However, if you are feeding into a controller, then the controller might be taking the differentiation, and the sharp change between 0 and non-zero would be a problem for differentiation. Therefore for you situation you should probably instead use an enabled subsystem https://www.mathworks.com/help/simulink/ug/enabled-subsystems.html, in which the control signal is the output of a comparison block between the clock and a constant block which is the enable time.

댓글 수: 5

Kh zaa
Kh zaa 2018년 9월 5일
I try to use the previous solution, but i found it is not appropraite for my model. I need the delay to be inside S- function (where the controller is implemented). can i do that by modeifing sample time inside s- function or any other solution ? thanks
Walter Roberson
Walter Roberson 2018년 9월 5일
You appear to want a real time delay of 2 seconds relative to a simulated time, and it is not clear as to whether you want the other blocks to be informed about the 2 second delay. If you build the real-time delay into the S function then the other blocks cannot know about it, and you will probably run into problems with block execution order.
It is not clear to me under what circumstances you want the 2 second delay to happen. Only once when the model initializes? Each time the block is simulated? Once per simulated cycle?
Kh zaa
Kh zaa 2018년 9월 6일
My model as follows: S- function collects measurements from Simulink and, then, execute its code. the outputs of S -function are used to update parameters in SIMULINK. the process is repeated until the simultaion is stopped. my problem is that I need S -function to wait for 2 seconds after running the model and, then, execute its code. In other words, i do not need the values of the meaurements during the first 2 seconds of simulation time. Another thing, after updating the parameters (from s-functions output), I need s -fuction to wait also 2 seconds. Thanks in advance
Kh zaa
Kh zaa 2018년 9월 10일
kind reminder
Aquatris
Aquatris 2018년 9월 10일
You can also use a "rate transition" block, which samples the signal in a different time than the simulation time. See image below where I use a sine wave as the source signal and the rate transition block allows to sample it every 2 sec (Zero order hold) and ignores the changes if 2 sec had not passed. Is this what you are trying to achieve?

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 General Applications에 대해 자세히 알아보기

질문:

2018년 8월 26일

댓글:

2018년 9월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by