Simulation mode
This commit is contained in:
parent
d92ceafa57
commit
d0083ed33f
@ -30,6 +30,7 @@ def query_search(partnum, source):
|
|||||||
fprint("Searching for " + partnum)
|
fprint("Searching for " + partnum)
|
||||||
if source == "Belden":
|
if source == "Belden":
|
||||||
token_url = "https://www.belden.com/coveo/rest/token?t=" + str(int(time.time()))
|
token_url = "https://www.belden.com/coveo/rest/token?t=" + str(int(time.time()))
|
||||||
|
try:
|
||||||
with requests.get(token_url) as r:
|
with requests.get(token_url) as r:
|
||||||
out = json.loads(r.content)
|
out = json.loads(r.content)
|
||||||
token = out["token"]
|
token = out["token"]
|
||||||
@ -47,7 +48,6 @@ def query_search(partnum, source):
|
|||||||
'Authorization': f'Bearer {token}',
|
'Authorization': f'Bearer {token}',
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
}
|
}
|
||||||
try:
|
|
||||||
with requests.post(search_url, headers=headers, data=search_data) as r:
|
with requests.post(search_url, headers=headers, data=search_data) as r:
|
||||||
a = r.text
|
a = r.text
|
||||||
a = json.loads(a)
|
a = json.loads(a)
|
||||||
|
@ -311,8 +311,6 @@ class LEDSystem():
|
|||||||
|
|
||||||
|
|
||||||
def setring(self, r,g,b,idx):
|
def setring(self, r,g,b,idx):
|
||||||
print(self.rings)
|
|
||||||
print(self.rings[idx])
|
|
||||||
ring = self.rings[idx]
|
ring = self.rings[idx]
|
||||||
for pixel in range(ring[2],ring[3]):
|
for pixel in range(ring[2],ring[3]):
|
||||||
self.setpixel(r,g,b,pixel)
|
self.setpixel(r,g,b,pixel)
|
||||||
@ -442,7 +440,7 @@ class LEDSystem():
|
|||||||
dgs /= sizerem
|
dgs /= sizerem
|
||||||
dbs /= sizerem
|
dbs /= sizerem
|
||||||
sum += abs(drs) + abs(dgs) + abs(dbs)
|
sum += abs(drs) + abs(dgs) + abs(dbs)
|
||||||
print(drs,dgs,dbs)
|
#print(drs,dgs,dbs)
|
||||||
for x in range(idxa,idxb):
|
for x in range(idxa,idxb):
|
||||||
old = self.exactdata[x]
|
old = self.exactdata[x]
|
||||||
new = list(old)
|
new = list(old)
|
||||||
|
42
run.py
42
run.py
@ -30,6 +30,8 @@ from search import JukeboxSearch
|
|||||||
from pyModbusTCP.client import ModbusClient
|
from pyModbusTCP.client import ModbusClient
|
||||||
from uptime import uptime
|
from uptime import uptime
|
||||||
|
|
||||||
|
# set to false to run without real hardware for development
|
||||||
|
real = False
|
||||||
|
|
||||||
mbconn = None
|
mbconn = None
|
||||||
config = None
|
config = None
|
||||||
@ -60,6 +62,7 @@ cable_list_state = list()
|
|||||||
just_placed = -1
|
just_placed = -1
|
||||||
ring_animation = None
|
ring_animation = None
|
||||||
led_set_mode = None
|
led_set_mode = None
|
||||||
|
sensors = [0,0,0,0]
|
||||||
|
|
||||||
def arm_start_callback(res):
|
def arm_start_callback(res):
|
||||||
fprint("Arm action complete.")
|
fprint("Arm action complete.")
|
||||||
@ -310,7 +313,10 @@ def setup_server(pool):
|
|||||||
global jbs
|
global jbs
|
||||||
|
|
||||||
arm = Rob(config)
|
arm = Rob(config)
|
||||||
|
if real:
|
||||||
pool.apply_async(ur5_control.powerup_arm, (arm,), callback=arm_start_callback, error_callback=handle_error)
|
pool.apply_async(ur5_control.powerup_arm, (arm,), callback=arm_start_callback, error_callback=handle_error)
|
||||||
|
else:
|
||||||
|
arm_ready = True
|
||||||
global ledsys
|
global ledsys
|
||||||
ledsys = LEDSystem()
|
ledsys = LEDSystem()
|
||||||
#pool.apply_async(ledsys.init, callback=led_start_callback)
|
#pool.apply_async(ledsys.init, callback=led_start_callback)
|
||||||
@ -343,6 +349,7 @@ def setup_server(pool):
|
|||||||
while arm_ready is False:
|
while arm_ready is False:
|
||||||
sleep(0.1)
|
sleep(0.1)
|
||||||
|
|
||||||
|
if real:
|
||||||
ur5_control.init_arm(arm)
|
ur5_control.init_arm(arm)
|
||||||
fprint("Arm initialized.", sendqueue=to_server_queue)
|
fprint("Arm initialized.", sendqueue=to_server_queue)
|
||||||
|
|
||||||
@ -397,6 +404,7 @@ def get_open_spot(sensordata):
|
|||||||
|
|
||||||
def mainloop_server(pool):
|
def mainloop_server(pool):
|
||||||
# NON-blocking loop
|
# NON-blocking loop
|
||||||
|
global real
|
||||||
global ring_animation
|
global ring_animation
|
||||||
global led_set_mode
|
global led_set_mode
|
||||||
global just_placed
|
global just_placed
|
||||||
@ -416,7 +424,7 @@ def mainloop_server(pool):
|
|||||||
global mainloop_get
|
global mainloop_get
|
||||||
global cable_list_state
|
global cable_list_state
|
||||||
global scan_value
|
global scan_value
|
||||||
print(" ***** Running main system loop ***** ")
|
#print(" ***** Running main system loop ***** ")
|
||||||
if killme.value > 0:
|
if killme.value > 0:
|
||||||
killall()
|
killall()
|
||||||
|
|
||||||
@ -429,10 +437,12 @@ def mainloop_server(pool):
|
|||||||
ledsys.mainloop(led_set_mode, ring_animation)
|
ledsys.mainloop(led_set_mode, ring_animation)
|
||||||
led_set_mode = None
|
led_set_mode = None
|
||||||
else:
|
else:
|
||||||
fprint("Not triggering LED loop: no ring animation")
|
pass
|
||||||
|
#fprint("Not triggering LED loop: no ring animation")
|
||||||
|
|
||||||
if mode == "Startup":
|
if mode == "Startup":
|
||||||
#counter = 54 # remove for demo
|
if not real:
|
||||||
|
counter = 54
|
||||||
if counter < 54:
|
if counter < 54:
|
||||||
# scanning cables
|
# scanning cables
|
||||||
if arm_state is None:
|
if arm_state is None:
|
||||||
@ -512,7 +522,8 @@ def mainloop_server(pool):
|
|||||||
while len(tmp) < 54:
|
while len(tmp) < 54:
|
||||||
tmp.append(False) # must have 54 entries
|
tmp.append(False) # must have 54 entries
|
||||||
|
|
||||||
#cable_list = tmp # comment out for real demo
|
if not real:
|
||||||
|
cable_list = tmp # comment out for real demo
|
||||||
|
|
||||||
for idx in range(len(cable_list)):
|
for idx in range(len(cable_list)):
|
||||||
cable_list_state.append(True)
|
cable_list_state.append(True)
|
||||||
@ -556,7 +567,7 @@ def mainloop_server(pool):
|
|||||||
|
|
||||||
fprint("All cables added to database.")
|
fprint("All cables added to database.")
|
||||||
mode = "Idle"
|
mode = "Idle"
|
||||||
serverproc = Process(target=start_server_socket, args=(cable_list,), error_callback=handle_error)
|
serverproc = Process(target=start_server_socket, args=(cable_list,))
|
||||||
serverproc.start()
|
serverproc.start()
|
||||||
else:
|
else:
|
||||||
# TODO: manual input
|
# TODO: manual input
|
||||||
@ -566,8 +577,10 @@ def mainloop_server(pool):
|
|||||||
if mode == "Idle":
|
if mode == "Idle":
|
||||||
# do nothing
|
# do nothing
|
||||||
if arm_ready is False:
|
if arm_ready is False:
|
||||||
|
if real:
|
||||||
pool.apply_async(ur5_control.move_to_home, (arm,), callback=arm_start_callback, error_callback=handle_error)
|
pool.apply_async(ur5_control.move_to_home, (arm,), callback=arm_start_callback, error_callback=handle_error)
|
||||||
#arm_ready = True
|
else:
|
||||||
|
arm_ready = True
|
||||||
|
|
||||||
else:
|
else:
|
||||||
global mainloop_get
|
global mainloop_get
|
||||||
@ -585,14 +598,22 @@ def mainloop_server(pool):
|
|||||||
spot = get_open_spot(sensors)
|
spot = get_open_spot(sensors)
|
||||||
if spot is not False:
|
if spot is not False:
|
||||||
arm_ready = False
|
arm_ready = False
|
||||||
|
if real:
|
||||||
pool.apply_async(ur5_control.holder_to_tray, (arm, get_cable, spot), callback=arm_start_callback, error_callback=handle_error)
|
pool.apply_async(ur5_control.holder_to_tray, (arm, get_cable, spot), callback=arm_start_callback, error_callback=handle_error)
|
||||||
|
else:
|
||||||
|
arm_ready = True
|
||||||
|
fprint("Getting cable at position " + str(get_cable))
|
||||||
mode = "Pickup"
|
mode = "Pickup"
|
||||||
cable_list_state[get_cable] = False # mark as removed
|
cable_list_state[get_cable] = False # mark as removed
|
||||||
get_sensors(sensors,flag=get_open_spot(sensors))
|
get_sensors()
|
||||||
|
|
||||||
if action == "return":
|
if action == "return":
|
||||||
arm_ready = False
|
arm_ready = False
|
||||||
|
fprint("Returning cable from tray position " + str(get_cable))
|
||||||
|
if real:
|
||||||
pool.apply_async(ur5_control.tray_to_camera, (arm, get_cable), callback=arm_start_callback, error_callback=handle_error)
|
pool.apply_async(ur5_control.tray_to_camera, (arm, get_cable), callback=arm_start_callback, error_callback=handle_error)
|
||||||
|
else:
|
||||||
|
arm_ready = True
|
||||||
mode = "ReturnC"
|
mode = "ReturnC"
|
||||||
else:
|
else:
|
||||||
# LED idle anim
|
# LED idle anim
|
||||||
@ -615,7 +636,11 @@ def mainloop_server(pool):
|
|||||||
mode = "Scan"
|
mode = "Scan"
|
||||||
arm_ready = False
|
arm_ready = False
|
||||||
camera_ready = False
|
camera_ready = False
|
||||||
|
if real:
|
||||||
pool.apply_async(camera.read_qr, (10,), callback=camera_start_callback, error_callback=handle_error)
|
pool.apply_async(camera.read_qr, (10,), callback=camera_start_callback, error_callback=handle_error)
|
||||||
|
else:
|
||||||
|
camera_ready = True
|
||||||
|
scan_value = "10GXS13"
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# getting cable from and bringing to camera
|
# getting cable from and bringing to camera
|
||||||
@ -640,7 +665,10 @@ def mainloop_server(pool):
|
|||||||
if cable == scan_value and cable_list_state[idx] == False:
|
if cable == scan_value and cable_list_state[idx] == False:
|
||||||
cable_list_state[idx] = True # mark cable as returned
|
cable_list_state[idx] = True # mark cable as returned
|
||||||
arm_ready = False
|
arm_ready = False
|
||||||
|
if real:
|
||||||
pool.apply_async(ur5_control.camera_to_holder, (arm, idx), callback=arm_start_callback, error_callback=handle_error)
|
pool.apply_async(ur5_control.camera_to_holder, (arm, idx), callback=arm_start_callback, error_callback=handle_error)
|
||||||
|
else:
|
||||||
|
arm_ready = True
|
||||||
mode = "Return"
|
mode = "Return"
|
||||||
break
|
break
|
||||||
|
|
||||||
|
@ -59,9 +59,11 @@ def powerup_arm(robot):
|
|||||||
|
|
||||||
#
|
#
|
||||||
# wait for power up (this function runs async)
|
# wait for power up (this function runs async)
|
||||||
|
count = 0
|
||||||
while not ping(robot.ip):
|
while not ping(robot.ip) and count == 10:
|
||||||
time.sleep(0.5)
|
time.sleep(0.5)
|
||||||
|
count += 1
|
||||||
|
|
||||||
# trigger auto-initialize
|
# trigger auto-initialize
|
||||||
fprint("Arm online. Waiting for calibration.")
|
fprint("Arm online. Waiting for calibration.")
|
||||||
# wait for auto-initialize
|
# wait for auto-initialize
|
||||||
@ -72,16 +74,19 @@ def connect(robot):
|
|||||||
ip = robot.ip
|
ip = robot.ip
|
||||||
fprint("Connecting to arm at " + ip)
|
fprint("Connecting to arm at " + ip)
|
||||||
trying = True
|
trying = True
|
||||||
while trying:
|
count = 0
|
||||||
|
while trying and count < 10:
|
||||||
|
count += 1
|
||||||
try:
|
try:
|
||||||
robot.robot = urx.Robot(ip)
|
robot.robot = urx.Robot(ip)
|
||||||
trying = False
|
|
||||||
except:
|
|
||||||
time.sleep(1)
|
|
||||||
# Sets robot arm endpoint offset (x,y,z,rx,ry,rz)
|
|
||||||
robot.robot.set_tcp((robot.offset_x, robot.offset_y, robot.offset_z, 0, 0, 0))
|
robot.robot.set_tcp((robot.offset_x, robot.offset_y, robot.offset_z, 0, 0, 0))
|
||||||
# Set weight
|
# Set weight
|
||||||
robot.robot.set_payload(2, (0, 0, 0.1))
|
robot.robot.set_payload(2, (0, 0, 0.1))
|
||||||
|
trying = False
|
||||||
|
except:
|
||||||
|
time.sleep(0.5)
|
||||||
|
# Sets robot arm endpoint offset (x,y,z,rx,ry,rz)
|
||||||
|
|
||||||
return robot
|
return robot
|
||||||
|
|
||||||
def init_arm(robot):
|
def init_arm(robot):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user