I updated your model with work forwarding points instead of a work loop. I connected work forwarding points to each control point where the AGV drops off items. The Deposito queues' control points are the ones forwarding work to the drop off control points. This means that when the AGV gets to a drop off point, it will now see work from the 4 Deposito queues. Next is to make sure we can sort them by distance.
To sort by distance, we use CP labels and the distancetotravel command. When the AGV unloads, it gets a new CP label at the point it just unloaded at. Each queue also gets a CP label which references the CP it's connected to. The distancetotravel code is saying to find the distance between the CP where the AGV just unloaded and the CP of the items waiting to be loaded. The value.up.CP code is saying look at the CP label on the object that contains the item ('value' is the item and 'up' is the queue it is in).
The last thing to do is make sure the list is sorting by the shortest distance to travel. In process flow (which I updated to the AGV with Work Forwarding template), use the Query on the list that pulls the next location to order by TravelDistance. Note: I changed most the queues to only hold 10 items so I could test that it was working as expected. projeto-v4-teste-em.fsm
