Update runtime LED modes

This commit is contained in:
Cole Deck 2024-04-29 12:33:54 -05:00
parent c52fe167bf
commit 62bcb07956
6 changed files with 60 additions and 45 deletions

View File

@ -58,7 +58,7 @@ class DriveImg():
except: except:
self.onLine = False self.onLine = False
self.trans.close() self.trans.close()
return resposta return "Error", None
ret = self.trans.recv(64) ret = self.trans.recv(64)
try: try:
valida = str(ret[0:15].decode('UTF-8')) valida = str(ret[0:15].decode('UTF-8'))
@ -68,13 +68,13 @@ class DriveImg():
self.trans.close() self.trans.close()
#sleep(2) #sleep(2)
gravaLog(ip=self.ip,tipo="Falha",msg=f'Unable to find TC IMAGE bookmark') gravaLog(ip=self.ip,tipo="Falha",msg=f'Unable to find TC IMAGE bookmark')
return "Error" return "Error", None
except Exception as ex: except Exception as ex:
self.onLine = False self.onLine = False
self.trans.close() self.trans.close()
#sleep(2) #sleep(2)
gravaLog(ip=self.ip,tipo="Falha",msg=f'Error - {str(ex)}') gravaLog(ip=self.ip,tipo="Falha",msg=f'Error - {str(ex)}')
return "Error" return "Error", None
if ret: if ret:
frame = int.from_bytes(ret[24:27],"little") frame = int.from_bytes(ret[24:27],"little")
isJpeg = int.from_bytes(ret[32:33],"little") isJpeg = int.from_bytes(ret[32:33],"little")
@ -117,7 +117,7 @@ class DriveImg():
self.onLine = False self.onLine = False
self.trans.close() self.trans.close()
#sleep(2) #sleep(2)
return resposta return "Error", None
class DriveData(): class DriveData():
HEADERSIZE = 100 HEADERSIZE = 100

View File

@ -3,7 +3,7 @@ core:
serverip: 172.26.178.114 serverip: 172.26.178.114
clientip: 172.26.176.1 clientip: 172.26.176.1
server: Hyper-Vd server: Hyper-Vd
loopspeed: 60 # fps loopspeed: 40 # fps
arm: arm:
ip: 192.168.1.145 ip: 192.168.1.145
@ -29,52 +29,52 @@ led:
fps: 90 fps: 90
timeout: 1 timeout: 1
controllers: controllers:
- universe: 0 - universe: 1
ip: 192.168.1.200 ip: 192.168.1.5
ledstart: 0 ledstart: 0
ledend: 143 ledend: 143
mode: rgb mode: rgb
- universe: 1 - universe: 2
ip: 192.168.1.201 ip: 192.168.1.201
ledstart: 144 ledstart: 144
ledend: 287 ledend: 287
mode: rgb mode: rgb
- universe: 2 - universe: 3
ip: 192.168.1.202 ip: 192.168.1.202
ledstart: 288 ledstart: 288
ledend: 431 ledend: 431
mode: rgb mode: rgb
- universe: 3 - universe: 4
ip: 192.168.1.203 ip: 192.168.1.203
ledstart: 432 ledstart: 432
ledend: 575 ledend: 575
mode: rgb mode: rgb
- universe: 4 - universe: 5
ip: 192.168.1.204 ip: 192.168.1.204
ledstart: 576 ledstart: 576
ledend: 719 ledend: 719
mode: rgb mode: rgb
- universe: 5 - universe: 6
ip: 192.168.1.205 ip: 192.168.1.205
ledstart: 720 ledstart: 720
ledend: 863 ledend: 863
mode: rgb mode: rgb
- universe: 6 - universe: 7
ip: 192.168.1.206 ip: 192.168.1.206
ledstart: 864 ledstart: 864
ledend: 1007 ledend: 1007
mode: rgb mode: rgb
- universe: 7 - universe: 8
ip: 192.168.1.207 ip: 192.168.1.207
ledstart: 1008 ledstart: 1008
ledend: 1151 ledend: 1151
mode: rgb mode: rgb
- universe: 8 - universe: 9
ip: 192.168.1.208 ip: 192.168.1.208
ledstart: 1152 ledstart: 1152
ledend: 1295 ledend: 1295
mode: rgb mode: rgb
- universe: 9 - universe: 0
ip: 192.168.1.209 ip: 192.168.1.209
ledstart: 1296 ledstart: 1296
ledend: 1365 ledend: 1365
@ -435,7 +435,7 @@ led:
pos: [375, 300] pos: [375, 300]
global_position_offset: [0,0] # default coordinate spce below as center of arm at 0,0 - adjust if necessary global_position_offset: [0,0] # default coordinate spce below as center of arm at 0,0 - adjust if necessary
animation_time: 40 animation_time: 200
position_map: position_map:
- index: 0 - index: 0
pos: [-152.4, 263.965] pos: [-152.4, 263.965]

View File

@ -247,7 +247,7 @@ class LEDSystem():
# send all LED data to all controllers # send all LED data to all controllers
# data must have all LED data in it as [(R,G,B,)] tuples in an array, 1 tuple per pixel # data must have all LED data in it as [(R,G,B,)] tuples in an array, 1 tuple per pixel
self.sender.manual_flush = False self.sender.manual_flush = False
print(datain[self.controllers[0][0]:self.controllers[0][1]]) #print(datain[self.controllers[0][0]:self.controllers[0][1]])
for x in range(len(self.controllers)): for x in range(len(self.controllers)):
self.sender[x+1].dmx_data = list(sum(datain[self.controllers[x][0]:self.controllers[x][1]] , ())) # flatten the subsection of the data array self.sender[x+1].dmx_data = list(sum(datain[self.controllers[x][0]:self.controllers[x][1]] , ())) # flatten the subsection of the data array
@ -320,7 +320,7 @@ class LEDSystem():
return self return self
def runmodes(self, ring = -1, speed = 1): def runmodes(self, ring = -1, speed = 1):
fprint("Mode: " + str(self.mode)) #fprint("Mode: " + str(self.mode))
if self.mode == "Startup": if self.mode == "Startup":
# loading animation. cable check # loading animation. cable check
if self.firstrun: if self.firstrun:
@ -330,7 +330,7 @@ class LEDSystem():
self.ringstatus[x] = [True, self.animation_time] self.ringstatus[x] = [True, self.animation_time]
if self.changecount > 0: if self.changecount > 0:
fprint(self.changecount) #fprint(self.changecount)
self.changecount = self.fadeorder(0,len(self.leds), self.changecount, 0,50,100) self.changecount = self.fadeorder(0,len(self.leds), self.changecount, 0,50,100)
else: else:
self.setmode("Startup2") self.setmode("Startup2")
@ -373,7 +373,8 @@ class LEDSystem():
self.firstrun = False self.firstrun = False
self.changecount = self.animation_time # 100hz self.changecount = self.animation_time # 100hz
if self.changecount > 0: if self.changecount > 0:
self.changecount = self.fadeorder(self.rings[ring][2],self.rings[ring][3], self.changecount, 0,100,0) #self.changecount = self.fadeorder(self.rings[ring][2],self.rings[ring][3], self.changecount, 0,100,0)
self.changecount = self.fadeorder(self.rings[ring][2],self.rings[ring][2]+24, self.changecount, 0,100,0)
else: else:
self.setring(0,100,0,ring) self.setring(0,100,0,ring)
self.setmode("idle") self.setmode("idle")
@ -531,7 +532,7 @@ class LEDSystem():
def mapimage(self, image, fps=90): def mapimage(self, image, fps=90):
while uptime() - self.start < 1/fps: while uptime() - self.start < 1/fps:
time.sleep(0.00001) time.sleep(0.00001)
fprint(1 / (uptime() - self.start)) #fprint(1 / (uptime() - self.start))
self.start = uptime() self.start = uptime()
minsize = min(image.shape[0:2]) minsize = min(image.shape[0:2])
leds_normalized2 = [(x * minsize, leds_normalized2 = [(x * minsize,
@ -568,10 +569,13 @@ class LEDSystem():
def mainloop(self, stmode, ring = -1, fps = 100, preview = False): def mainloop(self, stmode, ring = -1, fps = 100, preview = False):
while uptime() - self.start < 1/fps: while uptime() - self.start < 1/fps:
time.sleep(0.00001) time.sleep(0.00001)
fprint(1 / (uptime() - self.start)) #fprint("Running LED loop with ring " + str(ring) + " and set mode " + str(stmode))
#fprint(1 / (uptime() - self.start))
self.start = uptime() self.start = uptime()
if self.mode is not None: if self.mode is not None:
self.setmode(stmode) self.setmode(stmode)
#if self.
self.runmodes(ring) self.runmodes(ring)
if preview: if preview:
self.drawdata() self.drawdata()
@ -614,7 +618,7 @@ class LEDSystem():
for x in range(self.animation_time): for x in range(self.animation_time):
self.mainloop(None, preview=show) self.mainloop(None, preview=show)
self.clear_animations() self.clear_animations()
stmode = "StartupCheck" stmode = "idle"
self.mainloop(stmode, preview=show) self.mainloop(stmode, preview=show)
self.clear_animations() self.clear_animations()
return self return self
@ -641,16 +645,18 @@ class LEDSystem():
if __name__ == "__main__": if __name__ == "__main__":
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
"""cap = cv2.VideoCapture('badapple.mp4') ledsys = LEDSystem()
ledsys.init()
cap = cv2.VideoCapture('output.mp4')
while cap.isOpened(): while cap.isOpened():
ret, frame = cap.read() ret, frame = cap.read()
if not ret: if not ret:
break break
mapimage(frame, fps=30)""" ledsys.mapimage(frame, fps=90)
show = False show = False
ring = 1 ring = 1
ledsys = LEDSystem()
ledsys.init()
ledsys.startup_animation(show) ledsys.startup_animation(show)
for x in range(54): for x in range(54):
ledsys.ringstatus[x][0] = True ledsys.ringstatus[x][0] = True

BIN
map.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 370 KiB

After

Width:  |  Height:  |  Size: 371 KiB

View File

@ -19,7 +19,7 @@ class qr_reader():
print(str(x) + " ", end="", flush=True) print(str(x) + " ", end="", flush=True)
imgtype, img = self.camera.read_img() imgtype, img = self.camera.read_img()
if True: if img is not None:
#fprint(imgtype) #fprint(imgtype)
image_array = np.frombuffer(img, np.uint8) image_array = np.frombuffer(img, np.uint8)
img = cv2.imdecode(image_array, cv2.IMREAD_COLOR) img = cv2.imdecode(image_array, cv2.IMREAD_COLOR)

39
run.py
View File

@ -415,22 +415,34 @@ def mainloop_server(pool):
global cable_list global cable_list
global mainloop_get global mainloop_get
global cable_list_state global cable_list_state
global scan_value
print(" ***** Running main system loop ***** ")
if killme.value > 0: if killme.value > 0:
killall() killall()
if True:
# do every loop!
if ring_animation is not None and ledsys.mode != "idle":
ledsys.mainloop(None, ring_animation)
elif ring_animation is not None:
ledsys.mainloop(led_set_mode, ring_animation)
led_set_mode = None
else:
fprint("Not triggering LED loop: no ring animation")
if mode == "Startup": if mode == "Startup":
#counter = 54 # remove for demo #counter = 54 # remove for demo
if counter < 54: if counter < 54:
# scanning cables # scanning cables
ring_animation = counter
led_set_mode = "GrabA"
if arm_state is None: if arm_state is None:
#pool.apply_async(arm_start_callback, ("",)) #pool.apply_async(arm_start_callback, ("",))
arm_ready = False arm_ready = False
pool.apply_async(ur5_control.to_camera, (arm,counter), callback=arm_start_callback, error_callback=handle_error) pool.apply_async(ur5_control.holder_to_camera, (arm,counter), callback=arm_start_callback, error_callback=handle_error)
fprint("Getting cable index " + str(counter) + " and scanning...") fprint("Getting cable index " + str(counter) + " and scanning...")
arm_state = "GET" arm_state = "GET"
ring_animation = counter
led_set_mode = "GrabA"
#ur5_control.to_camera(arm, counter) #ur5_control.to_camera(arm, counter)
#arm_ready = True #arm_ready = True
@ -440,6 +452,8 @@ def mainloop_server(pool):
arm_ready = False arm_ready = False
elif camera_ready: elif camera_ready:
ring_animation = counter
led_set_mode = "GrabC"
fprint("Adding cable to list...") fprint("Adding cable to list...")
global scan_value global scan_value
if scan_value is False: if scan_value is False:
@ -449,7 +463,7 @@ def mainloop_server(pool):
else: else:
cable_list.append(scan_value) cable_list.append(scan_value)
fprint(scan_value) fprint(scan_value)
pool.apply_async(ur5_control.return_camera, (arm,counter), callback=arm_start_callback, error_callback=handle_error) pool.apply_async(ur5_control.camera_to_holder, (arm,counter), callback=arm_start_callback, error_callback=handle_error)
#ur5_control.return_camera(arm, counter) #ur5_control.return_camera(arm, counter)
#arm_ready = True #arm_ready = True
arm_state = "RETURN" arm_state = "RETURN"
@ -571,14 +585,14 @@ 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
pool.apply_async(ur5_control.pick_up_routine, (arm, get_cable, True, 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)
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(sensors,flag=get_open_spot(sensors))
if action == "return": if action == "return":
arm_ready = False arm_ready = False
pool.apply_async(ur5_control.return_routine, (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)
mode = "ReturnC" mode = "ReturnC"
else: else:
# LED idle anim # LED idle anim
@ -610,7 +624,6 @@ def mainloop_server(pool):
if mode == "Scan": if mode == "Scan":
if camera_ready == True: if camera_ready == True:
global scan_value
if scan_value is False: if scan_value is False:
# unable to scan ???? not good # unable to scan ???? not good
fprint("Unable to scan cable. Gonna retry.") fprint("Unable to scan cable. Gonna retry.")
@ -627,7 +640,7 @@ 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
pool.apply_async(ur5_control.return_camera, (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)
mode = "Return" mode = "Return"
break break
@ -644,12 +657,7 @@ def mainloop_server(pool):
# led animation # led animation
pass pass
if True:
# do every loop!
if ring_animation is not None and ledsys.mode != "idle":
ledsys.mainloop(None, ring_animation)
elif ring_animation is not None:
ledsys.mainloop(led_set_mode, ring_animation)
@ -803,6 +811,7 @@ if __name__ == "__main__":
while(keeprunning): while(keeprunning):
start = uptime() start = uptime()
mainloop_server(pool) mainloop_server(pool)
#sleep(0.01)
# limit to certain "framerate" # limit to certain "framerate"
while start + 1.0/speed < uptime(): while start + 1.0/speed < uptime():
pass pass