question

Rambabu avatar image
0 Likes"
Rambabu asked Jason Lightfoot edited

How to get the different recipes output from mixer.

Hi flexsimers,

I have a query on mixing the ingredient in different proportions to make different recipes using mixer. In my model I am using mixer to mix four ingredients and make four different recipes. The ratio of ingredients to be mixed are taken in the global table. Is there any solution?

I am attaching the model here: mixing ingredients.fsm

Thankyou.


FlexSim 23.1.3
fluid mixerrecipe tablemixer 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

·
Jason Lightfoot avatar image
0 Likes"
Jason Lightfoot answered Jason Lightfoot edited

Just write to the table which is found at:

Table recipetable = getvarnode(current,"recipetable");

Then read the values from the global table with your format you'll need something like:

Table recipeTable=getvarnode(Model.find("FluidMixer1"),"recipetable");
Table globRecipes=Table("RecipesTable");
string newRecipe="Recipe2";
for (int n=globRecipes.numCols;n>0;n--){
    string ingredient=globRecipes.getColHeader(n);
    int row=recipeTable.getRowByKey(ingredient,1);
    recipeTable[row]["Amount"]=globRecipes[newRecipe][n];
}

But you need to change the ingredient names to match those of the mixer. Example attached.

Note you can also choose the option to update from a global table on the triggers, but that relies on your table format matching what the trigger expects.

mixing-ingredients_jl.fsm



· 4
5 |100000

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

Rambabu avatar image Rambabu commented ·

@Jason Lightfoot The above code indicates only for recipe2. Can you Explain that How to do for remaining recipes by order. I am using global table data only.

Thankyou

0 Likes 0 ·
Jason Lightfoot avatar image Jason Lightfoot ♦ Rambabu commented ·

Create a user command that accepts two parameters: the mixer and the recipe name.

1696680501972.png

In the code place this version of the above script:

Object mixer=param(1);
string newRecipe=param(2);

Table recipeTable=getvarnode(mixer,"recipetable");
Table globRecipes=Table("RecipesTable");
for (int n=globRecipes.numCols;n>0;n--){
    string ingredient=globRecipes.getColHeader(n);
    int row=recipeTable.getRowByKey(ingredient,1);
    recipeTable[row]["Amount"]=globRecipes[newRecipe][n];
}

then call the command using

changeMixerRecipe(<mixerObject>,<recipename>)

where you replace the chevron parameters with a mixer object and a string name of a recipe. eg:

Object mymixer=Model.find("FluidMixer1");
string recipe=getRecipeForOrder(orderNum);   // another user command
changeMixerRecipe(mymixer,recipe);

I can't tell you how you map the order to the recipe - that will be based on the data you know and have.

0 Likes 0 ·
1696680501972.png (9.7 KiB)
Rambabu avatar image Rambabu Rambabu commented ·

@Jason Lightfoot Thankyou for your answer, But I applied that code to my model that shows error. When I debugging the code. It is showing the error in the last line. Could You tell me why it was going wrong.

  1. Table recipeTable=getvarnode(Model.find("FluidMixer1"),"recipetable");
  2. Table globRecipes=Table("RecipesTable");
  3. string newRecipe="Recipe2";
  4. for (int n=globRecipes.numCols;n>0;n--){
  5. string ingredient=globRecipes.getColHeader(n);
  6. int row=recipeTable.getRowByKey(ingredient,1);
  7. recipeTable[row]["Amount"]=globRecipes[newRecipe][n];
  8. }


image-2023-10-09-13-10-53.png

Thankyou

0 Likes 0 ·
Jason Lightfoot avatar image Jason Lightfoot ♦ Rambabu commented ·

I don't think the error screen matches the code - nowhere do you mention Recipe3 - we'd need to see the model to determine what is wrong. Your row headers should look something like this:

1696861383493.png

0 Likes 0 ·
1696861383493.png (2.8 KiB)

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

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