This repository has been archived by the owner on Sep 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathprintcontrol.py
executable file
·89 lines (74 loc) · 2.46 KB
/
printcontrol.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env python
from sys import argv
from octoclient import OctoClient
from api_keys import URL, API_KEY
import os
from os.path import dirname
# Pause the printer
def pause_print():
try:
client = OctoClient(url=URL, apikey=API_KEY)
flags = client.printer()['state']['flags']
if flags['printing']:
client.pause()
print("Print paused.")
print("Layer: " + str(LAYER))
elif flags['paused'] or flags['pausing']:
print("Print already paused.")
else:
print("Print cancelled or error occurred.")
except Exception as e:
print(e)
print(argv)
if len(argv) < 2:
exit()
if argv[2] == 'nan': # Exit if SCORE is NaN, this occurs on the background and first layer
img_file = str(argv[3])
logfile = dirname(img_file) + '/output.log'
os.system("sed -i '/g$/d' {}".format(logfile))
exit()
# Get SCORE, DEVIANCE and current layer from get_score.py
LAYER = int(argv[1])
# Do nothing if it is the background or first layer
if LAYER <= 7:
img_file = str(argv[6])
logfile = dirname(img_file) + '/output.log'
os.system("sed -i '/g$/d' {}".format(logfile))
quit()
SCORE = float(argv[2])
DEVIANCE = float(argv[3])
SCR_DIFF = float(argv[4])
DEV_DIFF = float(argv[5])
img_file = str(argv[6])
# Detachment thresholds
SCR_THRES = 1.0
DEV_THRES = 1.0
# Partial Breakage thresholds for DIFF values
BR_SCR_THRES = 0.2
BR_DEV_THRES = 0.2
# Filament run out/clog thresholds
FIL_SCR_THRES = 0.2
FIL_DEV_THRES = 0.2
# This indicates the model has detached from the bed
if SCORE > SCR_THRES and DEVIANCE > DEV_THRES:
print("Cause: Print detached from bed")
pause_print()
# This indicates a part of the model has broken off
elif SCR_DIFF > BR_SCR_THRES and DEV_DIFF > BR_DEV_THRES:
print("Cause: Potential (partial) breakage")
pause_print()
elif SCORE < FIL_SCR_THRES and DEVIANCE < FIL_DEV_THRES:
print("Cause: Filament ran out or nozzle/extruder clog")
pause_print()
else:
import cv2
from ml_api.lib.detection_model import load_net, detect
net_main, meta_main = load_net("./ml_api/model/model.cfg", "./ml_api/model/model.weights", "./ml_api/model/model.meta")
img = cv2.imread(img_file)
detection = detect(net_main, meta_main, img, thresh=0.3)
print(len(detection))
if len(detection) > 0:
print("Cause: Spaghetti")
pause_print()
logfile = dirname(img_file) + '/output.log'
os.system("sed -i '/g$/d' {}".format(logfile))