Adding up the block statistics for two adjacent blocks in Simevents

1 次查看(过去 30 天)
Hi
I've spent two days tearing my hair out trying to understand upgraded Simevents (Legacy Simevents much easier!). Frustration aside....
I have two adjacent Entity Servers, one feeding the next. (One is a one item painting rack for widgets, followed by an 8 item shelf drying rack for the painted widgets).
I would like to create a scope with a counter showing the number of widegts in both servers i.e. a sum. I have created "Number of entities in Block, n" data ports for the blocks in Statistics but can't for the life of me add the two numbers together and output to:
  1. A scope or
  2. A function (I'd like to do some switching up and down stream based on how many are here)
I know this will be ridiculously easy but .....
Thanks for the help.

采纳的回答

Paul
Paul 2020-9-6
编辑:Paul 2020-9-6
Abdolkarim,
I definitely owe you a beer. This is a massive, help in particular the attached example.
In this example the Server calls the function and returns the result to the attribute (attribute1 in this example).
If I wanted to create a function that operates independent of a single entity how might I do that?
A specific example might be sending a control signal to an output or output switch that depends on the amouint of WIP in the servers ? I'd like to call a function from the switch but that doesn't seem to be an option - requiring instead a control signal. Maybe introduce a [logic] buffer upstream and call from that?
Below I've modified your function to allow for a max number in the painting cycle (seal_cycle_max), checked to see if it's grerater that max and want to create a control signal that switches products upstream. However I'm unclear how to get the control_signal from the Matlab block to the Input Switch. There seem to be to "out" blocks both in the image and am unsure if I use one of these (what's the difference?)or something else.
function seal_control_signal = MyFunction (WIP_Server1, WIP_Server2, seal_cycle_max)
WIP = WIP_Server1 + WIP_Server2;
if mystatistic >= seal_cycle_max
control_signal=2,
else
control_signal=1
end
seal_control_signal=control_signal;
Many thanks. Once I get going I won't be such a nuisance!
Paul
  2 个评论
Abdolkarim Mohammadi
编辑:Abdolkarim Mohammadi 2020-9-7
Such operations don't need functions. You can simply implement it with the Switch block (Do not confuse it with SimEvent's Entity input switch or Entity output switch). Simulink functions like the one I posted are best when you need to call them within event action.
Paul
Paul 2020-9-7
ok, that makes sense. This also highlights the new version of Simevents seems to lean more on Simulink than before. I had largely been ignoring Simulink functions. Thanks very much for clarifying.

请先登录,再进行评论。

更多回答(1 个)

Abdolkarim Mohammadi
编辑:Abdolkarim Mohammadi 2020-9-4
If I have understood you correctly, you want to calculate the system's WIP (Work In Progress). You can use the Add block to sum up the number of entities in each of the blocks. For example:
The scope shows:
  2 个评论
Paul
Paul 2020-9-5
Thanks Abdolkarim you are a legend!
That's incredibly helpful and works as I wanted.
Would you mind clarifying a couple of things
  1. What is the difference between the rectangular Add block you use above and the circular "Sum" block in Simulink under "Commonly used blocks" in the the 'Simulink Library Brower'?
  2. If I wanted to create a Matlab function that used this Statistics data for more complex calculations (e.g. involving process time variability I may introduce) how to I pass this data to a Matlab function? I have seen how to call a function from within "Events Actions" and embed and call a Matlab Function in a Simulink function but am not clear how to use Statistics,for example 'Number in block' as above, in a function. Thanks.
P
Abdolkarim Mohammadi
编辑:Abdolkarim Mohammadi 2020-9-5
Many thanks, Paul.
1) They just differ visually. I prefer rectangular because it is visually consistent with other blocks.
2) You want the function to be callable from event actions, so you should use Simulink Function. And you want to write textual MATLAB functions within it, so it should contain MATLAB function block. I have attached an example, where the Entry event action of the second server calls GetWIP() function.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Discrete-Event Simulation 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by