update sensor system
This commit is contained in:
parent
b56d176c82
commit
38ee4f9b9a
24
run.py
24
run.py
@ -460,7 +460,6 @@ def handle_error(error):
|
|||||||
def get_sensors():
|
def get_sensors():
|
||||||
global mbconn
|
global mbconn
|
||||||
global sensors
|
global sensors
|
||||||
oldsens = sensors
|
|
||||||
#print("Reading sensors")
|
#print("Reading sensors")
|
||||||
mbconn.open()
|
mbconn.open()
|
||||||
"""
|
"""
|
||||||
@ -474,27 +473,28 @@ def get_sensors():
|
|||||||
port 8: 368
|
port 8: 368
|
||||||
|
|
||||||
"""
|
"""
|
||||||
out = list()
|
|
||||||
if real:
|
if real:
|
||||||
for reg in [352, 288, 304, 368]:
|
sens = [352, 288, 304, 368]
|
||||||
|
for idx in range(len(sens)):
|
||||||
|
reg = sens[idx]
|
||||||
val = mbconn.read_holding_registers(reg)
|
val = mbconn.read_holding_registers(reg)
|
||||||
if val is not None:
|
if val is not None:
|
||||||
val = val[0]
|
val = val[0]
|
||||||
if val == 1:
|
if val == 1 and sensors[idx] >= 0: # skip negative values
|
||||||
out.append(1)
|
sensors[idx] += 1
|
||||||
else:
|
else:
|
||||||
out.append(0)
|
sensors[idx] = 0
|
||||||
else:
|
else:
|
||||||
out = [0, 0, 0, 0]
|
out = [0, 0, 0, 0]
|
||||||
|
|
||||||
if len(out) != 4:
|
if len(out) != 4:
|
||||||
return -1
|
return -1
|
||||||
sensors = out
|
|
||||||
#fprint("Values: " + str(sensors))
|
#fprint("Values: " + str(sensors))
|
||||||
mbconn.close()
|
mbconn.close()
|
||||||
for x in range(len(oldsens)):
|
for x in range(len(sensors)):
|
||||||
if oldsens[x] == 0 and out[x] == 1:
|
if sensors[x] >= 180: # 3 sec
|
||||||
# cable newly detected on tray
|
# cable newly detected on tray
|
||||||
|
sensors[x] = -1
|
||||||
fprint("Precense detected: slot " + str(x))
|
fprint("Precense detected: slot " + str(x))
|
||||||
return x
|
return x
|
||||||
|
|
||||||
@ -771,10 +771,9 @@ def mainloop_server(pool, manager):
|
|||||||
global mainloop_get
|
global mainloop_get
|
||||||
#print("Checking sensors..")
|
#print("Checking sensors..")
|
||||||
newtube = get_sensors()
|
newtube = get_sensors()
|
||||||
if newtube >= 0 and newtube != just_placed:
|
if newtube >= 0:
|
||||||
# need to return a cable
|
# need to return a cable
|
||||||
mainloop_get.put(("return", newtube))
|
mainloop_get.put(("return", newtube))
|
||||||
just_placed = -1
|
|
||||||
|
|
||||||
if not mainloop_get.empty():
|
if not mainloop_get.empty():
|
||||||
fprint("Movement requested. Keep clear of the machine!")
|
fprint("Movement requested. Keep clear of the machine!")
|
||||||
@ -796,7 +795,7 @@ def mainloop_server(pool, manager):
|
|||||||
fprint("Getting cable at position " + str(get_cable))
|
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()
|
|
||||||
|
|
||||||
if action == "return":
|
if action == "return":
|
||||||
arm_ready = False
|
arm_ready = False
|
||||||
@ -904,6 +903,7 @@ def mainloop_server(pool, manager):
|
|||||||
else: # camera not ready
|
else: # camera not ready
|
||||||
timecount += 1
|
timecount += 1
|
||||||
if timecount > 180:
|
if timecount > 180:
|
||||||
|
print("Camera timeout reached.")
|
||||||
timecount = 0
|
timecount = 0
|
||||||
camera_ready = True
|
camera_ready = True
|
||||||
arm_ready = True
|
arm_ready = True
|
||||||
|
Loading…
x
Reference in New Issue
Block a user