Handshake Logic

Hello, I am using a UR 10E to weld 2 separate stations, station A and station B. I want to be able to use two separate buttons on either station to tell the robot that station A or B is ready. While station A is welding the operator can setup and press the button for station B and the robot will know that the station is ready and will automatically go to station B to weld. Same thing with station A, while station B is welding the operator can setup station A and hit the “ready” button and it will tell the robot that station A is ready once it is done welding station B.

We are currently using 1 button for a DI to start each station.

Trying to figure out how I would go about this using Polyscope. I am a bit lost, so any help would be appreciated.

You’ll need to use a thread for this. It depends how fancy you want to be. I had written a small queue class in urscript and implemented methods like push and pop to manage it. Otherwise, just using very basic variable assignment is fine.

The term you’re looking for here is “latching.” Here you are “latching” the operator’s input into a variable. So instead of using the input signal DIRECTLY, you let the input set a variable, which the robot is then free to check at any time.

Hey, Thank you for this. Saved me alot of time figuring it out on my own.

I am having an issues where sometimes it will go back to the same side even without any input. It doesnt do this all the time but once and a while it will be done welding station B and then it will got back to station B without any ready input.

i double checked that i had it set itself to false and it was correct. I even tried adding an assignment in the sub program for the station B to make sure it was set to false after starting and it still did it. not every time but once and a while.

any ideas on what this could be?

can you screenshot your code?

You’re probably encountering race conditions. For example in my code, what happens if you were to hold the button tied to DI0 for several seconds? The main program will see the variable has been set true, and it will set it false, then start the sub program for station 1. Except the thread still sees the input is held, so it immediately resets it to true. There’s debouncing logic that is likely needed.

global queue = [0,0,0,0]
queueSize = 4
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] = 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

Here’s the queue class that I had written for this. You’re welcome to give it a try. Just paste it all into a file and load it into a Script node and put it in the before start. After that, the program can be modified to look like this:

Note, this queue can only hold 4 inputs at a time (it was made before UR had real structs/ dynamic arrays), but since you only need 2 it should work fine.

Just out of curiosity…

what is the while loop for?

count = 0
while(count < 4000):
count = count + 1
end

Who knows. That was written by years-ago Eric. I want to say I was just having a weird race condition/timing issue and so that loop consumed some time. I had smashed 2 scripts together, this queue script and another that flashes outputs (how I was signaling to the operator that something was queued or not). It’s possible that it had more bearing on the flashing logic than the actual queue.