question

Benjamin W2 avatar image
0 Likes"
Benjamin W2 asked Benjamin W2 commented

How to dynamically load recipe into FlowMixer using FloWorks?

Hi @Mischa Spelt,

I am trying to load a recipe into a FlowMixer on the "On Empty" trigger. The recipes are all stored in the recipes table. Each time the mixer empties, the "recipeCounter" global variable increments and tells the mixer to load the next recipe on the "Schedule" table.

I am trying to load the recipe using the following code in the "On Empty" trigger. I know that the code is running, but it will not load the recipe into the Flow Mixer.

RecipeCounter++;
int recipeCounter = RecipeCounter;

string nextRecipe = Table("Schedule")[RecipeCounter][1];

if (nextRecipe == "Flat")
{
	current.as(FlowMixer).loadRecipe("Flat Prelatex");
	current.as(FlowMixer).startRecipe();
}

else if (nextRecipe == "Semi")
{
	current.as(FlowMixer).loadRecipe("Semi-gloss Prelatex");
	current.as(FlowMixer).startRecipe();
}

else if (nextRecipe == "High")
{
	current.as(FlowMixer).loadRecipe("High-gloss Prelatex");
	current.as(FlowMixer).startRecipe();
}

Here is a picture of the recipe that I am trying to load:

Is there something that I am missing? I also made sure to uncheck the "Continuously repeat recipe" box.

sample-paint-factory-6.fsm

FlexSim 18.2.3
FloWorksmixer recipe
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

Mischa Spelt avatar image
0 Likes"
Mischa Spelt answered Benjamin W2 commented

Hi Benjamin,

TL;DR: We'll fix the bug, you can temporarily work around by adding the following code at the top of the On Empty trigger:

int currentStep = getvarnum(current, "curstep");
if(currentStep > 0) {
  // Mixer is not idle yet, On Empty will fire again in just one or two events from now.
  return 0;
} 


What is going on?

Thanks for bringing this to our attention. There is an issue in the Flow Mixer, and by the looks of it has been for a while. At first I thought that it was just a timing problem where the mixer hadn't registered its Idle state yet, and therefore did not load the recipe, but it's worse: in your model the On Empty trigger actually fires twice! So it seems like recipes aren't loaded at all, but what happens is that the first time the mixer is not internally set to idle yet and the recipe change is rejected. Then the second time you increment the recipe counter again and the recipe is loaded... but that happens to be the same product that was already on it! In fact, the odd rows of your schedule table will give you Flat, Flat, Flat, Semi, Flat.

I will fix this in an upcoming version. We are finalizing a bug fix version for 19.0 which will be out shortly. For now, you can use the workaround at the top of this answer. It checks whether the mixer is internally idle by looking at the curstep variable. When you step through you will see that the first time the trigger fires, this value is still set to 3 (the last step of the Flat recipe), then the On Mixer Empty event fires and the curstep is reset to 0 -- this is the moment that loadRecipe() will actually accept a change.

In addition, there seems to be a bug in the return value of loadRecipe that I need to resolve with FlexSim, but the idea is you can check that as well: it's supposed to return 1 when the recipe change is successful and 0 when it is not because the product is invalid or the mixer is not idle, for example.

Some general tips

As a side note, I noticed you have a FlexSim Fluid Ticker in your model which is generating a lot of events. If you are only using FloWorks objects, you may want to remove the ticker to speed up your model a bit.

Also, since you are already using Process Flow in the model: there is a Process Flow template to make a mixer run through a production schedule. If you haven't checked it out already, have a look -- you can add it with the Process Flow button on the toolbar, "Add a FloWorks Process Flow" -- "Mixers with recipe table".

· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Benjamin W2 avatar image Benjamin W2 commented ·

Thank you! I appreciate the feedback.

0 Likes 0 ·