forked from MTS-AUV-ZHCET/ROVC2.0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgui1.py
266 lines (217 loc) · 10.1 KB
/
gui1.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
from tkinter import *
# from PIL import Image, ImageTk
import cv2
# import time
import pigpio
from PIL import Image as Img
from PIL import ImageTk
# Create an instance of TKinter Window or frame
app = Tk()
width = app.winfo_screenwidth()
height = app.winfo_screenheight()
# Set the size of the window
app.geometry("%dx%d" % (width, height))
#Create thvalue[0] Label to capture the Video frames
label =Label(app )
label.place(relwidth=1, relheight=0.45, rely=0.03)
label.place(x = 25 , y = 5 , height= 450 , width= 900)
label.grid(row=0, column=0, columnspan=5, padx = 20 , pady=40)
# cap= cv2.VideoCapture(0)
# #Define function to show frame
# def show_frames():
# # Get the latest frame and convert into Image
# cv2image= cv2.cvtColor(cap.read()[1],cv2.COLOR_BGR2RGB)
# img = Img.fromarray(cv2image)
# # Convert image to PhotoImage
# imgtk = ImageTk.PhotoImage(image = img)
# label.imgtk = imgtk
# label.configure(image=imgtk)
# # Repeat after an interval to capture continiously
# label.after(1, show_frames)
# show_frames()
thruster_one = 9 #Enter the PIN Number to Which Thrsuter 1 is coonected
thruster_two = 8 #Enter the PIN Number to Which Thrsuter 2 is coonected
thruster_three = 11 #Enter the PIN Number to Which Thrsuter 3 is coonected
thruster_four = 25 #Enter the PIN Number to Which Thrsuter 4 is coonected
thruster_pins = [thruster_one, thruster_two, thruster_three, thruster_four]
pi = pigpio.pi()
for item in thruster_pins:
pi.set_servo_pulsewidth(item,1500)
thvalue = [1500, 1500,1500,1500]
def forward(eve):
if thvalue[0] < 1850 and thvalue[1]<1850:
thvalue[0] = thvalue[0] + 10
thvalue[1] = thvalue[1] + 10
pi.set_servo_pulsewidth(thruster_one, thvalue[0])
pi.set_servo_pulsewidth(thruster_two, thvalue[1])
if thvalue[0] > 1500 and thvalue[1] > 1500:
result_str = "ROV IS IN MOTION \n" + "Thruster 1 is moving forward with " + \
str(abs(1500-thvalue[0])) + " unit speed \n" + \
"Thruster 2 is moving forward with " + \
str(abs(1500-thvalue[1])) + " unit speed"
elif thvalue[0] == 1500 and thvalue[1] == 1500:
result_str = "ROV IS AT REST"
else:
result_str = "ROV IS IN MOTION \n" + "Thruster 1 is moving backward with " + \
str(abs(1500-thvalue[0])) + " unit speed \n" + \
"Thruster 2 is moving backward with " + \
str(abs(1500-thvalue[1])) + " unit speed"
ele.delete("1.0","end")
ele.insert(INSERT, result_str)
if thvalue[2]<1500:
more_str = " \nROV IS moving Vertically Down with " + str(abs(1500 - thvalue[2])) + " unit speed"
ele.insert(INSERT, more_str)
if thvalue[2]>1500:
more_str = " \nROV IS moving Vertically UP with " + str(abs(1500 - thvalue[2])) + " unit speed"
ele.insert(INSERT, more_str)
def backward(eve):
if thvalue[0] > 1150 and thvalue[1] > 1150:
thvalue[0] = thvalue[0] - 10
thvalue[1] = thvalue[1] - 10
pi.set_servo_pulsewidth(thruster_one, thvalue[0])
pi.set_servo_pulsewidth(thruster_two, thvalue[1])
if thvalue[0] > 1500 and thvalue[1] > 1500:
result_str = "ROV IS IN MOTION \n" + "Thruster 1 is moving forward with " + \
str(abs(1500-thvalue[0])) + " unit speed \n" + \
"Thruster 2 is moving forward with " + \
str(abs(1500-thvalue[1])) + " unit speed"
elif thvalue[0] == 1500 and thvalue[1] == 1500:
result_str = "ROV IS AT REST"
else:
result_str = "ROV IS IN MOTION \n" + "Thruster 1 is moving backward with " + \
str(abs(1500-thvalue[0])) + " unit speed \n" + \
"Thruster 2 is moving backward with " + \
str(abs(1500-thvalue[1])) + " unit speed"
ele.delete("1.0","end")
ele.insert(INSERT, result_str)
if thvalue[2]<1500:
more_str = " \nROV IS moving Vertically Down with " + str(abs(1500 - thvalue[2])) + " unit speed"
ele.insert(INSERT, more_str)
if thvalue[2]>1500:
more_str = " \nROV IS moving Vertically UP with " + str(abs(1500 - thvalue[2])) + " unit speed"
ele.insert(INSERT, more_str)
def down(eve):
if thvalue[2] <= 1800 and thvalue[2]>1200:
thvalue[2] = thvalue[2] - 10
thvalue[3] = thvalue[3] - 10
pi.set_servo_pulsewidth(thruster_three, thvalue[2])
pi.set_servo_pulsewidth(thruster_four, thvalue[3])
if thvalue[2] > 1500:
result_str = "Rov is going up with " + str(abs(1500-thvalue[2])) + " unit speed"
elif thvalue[2] == 1500:
result_str = "Vertical Motion Of Rov has Stopped"
else:
result_str = "Rov is going down with " + str(abs(1500-thvalue[2])) + " unit speed"
ele.delete("1.0","end")
ele.insert(INSERT, result_str)
if thvalue[0]!=1500 or thvalue[1] != 1500:
more_str = "\n ROV Is also in Horizontal Forward Motion " + \
"You can Press Enter to Stop It "
ele.insert(INSERT, more_str)
def upward(eve):
if thvalue[2]>=1200 and thvalue[2]<1800:
thvalue[2] = thvalue[2] + 10
thvalue[3] = thvalue[3] + 10
pi.set_servo_pulsewidth(thruster_three, thvalue[2])
pi.set_servo_pulsewidth(thruster_four, thvalue[3])
if thvalue[2] > 1500:
result_str = "Rov is going up with " + str(abs(1500-thvalue[2])) + " unit speed"
elif thvalue[2] == 1500:
result_str = "Vertical Motion Of Rov has Stopped"
else:
result_str = "Rov is going down with " + str(abs(1500-thvalue[2])) + " unit speed"
ele.delete("1.0","end")
ele.insert(INSERT, result_str)
if thvalue[0]!=1500 or thvalue[1] != 1500:
more_str = "\n ROV Is also in Horizontal Forward Motion " + \
"You can Press Enter to Stop It "
ele.insert(INSERT, more_str)
def left(eve):
if thvalue[0] > 1500:
thvalue[0] = thvalue[0] - 50
thvalue[1] = thvalue[1] + 50
pi.set_servo_pulsewidth(thruster_one, thvalue[0])
pi.set_servo_pulsewidth(thruster_two, thvalue[1])
result_str = "Rov is turning left and speed of thruster 1 is " + str(abs(1500-thvalue[0])) + " unit and thruster 2 is " + str(abs(1500-thvalue[1])) + " unit"
elif thvalue[0] == 1500:
thvalue[1] = thvalue[1] + 10
pi.set_servo_pulsewidth(thruster_two, thvalue[1])
result_str = "Left Thruster is Stopped and Rov is turning left\n and speed of right thruster is " + \
str(abs(1500-thvalue[1])) + " unit"
else:
thvalue[0] = thvalue[0] + 10
thvalue[1] = thvalue[1] - 10
pi.set_servo_pulsewidth(thruster_one, thvalue[0])
pi.set_servo_pulsewidth(thruster_two, thvalue[1])
result_str = "Rov is turning right and speed of thruster 1 is " + str(abs(1500-thvalue[0])) + " unit and thruster 2 is " + str(abs(1500-thvalue[1])) + " unit"
ele.delete("1.0","end")
ele.insert(INSERT, result_str)
if thvalue[2]<1500:
more_str = " \nROV IS moving Vertically Down with " + str(abs(1500 - thvalue[2])) + " unit speed"
ele.insert(INSERT, more_str)
if thvalue[2]>1500:
more_str = " \nROV IS moving Vertically UP with " + str(abs(1500 - thvalue[2])) + " unit speed"
ele.insert(INSERT, more_str)
def right(eve):
if thvalue[1] > 1500:
thvalue[1] = thvalue[1] - 50
thvalue[0] = thvalue[0] + 50
pi.set_servo_pulsewidth(thruster_one, thvalue[0])
pi.set_servo_pulsewidth(thruster_two, thvalue[1])
result_str = "Rov is turning right and speed of thruster 1 is " + str(abs(1500-thvalue[0])) + " unit and thruster 2 is " + str(abs(1500-thvalue[1])) + " unit"
elif thvalue[1] == 1500:
thvalue[0] = thvalue[0] + 10
# pi.set_servo_pulsewidth(thruster_one, thvalue[0])
result_str = "right Thruster is Stopped and Rov is turning right\n and speed of left thruster is " + str(abs(1500-thvalue[0])) + " unit"
else:
thvalue[0] = thvalue[0] - 50
thvalue[1] = thvalue[1] + 50
pi.set_servo_pulsewidth(thruster_one, thvalue[0])
pi.set_servo_pulsewidth(thruster_two, thvalue[1])
result_str = "Rov is turning left and speed of thruster 1 is " + str(abs(1500-thvalue[0])) + " unit and thruster 2 is " + str(abs(1500-thvalue[1])) + " unit"
ele.delete("1.0","end")
ele.insert(INSERT, result_str)
if thvalue[2]<1500:
more_str = " \nROV IS moving Vertically Down with " + str(abs(1500 - thvalue[2])) + " unit speed"
ele.insert(INSERT, more_str)
if thvalue[2]>1500:
more_str = " \nROV IS moving Vertically UP with " + str(abs(1500 - thvalue[2])) + " unit speed"
ele.insert(INSERT, more_str)
def reset(eve):
thvalue[0] = 1500
thvalue[1] = 1500
thvalue[2] = 1500
thvalue[3] = 1500
pi.set_servo_pulsewidth(thruster_one, thvalue[0])
pi.set_servo_pulsewidth(thruster_two, thvalue[1])
pi.set_servo_pulsewidth(thruster_three, thvalue[2])
pi.set_servo_pulsewidth(thruster_four, thvalue[3])
result_str = "ROV IS AT REST"
ele.delete("1.0","end")
ele.insert(INSERT, result_str)
result = "Rov is not in Motion \nAll The thrusters aare in Idle State"
e =0
button_forward = Button(app, text="↑" , padx=40, pady=20 , command = lambda : forward(e)).place(x = 160 , y= 510)
button_backward = Button(app, text="↓" , padx=40, pady=20,command = lambda : backward(e)).place(x=160,y=575 )
button_left = Button(app, text="←" , padx=40, pady=20 ,command = lambda : left(e)).place(x=50, y=575 )
button_right = Button(app, text="→" , padx=40, pady=20,command = lambda : right(e)).place(y =575, x = 270 )
button_up = Button(app, text="UP" , padx=40, pady=20,command = lambda : upward(e)).place(x = 380, y= 510 )
button_down = Button(app, text="Down" , padx=40, pady=20,command = lambda : down(e)).place(x = 380 , y= 575 )
button_reset = Button(app, text="RESET" , padx=40, pady=20 , command = lambda : reset(e)).place(x = 100, y = 680)
app.bind('<Key-Up>',forward)
# app.bind('<KeyRelease-Up>',reset)
app.bind('<Key-Left>',left)
# app.bind('<KeyRelease-Left>',reset)
app.bind('<Key-Down>',backward)
# app.bind('<KeyRelease-Down>',reset)
app.bind('<Key-Right>',right)
# app.bind('<KeyRelease-Right>',reset)
app.bind('<Key-c>',down)
# app.bind('<KeyRelease-c>',reset)
app.bind('<Key-e>',upward)
# app.bind('<KeyRelease-e>',reset)
app.bind('<Return>', reset)
ele = Text(app, width=65, height = 5 ,borderwidth=5)
ele.place(relwidth=0.42 , relheight=0.25 , relx=0.54, rely = 0.63)
ele.insert(INSERT, result)
app.mainloop()