SimEvents - Entity Output Switch
Show older comments
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:


Simulink Function getPort(pass):

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:

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
Renato SL
on 6 Sep 2019
I have never done what you did with the global variable, so I cannot say if it is a valid approach or not. However I am curious on how you define Diverter1InfeedRunning. How do you assign its value?
Regarding your first comment, I think your first suspicion happens. Somehow the output is 0 and so the error message is generated. Again, I have never done something like your globalGetInspectionOutPort, so I cannot comment about its implementation. What block do you use for that? Is it a self-defined function?
I used SimEvents for the project I am working on, and for the control of Entity Output Switch, what I did is to route entities by its attributes.
What I would do if I work on something like you are doing is to add an attribute, say 'PassFinalDecision'.
The attribute will hold the value of 1 or 2, depending on the status of the conveyor & the attribute 'Pass' [like port in your getPort()]. This process can be done in the Entity Server block just after your Entity Server 1 [comment: I think this is where you call getPort(pass)].
Finally I'll have the Entity Output Switch route entities using 'PassFinalDecision' attribute.
Robert Hines
on 6 Sep 2019
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.
Answers (0)
Categories
Find more on Discrete-Event Simulation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!