Generating multiple entities per sample time with different attribute values

10 views (last 30 days)
Jesse on 26 Aug 2011
I'm trying to create a simple model with multiple entities being generated at a single time step but with different attribute values. I'll try to describe the model I tried to implement this (which seems like the most simple method that I expected to work):
An event triggered Stateflow "flow" chart triggered by a periodic function call generator at 1 second period. The attribute value is an output signal from the chart which feeds a "Set Attribute" block. The entity is generated by a function called Event-Based entity generator. In the flow chart is a single default transition ending on a junction. The "condition" action is the following:
{attr = 1;
attr = 2;
The full chain of blocks are: function call generator, Stateflow chart, Entity Generator, Set Attribute, Attribute Scope, and finally Entity Sink. From the Attribute Scope after the Set Attribute block, I only see the single attribute value "2" at every time step but any of the "Count" statistics seem to show both entities.
When using the Stateflow debugger, it seems that I don't see the entity being generated until after the chart is deactivated at each time step.
I've tried a few other ways as well such as using two separate Stateflow charts, intermediate function-called subsystems to trigger the entity generation, a feedback to my Stateflow chart on the departure count from the Entity Generator (and a loop in the Stateflow chart to only progress after the entity is generated) etc. Nothing I've tried seems to work however.
Now, here are my questions:
1. Can someone explain if this should be possible?
2. If so, try to describe what I should change to do this?
3. In my entity generator I have the "Allow OUT port blocking" enabled. If I disable this I get an error that the output is blocked however none of the subsequent blocks, as far as I understood, should block the entity from progressing. Can someone also explain this?
Here's a link to the file.
  1 Comment
Jesse on 26 Aug 2011
From some more researching it seems that this should be possible but I think the issue is related to trying to do this with "signals" which are inherently time based. Presumably if the synchronization between when the entity arrives at the "Set Attribute" block this would work. I saw a few references to including a zero time single Server block and I also tried this but no where that I placed it seemed to make any difference. For now I've decided to implement this with multiple generator blocks and a Path Combiner block. This is sufficient for my particular use case where the set of attribute values is fixed prior to simulation but this would not work if that were not the case. I'm going to leave this question open for another few days to see if someone else has some other ideas on how to do this.

Sign in to comment.

Answers (2)

Rick Rosson
Rick Rosson on 26 Aug 2011
  1. What release of MATLAB are you using?
  2. Can you please post one or more screenshots of your Simulink/SimEvents model, and your Stateflow chart?
  3. Please take a look at the documentation in SimEvents for what is called the "Discrete Event Subsystem". You may find that it will help
>> docsearch('"discrete event subsystem"');
  1 Comment
Jesse on 26 Aug 2011
Thanks for the response. It's R2010b. I'm not sure how to attach images to the post. I've uploaded my example model to the File Exchange but am just waiting for it to be approved. I have looked at the discrete event documentation but it wasn't clear to me if that would solve the issue. I'll go back though and actually test something with one of these subsystems.

Sign in to comment.

Devdatt Lad
Devdatt Lad on 26 Aug 2011
From your description, it seems that you're expecting interspersed block execution to happen, i.e. generate an entity between the first trigger and the second trigger. What actually happens (and you've observed) is the Stateflow chart will execute completely at a given time before any entities are generated by the next block. You can execute a block multiple times at a given time, but not interspersed with other blocks.
You can redesign your system so that your Stateflow chart does basically just the following:
{attr = attr+1; trigger}
with initial value of attr=0. The trigger will fire the Event-Based Entity Generator, generate the entity, which will then go to the Set Attribute block, set the attribute. Now add an Entity-Based Function Call Generator block after the Set Attribute block which will send another function-call back to the Stateflow chart indicating that the entity generation is complete, and asking it for the next trigger. Upon receiving this function-call the Stateflow chart executes again sending out another trigger for the next entity.
So the Stateflow chart will be receiving 2 function-calls, one from the Function-Call Generator and the other from the Entity-Based Function-Call Generator. Use a Mux to combine them for the Stateflow input.
Of course, you will need to have an escape condition in your Stateflow chart so that after N function-calls are received at a given time, you will stop sending triggers and reset for the next time step.
Haven't tried this out myself yet, so it might need some tweaking to get just right. I think the demo model sedemo_async_stateflow might have some hints on this.
Jesse on 26 Aug 2011
Well it seemed like the solution. Unfortunately the attribute (attr output from Stateflow) doesn't seem to change, at least the change isn't registered by the Set Attribute block (using the Stateflow debugger however does show the value changing). I also connected a SimEvents Signal Scope and that too never shows the value of attr changing. I do appreciate your description of the "interspersed block execution". That is a good concept of which to be aware. I'll keep it in mind as I continue to try to get this to work.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!