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

2 views (last 30 days)
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.

Answers (1)

Manikanta Aditya
Manikanta Aditya on 28 Apr 2023
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.

Categories

Find more on Complex Logic in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!