-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBIU_gui_helper_functions.py
133 lines (123 loc) · 5.37 KB
/
BIU_gui_helper_functions.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
from guizero import App, TextBox, Text, PushButton, CheckBox
from subprocess import call, Popen
from pathlib import Path
from datetime import datetime as dtm
from datetime import date as dt
def text_box(app, disp:str, position:list, default):
'''
Takes in app as guizero application object, and then return the following to the caller of this function:
label: a guizero Text object
box : a guizero TextBox object
'''
if len(position) == 2:
posbox = [position[0]+1, position[1]]
else:
print('Incorrect number of arguments to text_box.')
return
label = Text(app, grid = position, text = disp, align = 'left')
box = TextBox(app, grid=posbox, text=str(default), align='left')
box.text_size = 12
return label, box
# def pedal():
# GPIO.setup(pin.pedalsensor,GPIO.IN, pull_up_down = GPIO.PUD_UP)
# if button_start.enabled and GPIO.input(pin.pedalsensor)==0:
# print("Pedal triggered")
# startprocess()
def startprocess(stime, rdelay, pdelay, is_dry_fire:bool, sprayname, recfile) -> None:
'''
This function takes in spraytime, retraction delay, and plunge delay to run BIUA&P in the system command line.
:return: void
'''
print("Starting continous spray process.")
spraytime = str(float(stime.value)/1000)
retractiondelay = str(float(rdelay.value)/1000)
plungedelay = str(float(pdelay.value)/1000)
print('Starting A&P')
arguments = ["python3","BIUapplyandplunge.py","--stime",spraytime,"--rdelay",retractiondelay,"--pdelay",plungedelay]
#button_start.disable()
if is_dry_fire:
arguments.append("--donotplunge")
call(arguments)
print("A&P finished.")
# Writing spray record.
with open(Path(recfile.value),'a') as file:
timestamp = dtm.now().strftime("%Y-%m-%d %H:%M:%S")
lines = ['\n__________\n',timestamp+' | '+ sprayname.value,' | Continuous Mode\n',
'\tSpray Length: '+spraytime+' s\n',
'\tRetraction Delay: '+retractiondelay+' s\n',
'\tPlunge Delay: '+plungedelay+' s\n']
file.writelines(lines)
print('Spray Record Saved to {0}'.format(recfile.value))
def pulsestartprocess(rdelay, pdelay, pnum, plen, pinterval, is_dry_fire, sprayname, recfile) -> None:
'''
This function takes in retraction delay, plunge delay, and pulse length to run BIUA&P in the system command line.
:param rdelay: retraction delay
:param pdelay: plunge delay
:param plen: pulse length
:param is_dry_fire: boolean to determine whether to plunge or not
:return: void
'''
print("Starting pulse spray.")
retractiondelay = str(float(rdelay.value)/1000)
plungedelay = str(float(pdelay.value)/1000)
pulselength = str(float(plen.value)/1000)
breaktime = str(float(pinterval.value)/1000)
arguments = ["python3","BIUapplyandplunge.py","--pulse","--pcycles",pnum.value,"--stime",pulselength, "--breaktime", breaktime, "--rdelay",retractiondelay,"--pdelay",plungedelay]
#button_pulse.disable()
if (is_dry_fire):
arguments.append("--donotplunge")
call(arguments)
# write records to file
with open(Path(recfile.value),'a') as file:
timestamp = dtm.now().strftime("%Y-%m-%d %H:%M:%S")
lines = ['\n__________\n',timestamp+' | '+ sprayname.value,' | Pulse Mode\n',
'\tPulse Length: '+pulselength+' s\n',
'\tPulse Interval: '+breaktime+' s\n',
'\tPulses: '+pnum.value+'\n',
'\tRetraction Delay: '+retractiondelay+' s\n',
'\tPlunge Delay: '+plungedelay+' s\n']
file.writelines(lines)
print('Spray Record Saved to {0}'.format(recfile.value))
def powerup(tobe_enabled_buttons_list):
'''
This function runs BIUpowerupdown.py in the system command line and then takes in a list of buttons to be enabled.
:param tobe_enabled_buttons_list: list of guizero.PushButton objects to be enabled
:return: void
'''
print("Power up")
arguments = ["python3","BIUpowerupdown.py","--updown","up"]
call(arguments)
try:
for button in tobe_enabled_buttons_list:
button.enable()
except:
return
def powerdown(tobe_disabled_buttons_list):
'''
This function runs BIUpowerupdown.py in the system command line and then takes in a list of buttons to be disabled.
:param tobe_disabled_buttons_list: list of guizero.PushButton objects to be disabled
:return: void
'''
print("Power down")
arguments = ["python3","BIUpowerupdown.py","--updown","down"]
call(arguments)
try:
for button in tobe_disabled_buttons_list:
button.disable()
except:
return
def cleanprocess(cleantime, cleancycles):
'''
This function takes in clean time and clean cycles to run BIUclean.py in the system command line.
:param cleantime: spray time for cleaning in [ms]
:param cleancycles: number of cleaning cycles
:return: void
'''
print("Starting clean process")
spraytime = str(float(cleantime.value)/1000)
cycles = cleancycles.value
arguments = ["python3","BIUclean.py","--stime",spraytime,"--cycles",cycles]
#print(arguments)
#call(arguments)
Popen(arguments)
#call(["python3","cleancontrol.py","--stime",stime,"--cycles",cycles])