-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTool.py
87 lines (75 loc) · 3 KB
/
Tool.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
from time import sleep
from Devices import conveyor, camera, load_cell, send_data, tof_sensor
import requests
print("<---------------------Welcome To Grow-Simplee Tool------------------------->\n\n")
while True:
print("Stopping Conveyer Belt ...")
conveyor.stop()
print("--------------------------------------------------------------------------\n")
print("Please start inserting Similar Items into the tool\n")
input("Press Enter to continue...")
print("Starting Conveyer Belt ...")
conveyor.start()
items_info = []
while True:
print(
"--------------------------------------------------------------------------\n")
print("Waiting for Item ...")
while not conveyor.in_config():
pass
print("Item Detected ...")
max_height = float('-inf')
image = None
while (max_height <= 0) or not conveyor.out_config():
print(conveyor.centre_config())
if conveyor.centre_config() and image is None:
print(conveyor.centre_config())
print("Stopping Conveyer Belt For Image ...")
conveyor.stop()
image = camera.capture_image(brightness=50, contrast=90)
print("Starting Conveyer Belt after Image ...")
conveyor.start()
max_height = max(max_height, tof_sensor.get_height())
if not image:
print("Error in Image. Please Check the Object or insert again ...")
continue
# if max_height <= 0:
# print("Error in Height. Please Check the Object ...")
# print("Starting Conveyer Belt ...")
# conveyor.start()
# continue
try:
length, width = camera.get_length_width(image, max_height)
assert length > 0 and width > 0
except Exception as e:
print(e)
print("Error in dimensions. Please Check the Object ...")
print("Starting Conveyer Belt ...")
conveyor.start()
continue
# Just because we do not have a Bar Code Scanner
item_id = input("Please Enter Item ID: ")
item_info = {
"item_id": item_id,
"length": length,
"breadth": width,
"height": max_height,
"weight": load_cell.get_weight(),
}
items_info.append(item_info)
print(item_info)
print("Item Removed ...")
yes_no = input("1. Continue similar objects (y / n). \n ")
if yes_no == 'n':
if len(items_info) <= 2:
print("Please insert at least 3 items ...")
continue
print("Sending Data to Server ...")
response = requests.post(
"http://192.168.205.139:8000/add-item-details", json=items_info)
rejected_items = response.json()
print("Sent info to Server...")
print("Rejected Items: ", rejected_items)
break
sleep(0.05)
sleep(0.05)