FIFO Queue in Polyscope

first go to the third and after that to the fifth eventhough, the workspace #5 was asking for the robot first

If you want actual first come first serve, the robot should service number 5 first, then 3. By this logic, you could re-queue #1 repeatedly in such a way that #5 never gets serviced, if you scan from top to bottom. I had a similar use case (using 5 stations) and wrote my own queue datastructure in URScript, which I’ve modified for your 6 stations and included below.

global queue = [0,0,0,0,0,0]
queueSize = 6
queueIndex = 0
queueBack = queueSize - 1

def pushQueue(switchNumber):
  count = 0
  while(count < 4000):
    count = count + 1
  end
  queue[queueIndex] = switchNumber
  queueIndex = queueIndex + 1
  if(queueIndex >= queueSize):
    queueIndex = queueIndex - 1
  end
  sync()
end

def popQueue():
  count = 0
  while(count < 4000):
    count = count + 1
  end
  returnNum = queue[0]
  shiftLeft()
  queueIndex = queueIndex - 1
  return returnNum
end

def shiftLeft():
  queue[0] = queue[1]
  queue[1] = queue[2]
  queue[2] = queue[3]
  queue[3] = queue[4]
  queue[4] = queue[5]
  queue[5] = 0
end

def getFirstInQueue():
  return queue[0]
end

def isInQueue(number):
  i = 0
  while(i < queueSize):
    if(number == queue[i]):
      return True
    end
    i = i + 1
  end
  return False
end

isInQueue(stationNumber) returns true if the provided station number is present in the queue, false otherwise
pushQueue(stationNumber) loads the provided station number into the queue at the first empty spot
popQueue() returns the stationNumber in the first spot of the queue and shifts everything else left
getFirstInQueue() returns the station number in the first spot on the queue. Does not alter the queue contents

Here’s how to use the Thread and the “isInQueue()” function to prevent loading the queue with duplicate calls to the same station:
image

And here is how to drive the main program:

image

Let me know if you have any questions about any of it

1 Like