Add cables to meilisearch db
This commit is contained in:
170
run.py
170
run.py
@@ -1,5 +1,6 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from alive_progress import alive_bar
|
||||
import get_specs
|
||||
import traceback
|
||||
#import logging
|
||||
@@ -23,6 +24,8 @@ import server
|
||||
import asyncio
|
||||
import json
|
||||
import process_video
|
||||
import search
|
||||
from search import JukeboxSearch
|
||||
|
||||
|
||||
|
||||
@@ -33,6 +36,7 @@ led_ready = False
|
||||
camera_ready = False
|
||||
sensor_ready = False
|
||||
vm_ready = False
|
||||
cable_search_ready = False
|
||||
killme = None
|
||||
#pool = None
|
||||
serverproc = None
|
||||
@@ -41,6 +45,13 @@ ledsys = None
|
||||
arm = None
|
||||
to_server_queue = Queue()
|
||||
from_server_queue = Queue()
|
||||
mode = "Startup"
|
||||
counter = 0
|
||||
jbs = None
|
||||
scan_value = None
|
||||
arm_state = None
|
||||
cable_list = list()
|
||||
parse_res = None
|
||||
|
||||
def arm_start_callback(res):
|
||||
global arm_ready
|
||||
@@ -55,6 +66,8 @@ def led_start_callback(res):
|
||||
def camera_start_callback(res):
|
||||
global camera_ready
|
||||
camera_ready = True
|
||||
global scan_value
|
||||
scan_value = res
|
||||
|
||||
def sensor_start_callback(res):
|
||||
global sensor_ready
|
||||
@@ -64,6 +77,12 @@ def vm_start_callback(res):
|
||||
global vm_ready
|
||||
vm_ready = True
|
||||
|
||||
def cable_search_callback(res):
|
||||
global cable_search_ready
|
||||
cable_search_ready = True
|
||||
global parse_res
|
||||
parse_res = res
|
||||
|
||||
def wait_for(val, name):
|
||||
#global val
|
||||
if val is False:
|
||||
@@ -236,6 +255,7 @@ def setup_server(pool):
|
||||
global serverproc
|
||||
global camera
|
||||
global arm
|
||||
global jbs
|
||||
arm = Rob(config)
|
||||
pool.apply_async(arm.init_arm, callback=arm_start_callback)
|
||||
global ledsys
|
||||
@@ -245,6 +265,7 @@ def setup_server(pool):
|
||||
serverproc = Process(target=start_server_socket)
|
||||
serverproc.start()
|
||||
|
||||
|
||||
if led_ready is False:
|
||||
fprint("waiting for " + "LED controller initialization" + " to complete...", sendqueue=to_server_queue)
|
||||
while led_ready is False:
|
||||
@@ -260,7 +281,7 @@ def setup_server(pool):
|
||||
|
||||
if camera_ready is False:
|
||||
fprint("waiting for " + "Camera initilization" + " to complete...", sendqueue=to_server_queue)
|
||||
# camera = process_video.qr_reader(config["cameras"]["banner"]["ip"], config["cameras"]["banner"]["port"])
|
||||
camera = process_video.qr_reader(config["cameras"]["banner"]["ip"], config["cameras"]["banner"]["port"])
|
||||
|
||||
fprint("Camera initialized.", sendqueue=to_server_queue)
|
||||
|
||||
@@ -270,25 +291,158 @@ def setup_server(pool):
|
||||
while arm_ready is False:
|
||||
sleep(0.1)
|
||||
fprint("Arm initialized.", sendqueue=to_server_queue)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
jbs = JukeboxSearch()
|
||||
return True
|
||||
|
||||
|
||||
|
||||
def mainloop_server(pool):
|
||||
# NON-blocking loop
|
||||
global config
|
||||
global counter
|
||||
global killme
|
||||
global mode
|
||||
global jbs
|
||||
global arm
|
||||
global ledsys
|
||||
global camera
|
||||
global arm_ready
|
||||
global arm_state
|
||||
global camera_ready
|
||||
global cable_search_ready
|
||||
global cable_list
|
||||
|
||||
if killme.value > 0:
|
||||
killall()
|
||||
counter = counter + 1
|
||||
|
||||
# fprint("Looking for QR code...")
|
||||
# print(camera.read_qr(30))
|
||||
if mode == "Startup":
|
||||
counter = 54
|
||||
if counter < 54:
|
||||
# scanning cables
|
||||
|
||||
if arm_state is None:
|
||||
#pool.apply_async(arm.get cable to camera, callback=arm_start_callback)
|
||||
#ur5_control.goto_holder_index(arm)
|
||||
#ur5 get item
|
||||
# ur5 bring to camera
|
||||
fprint("Getting cable index " + str(counter) + " and scanning...")
|
||||
arm_state = "GET"
|
||||
|
||||
elif arm_ready and arm_state == "GET":
|
||||
fprint("Looking for QR code...")
|
||||
pool.apply_async(camera.read_qr, (30,), callback=camera_start_callback)
|
||||
arm_ready = False
|
||||
|
||||
elif camera_ready:
|
||||
fprint("Adding cable to list...")
|
||||
global scan_value
|
||||
if scan_value.find("bldn.app/") > -1:
|
||||
scan_value = scan_value[scan_value.find("bldn.app/")+9:]
|
||||
cable_list.append((counter, scan_value))
|
||||
fprint(scan_value)
|
||||
#pool.apply_async(arm.return cable, callback=arm_start_callback)
|
||||
arm_state = "RETURN"
|
||||
camera_ready = False
|
||||
|
||||
elif arm_ready and arm_state == "RETURN":
|
||||
counter += 1
|
||||
arm_state = None
|
||||
else:
|
||||
# just wait til arm/camera is ready
|
||||
pass
|
||||
else:
|
||||
# scanned everything
|
||||
tmp = list()
|
||||
for cable in cable_list:
|
||||
tmp.append(cable[1])
|
||||
|
||||
tmp = [
|
||||
# Actual cables in Jukebox
|
||||
|
||||
"AW86104CY",
|
||||
"AW3050",
|
||||
"AW6714",
|
||||
"AW1172C",
|
||||
"AWFIT-221-1_4",
|
||||
|
||||
"BLTF-1LF-006-RS5",
|
||||
"BLTF-SD9-006-RI5",
|
||||
"BLTT-SLG-024-HTN",
|
||||
"BLFISX012W0",
|
||||
"BLFI4X012W0",
|
||||
"BLSPE101",
|
||||
"BLSPE102",
|
||||
"BL7922A",
|
||||
"BL7958A",
|
||||
"BLIOP6U",
|
||||
"BL10GXW13",
|
||||
"BL10GXW53",
|
||||
"BL29501F",
|
||||
"BL29512",
|
||||
"BL3106A",
|
||||
"BL9841",
|
||||
"BL3105A",
|
||||
"BL3092A",
|
||||
"BL8760",
|
||||
"BL6300UE",
|
||||
"BL6300FE",
|
||||
"BLRA500P"
|
||||
]
|
||||
cable_list = tmp
|
||||
pool.apply_async(get_specs.get_multi, (tmp, 0.5), callback=cable_search_callback)
|
||||
mode = "Parsing"
|
||||
fprint("All cables scanned. Finding & parsing datasheets...")
|
||||
if mode == "Parsing":
|
||||
# waiting for search & parse to complete
|
||||
#cable_search_ready = True
|
||||
if cable_search_ready is False:
|
||||
pass
|
||||
else:
|
||||
# done
|
||||
global parse_res
|
||||
success, partnums = parse_res
|
||||
#partnums = list()
|
||||
# debug
|
||||
#success = True
|
||||
|
||||
#cable_list = list(range(len(partnums)))
|
||||
if success:
|
||||
# easy mode
|
||||
fprint("All cables inventoried and parsed.")
|
||||
for x in range(len(cable_list)):
|
||||
#cable_list[x] = (cable_list[x][0], partnums[x])
|
||||
cable_list[x] = (x, cable_list[x])
|
||||
fprint("Adding to database...")
|
||||
for idx,partnum in cable_list:
|
||||
with open("cables/" + partnum[2:] + "/search.json", "rb") as f:
|
||||
searchdata = json.load(f)
|
||||
searchdata["position"] = idx
|
||||
with open("cables/" + partnum[2:] + "/specs.json", "rb") as f:
|
||||
specs = json.load(f)
|
||||
searchdata["fullspecs"] = specs
|
||||
jbs.add_document(searchdata)
|
||||
|
||||
fprint("All cables added to database.")
|
||||
mode = "Idle"
|
||||
else:
|
||||
# TODO: manual input
|
||||
pass
|
||||
|
||||
|
||||
if mode == "Idle":
|
||||
# do nothing
|
||||
if arm_ready is False:
|
||||
pool.apply_async(ur5_control.move_to_home, (arm,), callback=arm_start_callback)
|
||||
arm_ready = True
|
||||
|
||||
else:
|
||||
# LED idle anim
|
||||
pass
|
||||
|
||||
|
||||
|
||||
|
||||
def run_loading_app():
|
||||
|
||||
|
||||
Reference in New Issue
Block a user