question

csmcdavid avatar image
0 Likes"
csmcdavid asked csmcdavid commented

Loading multiple flowitems not working

I have flowitems identified by label. The lable directs where the flowitem should go and prgramatically which transporter is to take it to the location (code below). The routing and transporter code is working, however for the last 2 options, the transporter should load 4 items, not 1. I've tried everything I can think of to do this but the cannot get this to work. The transporter is configured to load 4 items, the queue batches 4 items, is there a specific task to define the quantity. I would have thought to just loop through the load command would have accomplished the requirement.


/**Custom Code*/

Object item = param(1);

Object current = ownerobject(c);

string destination = getlabel(item, "TargetQueue");

Object dispatcher;

if (destination == "queue1") {

dispatcher = model().find("Transporter1");

// Create and dispatch a task sequence for Transporter1

TaskSequence ts = TaskSequence.create(dispatcher);

ts.addTask(TASKTYPE_TRAVEL, item, outobject(current, 1)); // Travel to the item

ts.addTask(TASKTYPE_LOAD, item); // Load the item

ts.addTask(TASKTYPE_TRAVEL, outobject(current, 1)); // Travel to the destination

ts.addTask(TASKTYPE_UNLOAD, item, outobject(current, 1)); // Unload the item

ts.dispatch();

return 1; // Send to port 1

} else if (destination == "queue2") {

dispatcher = model().find("Transporter1");

// Create and dispatch a task sequence for Transporter1

TaskSequence ts = TaskSequence.create(dispatcher);

ts.addTask(TASKTYPE_TRAVEL, item, outobject(current, 2)); // Travel to the item

ts.addTask(TASKTYPE_LOAD, item); // Load the item

ts.addTask(TASKTYPE_TRAVEL, outobject(current, 2)); // Travel to the destination

ts.addTask(TASKTYPE_UNLOAD, item, outobject(current, 2)); // Unload the item

ts.dispatch();

return 2; // Send to port 2

} else if (destination == "queue3") {

dispatcher = model().find("Transporter1");

// Create and dispatch a task sequence for Transporter1

TaskSequence ts = TaskSequence.create(dispatcher);

ts.addTask(TASKTYPE_TRAVEL, item, outobject(current, 3)); // Travel to the item

ts.addTask(TASKTYPE_LOAD, item); // Load the item

ts.addTask(TASKTYPE_TRAVEL, outobject(current, 3)); // Travel to the destination

ts.addTask(TASKTYPE_UNLOAD, item, outobject(current, 3)); // Unload the item

ts.dispatch();

return 3; // Send to port 3

} else if (destination == "queue4") {

dispatcher = model().find("Trolley");

// Create and dispatch a task sequence for Trolley

TaskSequence ts = TaskSequence.create(dispatcher);

ts.addTask(TASKTYPE_TRAVEL, item, outobject(current, 4)); // Travel to the item

ts.addTask(TASKTYPE_SETNODENUM, item, NULL, 4);

//ts.addTask(TASKTYPE_LOAD, item); // Load the item

for (int i = 0; i < 4; i++) {

ts.addTask(TASKTYPE_LOAD, item);

}

ts.addTask(TASKTYPE_TRAVEL, outobject(current, 4)); // Travel to the destination

ts.addTask(TASKTYPE_UNLOAD, item, outobject(current, 4)); // Unload the item

ts.dispatch();

return 4; // Send to port 4

} else if (destination == "queue5") {

dispatcher = model().find("Transporter2");

// Create and dispatch a task sequence for Transporter2

TaskSequence ts = TaskSequence.create(dispatcher);

ts.addTask(TASKTYPE_TRAVEL, item, outobject(current, 5)); // Travel to the item

ts.addTask(TASKTYPE_SETNODENUM, dispatcher, NULL, 4);

//ts.addTask(TASKTYPE_LOAD, item); // Load the item

for (int i = 0; i < 4; i++) {

ts.addTask(TASKTYPE_LOAD, item);

}

ts.addTask(TASKTYPE_TRAVEL, outobject(current, 5)); // Travel to the destination

ts.addTask(TASKTYPE_UNLOAD, item, outobject(current, 5)); // Unload the item

ts.dispatch();

return 5; // Send to port 5

} else {

return 0; // Default: No port

}

FlexSim 24.2.2
tasksequence
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

Felix Möhlmann avatar image
2 Likes"
Felix Möhlmann answered csmcdavid commented

You are telling the task executer to load the same item multiple times.

While it's good practice to learn coding in FlexSim, I don't really see why you are writing the task sequences yourself. And why in the Send to Port code.

As long as the "Trolley" and "Transporter2" are allowed to load multiple items, I don't see a reason why you can't use the default task sequence generated when the "Use Transport" option is active. All you'd need is a simple 'Object by Case' function to decide which TE is responsible for the transport.

1737642978996.png

1737642992406.png

batch-and-transport-by-type.fsm

Some info about how the default logic makes loading multiple items possible (so you can keep your code and adjust it):

The default transport task sequence consists of five tasks: Travel (to pickup), Load, Break, Travel (to dropoff), Unload.

The break task causes the TE's "Break To" code to execute.

1737643220886.pngThe code then checks the TE's task sequence queue for a different sequence to switch to, based on some condition. In effect, the TE can choose to interrupt the current task sequence after the load task and continue with a different one, if available and valid.


· 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.