How to Make a Simulink Scheduler for a Matlab Block Function to run each 40 ms of simulation?

조회 수: 4 (최근 30일)
Hello, I am trying to make a controller for a system that must run every 40-50 ms. I am having difficulties with Stateflow because if I try to adapt the example given by Mathworks the matlab blocks runs just once.
In the picture you see the controller that I adapted from the example
this is "Edge to Function" block
and this is the simple subsystem called by Call() event
inside the matlab block there is only
j = 0;
for i = 1:10
j = j+1;
end
and here the plot of the output j, as you can see the block is triggered just once
Can you please help me to understand how to call the matlab block every 40 seconds or address me to a good stateflow scheduler tutorial? I haven't been lucky

채택된 답변

Fangjun Jiang
Fangjun Jiang 2022년 8월 10일
Use a Function-call Generator block, specify the sample time. Put the MATLAB Function block inside a triggered subsystem, specify the trigger as Function-call.
  댓글 수: 3
Fangjun Jiang
Fangjun Jiang 2022년 8월 18일
"triggered system in a loop"?? It sounds too complicated. Please state your task, there might be a better way to construct the model to implement it.
Gianluca Mammone
Gianluca Mammone 2022년 8월 18일
편집: Gianluca Mammone 2022년 8월 18일
My task is to create a controller that runs every 40 Ms. The dynamic differential model of the plant is a matlab function followed by integrators that calculate the state.
This controller every 40 ms is triggered, collect the actual state (the output of the integrator which is the output of the Matlab Function Block), and gives the value of the controlled variable.
The controller is quite heavy (MPC with QP), so I am not too prone to use zero-older hold block
EDIT: I think I solved it, thank you for your patience.
One of the inputs (let's call it dx) of the triggered block was the direct output of the matlab function. Since the matlab function needed the output of the controller to run, there was this data dependency where dx was not initialized or defined.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Complex Logic에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by