forked from DexterInd/GoPiGo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathline_sensor_gui.py
More file actions
executable file
·108 lines (84 loc) · 3.94 KB
/
line_sensor_gui.py
File metadata and controls
executable file
·108 lines (84 loc) · 3.94 KB
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
#!/usr/bin/python
try:
import wx
except ImportError:
raise ImportError,"The wxPython module is required to run this program"
try: #first look for libraries in the same folder
import sys
#sys.path.insert(0, '/home/pi/Dexter/GoPiGo/Software/Python/line_follower')
import line_sensor
import scratch_line
except ImportError:
try: # look in the standard Raspbian for Robots folder.
sys.path.insert(0, '/home/pi/Dexter/GoPiGo/Software/Python/line_follower')
import line_sensor
import scratch_line
except ImportError:
raise ImportError,"Line sensor libraries not found"
sys.exit(0)
y=200
class line_sensor_app(wx.Frame):
def __init__(self,parent,id,title):
wx.Frame.__init__(self,parent,id,title,size=(500,400))
self.parent = parent
self.initialize()
# Exit
exit_button = wx.Button(self, label="Exit", pos=(25,350))
exit_button.Bind(wx.EVT_BUTTON, self.onClose)
robot = "/home/pi/Desktop/GoBox/Troubleshooting_GUI/dex.png"
png = wx.Image(robot, wx.BITMAP_TYPE_ANY).ConvertToBitmap()
wx.StaticBitmap(self, -1, png, (395, 275), (png.GetWidth()-320, png.GetHeight()-10))
self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground) # Sets background picture
#----------------------------------------------------------------------
def OnEraseBackground(self, evt):
"""
Add a picture to the background
"""
# yanked from ColourDB.py
dc = evt.GetDC()
if not dc:
dc = wx.ClientDC(self)
rect = self.GetUpdateRegion().GetBox()
dc.SetClippingRect(rect)
dc.Clear()
bmp = wx.Bitmap("/home/pi/Desktop/GoBox/Troubleshooting_GUI/dex.png") # Draw the photograph.
dc.DrawBitmap(bmp, 0, 400) # Absolute position of where to put the picture
def initialize(self):
sizer = wx.GridBagSizer()
# Set up buttons
black_line_set_button = wx.Button(self,-1,label="Set Black Line Values", pos=(10,y))
sizer.Add(black_line_set_button, (0,1))
self.Bind(wx.EVT_BUTTON, self.black_line_set_OnButtonClick, black_line_set_button)
white_line_set_button = wx.Button(self,-1,label="Set White Line Values", pos=(180,y))
sizer.Add(white_line_set_button, (0,1))
self.Bind(wx.EVT_BUTTON, self.white_line_set_button_OnButtonClick, white_line_set_button)
line_position_set_button = wx.Button(self,-1,label="Read Line Position", pos=(350,y))
sizer.Add(line_position_set_button, (0,1))
self.Bind(wx.EVT_BUTTON, self.line_position_set_button_OnButtonClick, line_position_set_button)
# Set up labels: This is where the output of sensor readings will be printed.
self.label = wx.StaticText(self,-1,label=u' ',pos=(150,y+150)) # Prints line sensor information out.
self.label_top = wx.StaticText(self,-1,label=u'Instructions:\n 1.\tPlace the line sensor so that all of the black sensors are over \n\tyour black line. Then press the button "Black Line Sensor Set".\n\n 2.\tNext, place the line sensor so that all of the black sensors are \n\tNOT over your black line and on the white background surface.\n\tThen press "White Line Sensor Set".\n\n 3.\tFinally, test the sensor by pressing "Read Line Position"',pos=(25,0))
sizer.Add( self.label, (1,0),(1,2), wx.EXPAND )
sizer.Add( self.label_top, (1,0),(1,2), wx.EXPAND )
self.Show(True)
def black_line_set_OnButtonClick(self,event):
for i in range(2):
line_sensor.get_sensorval()
line_sensor.set_black_line()
line_val=line_sensor.get_black_line()
self.label.SetLabel("Black Line : "+str(line_val))
def white_line_set_button_OnButtonClick(self,event):
for i in range(2):
line_sensor.get_sensorval()
line_sensor.set_white_line()
line_val=line_sensor.get_white_line()
self.label.SetLabel("White Line : "+str(line_val))
def line_position_set_button_OnButtonClick(self,event):
line_val=scratch_line.absolute_line_pos()
self.label.SetLabel("Line Position : "+str(line_val))
def onClose(self, event): # Close the entire program.
self.Close()
if __name__ == "__main__":
app = wx.App()
frame = line_sensor_app(None,-1,'Line Follower Calibration')
app.MainLoop()