MATLAB Answers

0

SimEvents - Entity Output Switch

Robert Hines さんによって質問されました 2019 年 9 月 5 日 16:24
最新アクティビティ Renato SL
さんによって コメントされました 2019 年 9 月 9 日 8:46
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 件のコメント

Renato SL
2019 年 9 月 6 日 7:55
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 2019 年 9 月 6 日 12:28
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
2019 年 9 月 9 日 8:46
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.

サインイン to comment.

0 件の回答


Translated by