How to sequence signal inputs to state chart over sample intervals of 10?

조회 수: 1 (최근 30일)
Nicholas Borrego
Nicholas Borrego 2023년 3월 31일
답변: Manikanta Aditya 2023년 4월 28일
I am making a classic model of a fruit-packing plant. I am using two momentary buttons to start and stop the model in infinite sample time, which works as intended. However I want to create a test scenario where the signals change in intervals of 10 time samples, but I am not sure how to implement this. Here's what I mean:
  1. At sample time t = 0, start == 0, stop == 0. (Machine is OFF)
  2. Run simulation for 10 samples. (Machine is OFF)
  3. At t = 20, start == 1, stop == 0. (Machine starts)
  4. Run simulation for 10 samples. (Machine runs)
  5. At t = 30, start == 0, stop == 1. (Machine stops)
  6. Run simulation for 10 samples. (Machine is in standby)
  7. At t == 40, start == 1, stop == 0. (Machine restarts)
  8. Run simulation for 10 samples (Machine runs)
Any help is appreciated, hope my question is clear.

답변 (1개)

Manikanta Aditya
Manikanta Aditya 2023년 4월 28일
Hi Nicolas
As per my understanding, you are interested to know how to create a test scenario where the signals change in intervals of 10-time samples.
Here is an example showing how you can do it:
% Set initial values
start = 0;
stop = 0;
% Main simulation loop
for t = 1:50 % iterate over 50 time steps
% Update start and stop signals based on current time
if t == 21
start = 1;
stop = 0;
elseif t == 31
start = 0;
stop = 1;
elseif t == 41
start = 1;
stop = 0;
end
% Run simulation for 1 time step
% Replace this with your actual simulation code
disp(['At time ' num2str(t) ': start = ' num2str(start) ', stop = ' num2str(stop)]);
end
I hope this resolves the issue you were facing.

카테고리

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