SimEvents - Entity Output Switch

5 views (last 30 days)
Robert Hines
Robert Hines on 5 Sep 2019
Commented: Renato SL on 9 Sep 2019
I'm having trouble controlling an entity output switch via a control port.
End Goal:
Model an inspection machine that rejects parts based on whether the inspection passes or not. Entity should be sent to one of two output ports. Entity should be sent to port 1 if a downstream conveyor (i.e., Diverter1Infeed) is running and the entity's Pass attribute is true. Entity should be sent to port 2 if downstream conveyor is stopped or if the entity's Pass attribute is false.
Environment:
  • MATLAB Version 9.5 (R2018b)
  • Simulink Version 9.2 (R2018b)
  • Control System Toolbox Version 10.5 (R2018b)
  • SimEvents Version 5.5 (R2018b)
  • Stateflow Version 9.2 (R2018b)
  • Symbolic Math Toolbox Version 8.2 (R2018b)
  • System Identification Toolbox Version 9.9 (R2018b)
Current Subsystem Implementation:
Inspection Machine.png
Inspection Machine 2.png
Simulink Function getPort(pass):
Inspection Machine 4.png
Matlab System globalGetInspectionOutPort:
Note: "Diverter1InfeedRunning" is a global signal defined in the model workspace.
classdef globalGetInspectionOutPort < matlab.System
% Determines which port a syringe should take when exiting
% the inspection machine
methods(Access = protected)
function setupImpl(obj)
% Perform one-time calculations, such as computing constants
end
function port = stepImpl(obj, pass)
global Diverter1InfeedRunning;
if (Diverter1InfeedRunning && pass)
port = 1;
else
port = 2;
end
end
function resetImpl(obj)
% Initialize / reset discrete-state properties
end
end
end
Error Generated:
Inspection Machine 5.png
Comments:
  • I suspect that the error essentially indicates that the Simulink function getPort() is either generating an error and therefore outputing a value of 0, or it's not being called/executed before the entity output switch control port is needed.
  • I have tried using the SimEvents debugger but it only flashes momentarily on the screen before the Diagnostic Viewer is displayed.
Questions:
  • Is this approach valid?
  • Is using a global variable (e.g., Diverter1InfeedRunning) a viable means of monitoring subsystem status for the purpose of making decisions, such as to which port an entitiy should go?
  • What are recommended ways of feeding the status of other subsystem(s) of the model into the this subsystem for use in making decisions?
  3 Comments
Robert Hines
Robert Hines on 6 Sep 2019
Renato,
Thanks for the feedback.
When I first built my model, I did exactly as you stated. I used an entity attribute to determine the output port.
However, the challenge that I have now is to use the status/state of another subsystem in determining which port to use. If the subsystem immediately following this subsystem is "not running", then the server should not accept any more entities and all entities currently being serviced by the server should go out port 2. This is how the physical equipment works.
My current attempt/method is to reference a global value indicating the downstream's running status in the getPort() function. At this point in time, I've just set the global value to a static value through the Model Explorer. I have not worked on manipulating the global value to reflect the downstream equipment's running status dynamically yet.
From some example models in the online SimEvents documentation, I've seen that it is possible to feedback messages from downstream blocks into upstream blocks. I'm wondering if that is a better approach.
Again, thanks for your comments.
Regards,
Bob
Renato SL
Renato SL on 9 Sep 2019
Hi Bob,
Have you thought about representing the status of the equipment with some kind of signal?
I imagine that a signal generator could generate numbers that would represent the status, for example the system is working if the value is greater or equal to zero and the system isn't working if the value is less than zero (or something like that). Maybe a Repeating Stair Sequence or Random Number block could be used.

Sign in to comment.

Answers (0)

Categories

Find more on Discrete-Event Simulation in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!