DoF - a Robotiq Community
Warning sign
The Dof Community was shut down in June 2023. This is a read-only archive.
If you have questions about Robotiq products please reach our support team.
matthewd92

The question I would ask is why a thread in the function?   Do you need this to be processed in the background?  If not, this is a quick function call and so could easily be inline.  If you need to know always what tool is loaded, like if someone paused the robot and swapped tools then you need the thread to loop so that it is always running. The way it's written it's a single execution background function.

The function would simply be as below, notice I am using a return statement and not assigning the global variable directly.

def toolStatus():
  if (get_standard_digital_in(0)):  
     return 1
  elif (get_standard_digital_in(1)):
     return 2
  end
  return 0
end

Use it like this:
ToolAct=toolStatus()
Couple of things to point out, since this function is not dependent on global state its easily tested and secondly, get_digital_in was deprecated quite a while ago and replaced with more specific calls which you see represented in the code above.  Since the function has been officially deprecated they will most likely remove it from the language in the future which would cause your code to break when the update comes out.

Since the status of the `get_standard_digital_in(n)` call is a boolean return value I do not need to compare it to True or False as it is True or False, I can simply state in my logic that it either is that value by stating it directly or I can negate it by saying something like this

if (!get_standard_digital_in(0)):  #Read as "if not true" or in more common vernacular "if false"