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

4 visualizaciones (últimos 30 días)
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.

Respuestas (1)

Manikanta Aditya
Manikanta Aditya el 28 de Abr. de 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.

Categorías

Más información sobre Complex Logic en Help Center y File Exchange.

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by