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.
Generating multiple entities per sample time with different attribute values
3 次查看(过去 30 天)
显示 更早的评论
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;
trigger;
attr = 2;
trigger;}
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?
回答(2 个)
Rick Rosson
2011-8-26
- What release of MATLAB are you using?
- Can you please post one or more screenshots of your Simulink/SimEvents model, and your Stateflow chart?
- 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"');
Devdatt Lad
2011-8-26
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Simulink Functions 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!