Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5

Help simulating two UR5 robots simultaneously using python

#1
I am having trouble simultaneously simulating two robots at the same time. I have two robots, "Robot A" and "Robot B" that each perform a large function. These functions reference user defined functions in two separate files, but they both work.

The trouble I'm having is that I can get either robot to complete its function, but not both. What am I doing wrong here, and how do I need to modify the robolink commands to make this setup work? Can someone assist?



My python code is pasted below. I am not sure what I am doing differently than on the following example:

//www.sinclairbody.com/doc/en/PythonAPI/exam...e-3-robots

Thanks!


Code:
# Type help("robolink") or help("robodk") for more information
# Press F5 to run the script
# Documentation: //www.sinclairbody.com/doc/en/RoboDK-API.html
# Reference: //www.sinclairbody.com/doc/en/PythonAPI/index.html
# Note: It is not required to keep a copy of this file, your python script is saved with the station
from robolink import * # RoboDK API
from robodk import * # Robot toolbox
from M75_Pick_Place import *
from M75_Place_Clean import *
import threading
import time

def run_robot_a():
# Gather required items from the station tree for Robot A
rdk_a = Robolink()
robot_a = rdk_a.Item('UR5e')

rdk_a.ShowMessage("Robot A")
#robot_a = rdk_a.Item('UR5e')
a_home = rdk_a.Item('A_HOME') #Joint target
a_pick_to_clean_0 = rdk_a.Item('A_PICK_TO_CLEAN0') #Joint target
a_pick_to_clean_1 = rdk_a.Item('A_PICK_TO_CLEAN1') #Joint target
a_pick_to_clean_2 = rdk_a.Item('A_PICK_TO_CLEAN2') #Joint target
a_pick_to_clean_3 = rdk_a.Item('A_PICK_TO_CLEAN3') #Joint target

bin_input_active = rdk_a.Item('Active Input Bin') #Reference frame of 'Active Bin'
m75_tray = rdk_a.Item('M75 Input Tray') #Reference frame of 'M75 Tray'
disk_3a = rdk_a.Item('Disk3A') #Disk3A Reference Frame
disk_1a = rdk_a.Item('Disk1A') #Disk1A Reference Frame
robot_a.setPoseFrame(bin_input_active)
blade_count = 0


#Set linear speed, acceleration, and rounding for Robot A
robot_a.setSpeed(500)
robot_a.setAcceleration(1200)
robot_a.setRounding(20)

#Start at safe home position
robot_a.MoveJ(a_home)
robot_a.MoveJ (a_pick_to_clean_0)

#循环每个位置
while blade_count < 84:
#Update location of active bin
m75_set_active_bin_pos(rdk_a, robot_a, blade_count)
#Pick
robot_a.setSpeed(500)
m75_pick_fwd(rdk_a, robot_a)
#Grip part here
m75_pick_rev(rdk_a, robot_a)
robot_a.setSpeed(500)
#Pause
robot_a.Pause(0.5)

#Move safely out of pick area
robot_a.setRounding(20)
robot_a.MoveJ (a_pick_to_clean_0)
robot_a.MoveJ(a_pick_to_clean_1)
robot_a.MoveJ(a_pick_to_clean_2)
robot_a.MoveJ(a_pick_to_clean_3)

#Clean Disk 3A
robot_a.setPoseFrame(disk_3a)
m75_clean_3a(rdk_a, robot_a)

#Reset cleaning position
robot_a.MoveJ(a_pick_to_clean_3)

#Clean Disk 1A
robot_a.setPoseFrame(disk_1a)
m75_clean_1a(rdk_a, robot_a)

#Move safely from clean area to pick area
robot_a.setRounding(20)
robot_a.MoveJ(a_pick_to_clean_3)
robot_a.MoveJ(a_pick_to_clean_2)
robot_a.MoveJ(a_pick_to_clean_1)
robot_a.MoveJ (a_pick_to_clean_0)

robot_a.setPoseFrame(bin_input_active)

#Place
robot_a.setSpeed(500)
m75_place_fwd(rdk_a, robot_a)
#Release part here
m75_place_rev(rdk_a, robot_a)
robot_a.setSpeed(500)

#Pause
robot_a.Pause(0.5)

#Increase blade count for next pick
blade_count = blade_count + 1


#Move Safely back to home position
robot_a.MoveJ (a_pick_to_clean_0)
robot_a.MoveJ(a_home)



def run_robot_b():
# Gather required items from the station tree for Robot B
rdk_b = Robolink()
robot_b = rdk_b.Item('UR5e2')

rdk_b.ShowMessage("Robot B")
#robot_b = rdk_a.Item('UR5e2')
bin_output_active = rdk_b.Item('Active Output Bin') #Reference frame of 'Active Bin'
table_center = rdk_b.Item('Table Center')
b_home = rdk_b.Item('B_HOME')
b_home_to_clean = rdk_b.Item('B_HOME_TO_CLEAN')
b_place_to_clean_0 = rdk_b.Item('B_PLACE_TO_CLEAN0')
b_place_to_clean_1 = rdk_b.Item('B_PLACE_TO_CLEAN1')
b_place_to_clean_2 = rdk_b.Item('B_PLACE_TO_CLEAN2')
b_place_to_clean_3 = rdk_b.Item('B_PLACE_TO_CLEAN3')

blade_count = 0

#Set linear speed, acceleration, and rounding for Robot A
robot_b.setSpeed(500)
robot_b.setAcceleration(1200)
robot_b.setRounding(20)


#Start at safe home position
robot_b.MoveJ(b_home)

#Move from home position to clean position
robot_b.MoveJ(b_home)
robot_b.MoveJ(b_home_to_clean)
robot_b.MoveJ(b_place_to_clean_3)

#循环每个位置
while blade_count < 84:


#Swap
#robot_b.setPoseFrame(table_center)
#b_m75_swap(rdk_b, robot_b)

#robot_b.MoveJ(b_place_to_clean_1)
#robot_b.MoveJ(b_place_to_clean_2)


#Clean at Disk 3B
robot_b.Pause (0.50)

#Move from clean area to pick area
robot_b.MoveJ(b_place_to_clean_3)
robot_b.MoveJ(b_place_to_clean_2)
robot_b.MoveJ(b_place_to_clean_1)
robot_b.MoveJ(b_place_to_clean_0)

#Place
robot_b.setPoseFrame(bin_output_active)
#Update location of active bin
b_m75_set_active_bin_pos(rdk_b, robot_b, blade_count)

robot_b.setSpeed(500)
b_m75_place_fwd(rdk_b, robot_b)

#Release part here

#Pause
robot_b.Pause(0.25)

b_m75_place_rev(rdk_b, robot_b)
robot_b.setSpeed(500)


#Move safely out of place area back to clean area
robot_b.setRounding(20)
robot_b.MoveJ(b_place_to_clean_0)
robot_b.MoveJ(b_place_to_clean_1)
robot_b.MoveJ(b_place_to_clean_2)
robot_b.MoveJ(b_place_to_clean_3)

#Increase blade count for next place
blade_count = blade_count + 1


#Move Safely back to home position
robot_b.MoveJ(b_home)



##--------------------------Max Width-----------------------------------------#
## The program starts here:

demask_station = Robolink()
#robot_a = demask_station.Item('UR5e')
#robot_b = demask_station.Item('UR5e2')

#demask_station.ShowMessage("Before Threads")

thread_a = threading.Thread(target = run_robot_a, args = ())
thread_b = threading.Thread(target = run_robot_b, args = ())

thread_a.start()
thread_b.start()



thread_a.join()
thread_b.join()

#demask_station.ShowMessage("After Threads")
#2
I was able to solve this problem after a ton of debugging via two solutions of which I chose the 2nd option:

1. Adding a short sleep command after the first thread start call.
Code:
thread_a.start()
sleep(0.01)
thread_b.start()



2. Removing the last ShowMessage line of code. It appears this is a slower function. I was using it to debug before I realized I just could print to the console.
Code:
def run_robot_a():
# Gather required items from the station tree for Robot A
rdk_a = Robolink()
robot_a = rdk_a.Item('UR5e')

rdk_a.ShowMessage("Robot A")




Users browsing this thread:
1 Guest(s)