Update runtime LED modes
This commit is contained in:
parent
c52fe167bf
commit
62bcb07956
@ -58,7 +58,7 @@ class DriveImg():
|
||||
except:
|
||||
self.onLine = False
|
||||
self.trans.close()
|
||||
return resposta
|
||||
return "Error", None
|
||||
ret = self.trans.recv(64)
|
||||
try:
|
||||
valida = str(ret[0:15].decode('UTF-8'))
|
||||
@ -68,13 +68,13 @@ class DriveImg():
|
||||
self.trans.close()
|
||||
#sleep(2)
|
||||
gravaLog(ip=self.ip,tipo="Falha",msg=f'Unable to find TC IMAGE bookmark')
|
||||
return "Error"
|
||||
return "Error", None
|
||||
except Exception as ex:
|
||||
self.onLine = False
|
||||
self.trans.close()
|
||||
#sleep(2)
|
||||
gravaLog(ip=self.ip,tipo="Falha",msg=f'Error - {str(ex)}')
|
||||
return "Error"
|
||||
return "Error", None
|
||||
if ret:
|
||||
frame = int.from_bytes(ret[24:27],"little")
|
||||
isJpeg = int.from_bytes(ret[32:33],"little")
|
||||
@ -117,7 +117,7 @@ class DriveImg():
|
||||
self.onLine = False
|
||||
self.trans.close()
|
||||
#sleep(2)
|
||||
return resposta
|
||||
return "Error", None
|
||||
|
||||
class DriveData():
|
||||
HEADERSIZE = 100
|
||||
|
26
config.yml
26
config.yml
@ -3,7 +3,7 @@ core:
|
||||
serverip: 172.26.178.114
|
||||
clientip: 172.26.176.1
|
||||
server: Hyper-Vd
|
||||
loopspeed: 60 # fps
|
||||
loopspeed: 40 # fps
|
||||
|
||||
arm:
|
||||
ip: 192.168.1.145
|
||||
@ -29,52 +29,52 @@ led:
|
||||
fps: 90
|
||||
timeout: 1
|
||||
controllers:
|
||||
- universe: 0
|
||||
ip: 192.168.1.200
|
||||
- universe: 1
|
||||
ip: 192.168.1.5
|
||||
ledstart: 0
|
||||
ledend: 143
|
||||
mode: rgb
|
||||
- universe: 1
|
||||
- universe: 2
|
||||
ip: 192.168.1.201
|
||||
ledstart: 144
|
||||
ledend: 287
|
||||
mode: rgb
|
||||
- universe: 2
|
||||
- universe: 3
|
||||
ip: 192.168.1.202
|
||||
ledstart: 288
|
||||
ledend: 431
|
||||
mode: rgb
|
||||
- universe: 3
|
||||
- universe: 4
|
||||
ip: 192.168.1.203
|
||||
ledstart: 432
|
||||
ledend: 575
|
||||
mode: rgb
|
||||
- universe: 4
|
||||
- universe: 5
|
||||
ip: 192.168.1.204
|
||||
ledstart: 576
|
||||
ledend: 719
|
||||
mode: rgb
|
||||
- universe: 5
|
||||
- universe: 6
|
||||
ip: 192.168.1.205
|
||||
ledstart: 720
|
||||
ledend: 863
|
||||
mode: rgb
|
||||
- universe: 6
|
||||
- universe: 7
|
||||
ip: 192.168.1.206
|
||||
ledstart: 864
|
||||
ledend: 1007
|
||||
mode: rgb
|
||||
- universe: 7
|
||||
- universe: 8
|
||||
ip: 192.168.1.207
|
||||
ledstart: 1008
|
||||
ledend: 1151
|
||||
mode: rgb
|
||||
- universe: 8
|
||||
- universe: 9
|
||||
ip: 192.168.1.208
|
||||
ledstart: 1152
|
||||
ledend: 1295
|
||||
mode: rgb
|
||||
- universe: 9
|
||||
- universe: 0
|
||||
ip: 192.168.1.209
|
||||
ledstart: 1296
|
||||
ledend: 1365
|
||||
@ -435,7 +435,7 @@ led:
|
||||
pos: [375, 300]
|
||||
|
||||
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:
|
||||
- index: 0
|
||||
pos: [-152.4, 263.965]
|
||||
|
@ -247,7 +247,7 @@ class LEDSystem():
|
||||
# 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
|
||||
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)):
|
||||
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
|
||||
|
||||
def runmodes(self, ring = -1, speed = 1):
|
||||
fprint("Mode: " + str(self.mode))
|
||||
#fprint("Mode: " + str(self.mode))
|
||||
if self.mode == "Startup":
|
||||
# loading animation. cable check
|
||||
if self.firstrun:
|
||||
@ -330,7 +330,7 @@ class LEDSystem():
|
||||
self.ringstatus[x] = [True, self.animation_time]
|
||||
|
||||
if self.changecount > 0:
|
||||
fprint(self.changecount)
|
||||
#fprint(self.changecount)
|
||||
self.changecount = self.fadeorder(0,len(self.leds), self.changecount, 0,50,100)
|
||||
else:
|
||||
self.setmode("Startup2")
|
||||
@ -373,7 +373,8 @@ class LEDSystem():
|
||||
self.firstrun = False
|
||||
self.changecount = self.animation_time # 100hz
|
||||
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:
|
||||
self.setring(0,100,0,ring)
|
||||
self.setmode("idle")
|
||||
@ -531,7 +532,7 @@ class LEDSystem():
|
||||
def mapimage(self, image, fps=90):
|
||||
while uptime() - self.start < 1/fps:
|
||||
time.sleep(0.00001)
|
||||
fprint(1 / (uptime() - self.start))
|
||||
#fprint(1 / (uptime() - self.start))
|
||||
self.start = uptime()
|
||||
minsize = min(image.shape[0:2])
|
||||
leds_normalized2 = [(x * minsize,
|
||||
@ -568,10 +569,13 @@ class LEDSystem():
|
||||
def mainloop(self, stmode, ring = -1, fps = 100, preview = False):
|
||||
while uptime() - self.start < 1/fps:
|
||||
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()
|
||||
if self.mode is not None:
|
||||
self.setmode(stmode)
|
||||
|
||||
#if self.
|
||||
self.runmodes(ring)
|
||||
if preview:
|
||||
self.drawdata()
|
||||
@ -614,7 +618,7 @@ class LEDSystem():
|
||||
for x in range(self.animation_time):
|
||||
self.mainloop(None, preview=show)
|
||||
self.clear_animations()
|
||||
stmode = "StartupCheck"
|
||||
stmode = "idle"
|
||||
self.mainloop(stmode, preview=show)
|
||||
self.clear_animations()
|
||||
return self
|
||||
@ -641,16 +645,18 @@ class LEDSystem():
|
||||
if __name__ == "__main__":
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
"""cap = cv2.VideoCapture('badapple.mp4')
|
||||
ledsys = LEDSystem()
|
||||
ledsys.init()
|
||||
cap = cv2.VideoCapture('output.mp4')
|
||||
while cap.isOpened():
|
||||
ret, frame = cap.read()
|
||||
if not ret:
|
||||
break
|
||||
mapimage(frame, fps=30)"""
|
||||
break
|
||||
ledsys.mapimage(frame, fps=90)
|
||||
|
||||
show = False
|
||||
ring = 1
|
||||
ledsys = LEDSystem()
|
||||
ledsys.init()
|
||||
|
||||
ledsys.startup_animation(show)
|
||||
for x in range(54):
|
||||
ledsys.ringstatus[x][0] = True
|
||||
|
BIN
map.png
BIN
map.png
Binary file not shown.
Before Width: | Height: | Size: 370 KiB After Width: | Height: | Size: 371 KiB |
@ -19,7 +19,7 @@ class qr_reader():
|
||||
print(str(x) + " ", end="", flush=True)
|
||||
imgtype, img = self.camera.read_img()
|
||||
|
||||
if True:
|
||||
if img is not None:
|
||||
#fprint(imgtype)
|
||||
image_array = np.frombuffer(img, np.uint8)
|
||||
img = cv2.imdecode(image_array, cv2.IMREAD_COLOR)
|
||||
|
39
run.py
39
run.py
@ -415,22 +415,34 @@ def mainloop_server(pool):
|
||||
global cable_list
|
||||
global mainloop_get
|
||||
global cable_list_state
|
||||
|
||||
global scan_value
|
||||
print(" ***** Running main system loop ***** ")
|
||||
if killme.value > 0:
|
||||
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":
|
||||
#counter = 54 # remove for demo
|
||||
if counter < 54:
|
||||
# scanning cables
|
||||
ring_animation = counter
|
||||
led_set_mode = "GrabA"
|
||||
if arm_state is None:
|
||||
#pool.apply_async(arm_start_callback, ("",))
|
||||
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...")
|
||||
arm_state = "GET"
|
||||
ring_animation = counter
|
||||
led_set_mode = "GrabA"
|
||||
#ur5_control.to_camera(arm, counter)
|
||||
#arm_ready = True
|
||||
|
||||
@ -440,6 +452,8 @@ def mainloop_server(pool):
|
||||
arm_ready = False
|
||||
|
||||
elif camera_ready:
|
||||
ring_animation = counter
|
||||
led_set_mode = "GrabC"
|
||||
fprint("Adding cable to list...")
|
||||
global scan_value
|
||||
if scan_value is False:
|
||||
@ -449,7 +463,7 @@ def mainloop_server(pool):
|
||||
else:
|
||||
cable_list.append(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)
|
||||
#arm_ready = True
|
||||
arm_state = "RETURN"
|
||||
@ -571,14 +585,14 @@ def mainloop_server(pool):
|
||||
spot = get_open_spot(sensors)
|
||||
if spot is not 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"
|
||||
cable_list_state[get_cable] = False # mark as removed
|
||||
get_sensors(sensors,flag=get_open_spot(sensors))
|
||||
|
||||
if action == "return":
|
||||
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"
|
||||
else:
|
||||
# LED idle anim
|
||||
@ -610,7 +624,6 @@ def mainloop_server(pool):
|
||||
|
||||
if mode == "Scan":
|
||||
if camera_ready == True:
|
||||
global scan_value
|
||||
if scan_value is False:
|
||||
# unable to scan ???? not good
|
||||
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:
|
||||
cable_list_state[idx] = True # mark cable as returned
|
||||
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"
|
||||
break
|
||||
|
||||
@ -644,12 +657,7 @@ def mainloop_server(pool):
|
||||
# led animation
|
||||
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):
|
||||
start = uptime()
|
||||
mainloop_server(pool)
|
||||
#sleep(0.01)
|
||||
# limit to certain "framerate"
|
||||
while start + 1.0/speed < uptime():
|
||||
pass
|
||||
|
Loading…
x
Reference in New Issue
Block a user