Update MQTT commands, arm height
This commit is contained in:
parent
b677556ece
commit
534cc23c8d
@ -1 +0,0 @@
|
|||||||
<EFBFBD>K7.
|
|
1
pick_count.txt
Normal file
1
pick_count.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
55
|
37
run.py
37
run.py
@ -32,6 +32,7 @@ from uptime import uptime
|
|||||||
import fileserver
|
import fileserver
|
||||||
import paho.mqtt.client as mqtt
|
import paho.mqtt.client as mqtt
|
||||||
import pickle
|
import pickle
|
||||||
|
import time
|
||||||
|
|
||||||
# set to false to run without real hardware for development
|
# set to false to run without real hardware for development
|
||||||
real = False
|
real = False
|
||||||
@ -79,7 +80,8 @@ timecount = 0
|
|||||||
secondsclock = 0
|
secondsclock = 0
|
||||||
unacked_publish = set()
|
unacked_publish = set()
|
||||||
mqttc = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2)
|
mqttc = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2)
|
||||||
counter_file = 'pick_count.pkl'
|
counter_file = 'pick_count.txt'
|
||||||
|
cycle_start_time = time.time()
|
||||||
|
|
||||||
|
|
||||||
mqttc.user_data_set(unacked_publish)
|
mqttc.user_data_set(unacked_publish)
|
||||||
@ -134,22 +136,32 @@ def initialize_counter():
|
|||||||
global counter
|
global counter
|
||||||
try:
|
try:
|
||||||
with open(counter_file, 'rb') as file:
|
with open(counter_file, 'rb') as file:
|
||||||
counter = pickle.load(file)
|
counter = int(file.readline().decode())
|
||||||
|
fprint("Read count at " + str(counter))
|
||||||
if not isinstance(counter, int):
|
if not isinstance(counter, int):
|
||||||
raise ValueError("Counter is not an integer")
|
raise ValueError("Counter is not an integer")
|
||||||
except (FileNotFoundError, ValueError, pickle.PickleError):
|
|
||||||
|
except (FileNotFoundError, ValueError) as e:
|
||||||
counter = 101
|
counter = 101
|
||||||
|
fprint("Error. Resetting count." + str(e))
|
||||||
|
fprint(counter)
|
||||||
save_counter()
|
save_counter()
|
||||||
|
|
||||||
|
fprint(counter)
|
||||||
|
|
||||||
# Save the counter to the file
|
# Save the counter to the file
|
||||||
def save_counter():
|
def save_counter():
|
||||||
|
global counter
|
||||||
|
fprint(counter)
|
||||||
with open(counter_file, 'wb') as file:
|
with open(counter_file, 'wb') as file:
|
||||||
pickle.dump(counter, file)
|
file.write(str(counter).encode())
|
||||||
|
|
||||||
# Increment the counter
|
# Increment the counter
|
||||||
def increment_counter():
|
def increment_counter():
|
||||||
global counter
|
global counter
|
||||||
counter += 1
|
fprint(counter)
|
||||||
|
fprint("Setting count to " + str(counter + 1))
|
||||||
|
counter = counter + 1
|
||||||
save_counter()
|
save_counter()
|
||||||
|
|
||||||
def check_server():
|
def check_server():
|
||||||
@ -499,7 +511,7 @@ def setup_server(pool, manager):
|
|||||||
mqttc.connect(config["mqtt"]["server"])
|
mqttc.connect(config["mqtt"]["server"])
|
||||||
mqttc.loop_start()
|
mqttc.loop_start()
|
||||||
|
|
||||||
initialize_counter()
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -623,6 +635,8 @@ def mainloop_server(pool, manager):
|
|||||||
global failcount
|
global failcount
|
||||||
global timecount
|
global timecount
|
||||||
global secondsclock
|
global secondsclock
|
||||||
|
global cycle_start_time
|
||||||
|
|
||||||
|
|
||||||
if mode != oldmode:
|
if mode != oldmode:
|
||||||
print(" ***** Running mode:", mode, "***** ")
|
print(" ***** Running mode:", mode, "***** ")
|
||||||
@ -630,6 +644,7 @@ def mainloop_server(pool, manager):
|
|||||||
mqtt_send(mode, "mode")
|
mqtt_send(mode, "mode")
|
||||||
if mode == "Startup": # very first loop
|
if mode == "Startup": # very first loop
|
||||||
pass
|
pass
|
||||||
|
initialize_counter()
|
||||||
|
|
||||||
if killme.value > 0:
|
if killme.value > 0:
|
||||||
killall()
|
killall()
|
||||||
@ -752,7 +767,7 @@ def mainloop_server(pool, manager):
|
|||||||
global scan_value
|
global scan_value
|
||||||
if scan_value is False:
|
if scan_value is False:
|
||||||
cable_list.append(scan_value)
|
cable_list.append(scan_value)
|
||||||
elif scan_value.find("bldn.app/") > -1:
|
elif scan_value.upper.find("BLDN.APP/") > -1:
|
||||||
scan_value = scan_value[scan_value.find("bldn.app/")+9:]
|
scan_value = scan_value[scan_value.find("bldn.app/")+9:]
|
||||||
else:
|
else:
|
||||||
cable_list.append(scan_value)
|
cable_list.append(scan_value)
|
||||||
@ -889,9 +904,10 @@ def mainloop_server(pool, manager):
|
|||||||
killme.set(1)
|
killme.set(1)
|
||||||
else:
|
else:
|
||||||
fprint("Movement requested. Keep clear of the machine!")
|
fprint("Movement requested. Keep clear of the machine!")
|
||||||
mqtt_send("start", "cycle_start")
|
#mqtt_send("{\"value\": " + str(time.time() * 1000) + " }", "cycle_start")
|
||||||
|
cycle_start_time = int(time.time() * 1000)
|
||||||
increment_counter()
|
increment_counter()
|
||||||
mqtt_send(counter, "pick_count_total")
|
mqtt_send("{\"value\": " + str(counter) + " }", "pick_count_total")
|
||||||
if get_cable > -1:
|
if get_cable > -1:
|
||||||
global sensors
|
global sensors
|
||||||
if action == "pickup":
|
if action == "pickup":
|
||||||
@ -928,7 +944,8 @@ def mainloop_server(pool, manager):
|
|||||||
# complete
|
# complete
|
||||||
if arm_ready == True:
|
if arm_ready == True:
|
||||||
mode = "Idle"
|
mode = "Idle"
|
||||||
mqtt_send("start", "cycle_end")
|
sleep(9)
|
||||||
|
mqtt_send("{\"value\": " + str(int(time.time() * 1000) - cycle_start_time) + " }", "cycle_time")
|
||||||
else:
|
else:
|
||||||
# getting cable and bringing to tray
|
# getting cable and bringing to tray
|
||||||
# led animation
|
# led animation
|
||||||
|
@ -261,7 +261,7 @@ def move_to_home(robot, keep_flip=False, speed=2):
|
|||||||
flip(robot)
|
flip(robot)
|
||||||
|
|
||||||
# Move robot to home position
|
# Move robot to home position
|
||||||
rob.movej(offset_gripper_angle(robot, *(-0.18, -0.108, 0.35), flip=is_flipped(robot)), vel=2, acc=2) # Move to safe position
|
rob.movej(offset_gripper_angle(robot, *(-0.18, -0.108, 0.25), flip=is_flipped(robot)), vel=2, acc=2) # Move to safe position
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user