Line 130: |
Line 130: |
| import socket | | import socket |
| | | |
− | GRAPH_SIZE = (700,300) | + | GRAPH_SIZE = (500,400) |
| GRAPH_STEP_SIZE = 1 | | GRAPH_STEP_SIZE = 1 |
| | | |
| sg.change_look_and_feel('GreenMono') # give our window a spiffy set of colors | | sg.change_look_and_feel('GreenMono') # give our window a spiffy set of colors |
| + | # ------ GetFile Window Definition ------ # |
| + | |
| + | # ------ Menu Definition ------ # |
| + | menu_def = [['&File', ['&Open Text File to Transmit', '---', 'Properties', '---','H&alt Everything']], |
| + | ['&Help', '&About...'], ] |
| + | # ------ Column Definition ------ # |
| + | col1 = [ |
| + | [sg.Text('Bot Message response', size=(30, 1))], |
| + | [sg.Output(size=(40, 20), font=('Mono 8'))], |
| + | [sg.Text('Bot Command Single Entry', size=(30, 1))], |
| + | [sg.InputText(size=(30, 0), key='-QUERY-')], |
| + | [sg.Button('Send Command',size=(20,1), button_color=(sg.YELLOWS[0], sg.GREENS[0]), bind_return_key=True)], |
| + | ] |
| + | col2 = [ |
| + | [sg.Text('Bot Jitter Test',font=('Mono 9'), justification="center", size=(48, 1))], |
| + | [sg.Button('<<CCW',size=(10,1),font=('Mono 9'), button_color=(sg.YELLOWS[0], sg.GREENS[0])), |
| + | sg.Button('S2S-F2B',size=(10,1),font=('Mono 9'), button_color=(sg.YELLOWS[0], sg.GREENS[0])), |
| + | sg.Button('Combo',size=(10,1),font=('Mono 9'), button_color=(sg.YELLOWS[0], sg.GREENS[0])), |
| + | sg.Button('CW>>',size=(10,1),font=('Mono 9'), button_color=(sg.YELLOWS[0], sg.GREENS[0]))], |
| + | |
| + | [sg.Text('Bot Rotation',font=('Mono 9'), justification="center", size=(48, 1))], |
| + | [sg.Button('<<180 CCW',size=(10,1),font=('Mono 9'), button_color=(sg.YELLOWS[0], sg.GREENS[0])), |
| + | sg.Button('<180 CCW',size=(10,1),font=('Mono 9'), button_color=(sg.YELLOWS[0], sg.GREENS[0])), |
| + | sg.Button('180 CW>',size=(10,1),font=('Mono 9'), button_color=(sg.YELLOWS[0], sg.GREENS[0])), |
| + | sg.Button('180 CW>>',size=(10,1),font=('Mono 9'), button_color=(sg.YELLOWS[0], sg.GREENS[0])),], |
| + | |
| + | [sg.Button('<<Input CCW',size=(15,1),font=('Mono 9'), button_color=(sg.YELLOWS[0], sg.GREENS[0])), |
| + | sg.InputText(size=(11, 0), justification="center", key='-Rotate-'), |
| + | sg.Button('Input CW>>',size=(15,1),font=('Mono 9'), button_color=(sg.YELLOWS[0], sg.GREENS[0])), |
| + | ], |
| + | |
| + | [sg.Text('IMU',font=('Mono 9'), justification="center", size=(48, 1))], |
| + | [sg.Button('Zero to North',size=(16,1),font=('Mono 9'), button_color=(sg.YELLOWS[0], sg.GREENS[0])), |
| + | sg.Button('South',size=(8,1),font=('Mono 9'), button_color=(sg.YELLOWS[0], sg.GREENS[0])), |
| + | sg.Button('East',size=(8,1),font=('Mono 9'), button_color=(sg.YELLOWS[0], sg.GREENS[0])), |
| + | sg.Button('West',size=(8,1),font=('Mono 9'), button_color=(sg.YELLOWS[0], sg.GREENS[0])),], |
| + | |
| + | [sg.Text('Linear Movement',font=('Mono 9'), justification="center", size=(48, 1))], |
| + | [sg.Text('Bot Angle:',font=('Mono 9'), justification="Left", size=(10, 1)), |
| + | sg.InputText(size=(5, 0), justification="center", key='-BotAngle-'), |
| + | sg.Text('Line of Bearing:',font=('Mono 9'), justification="Left", size=(15, 1)), |
| + | sg.InputText(size=(5, 0), justification="center", key='-Bearing-'),], |
| + | [sg.Text('Speed:',font=('Mono 9'), justification="Left", size=(8, 1)), |
| + | sg.Slider(range=(1,255),key='speed', default_value=127, size=(22,15), orientation='horizontal', font=('Helvetica', 12)),], |
| + | [sg.Button('Execute Move',size=(15,1),font=('Mono 9'), button_color=(sg.YELLOWS[0], sg.GREENS[0])), |
| + | sg.Button('Execute Move with Spin',size=(30,1),font=('Mono 9'), button_color=(sg.YELLOWS[0], sg.GREENS[0])),], |
| + | ] |
| + | col3 = [ |
| + | [sg.Graph(GRAPH_SIZE, (0,0), GRAPH_SIZE, key='-GRAPH-', background_color='lightblue') |
| + | ], |
| + | |
| + | ] |
| + | layout = [ |
| + | [sg.Menu(menu_def, tearoff=True)], |
| + | [sg.Column(col1, pad=((1,1),(1,1)), justification="left", background_color = None), |
| + | sg.Column(col2, pad=((1,1),(1,1)), justification="left", background_color = None), |
| + | sg.Column(col3, pad=((1,1),(1,1)), justification="left", background_color = None), |
| + | ]] |
| | | |
− | layout = [[sg.Text('Robot Message response', size=(30, 1))],
| |
− | [sg.Output(size=(30, 20), font=('Mono 9')),
| |
− | sg.Graph(GRAPH_SIZE, (0,0), GRAPH_SIZE, key='-GRAPH-', background_color='lightblue')],
| |
− | [sg.Text('Robot Command Entry', size=(30, 1))],
| |
− | [sg.InputText(size=(30, 0), key='-QUERY-'),
| |
− | sg.Button('Send Command',size=(20,1), button_color=(sg.YELLOWS[0], sg.GREENS[0]), bind_return_key=True)],
| |
− | [sg.Button('Halt Everything',size=(20,1), button_color=(sg.YELLOWS[0], sg.GREENS[0]))]]
| |
| | | |
− | main_window = sg.Window('Robot Window Control', layout, font=('Helvetica', ' 11'), default_button_element_size=(8, 2)) | + | main_window = sg.Window('Crawler Bot Window Control', layout, font=('Helvetica', ' 11'), default_button_element_size=(8, 2)) |
| | | |
− | #start executing here | + | #start executing main here --------------------------------------- |
| if __name__ == '__main__': | | if __name__ == '__main__': |
− | | + | #sg.Popup('Data!') |
| message_from_bot = '' | | message_from_bot = '' |
− | client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | + | #client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
− | client.connect(('192.168.1.132', 13000)) | + | #client.connect(('192.168.1.132', 13000)) |
| escape = True | | escape = True |
| | | |
| while escape == True: | | while escape == True: |
| message_from_bot ='' | | message_from_bot ='' |
| + | #----------------process all the window events -------------------------- |
| event, value = main_window.read() | | event, value = main_window.read() |
| + | if event == 'Open Text File to Transmit': |
| + | text = sg.PopupGetFile("Open the file to transmit", |
| + | save_as=False, |
| + | file_types=(('ALL Files', '*.*'),), |
| + | no_window=False, |
| + | location=(None, None), |
| + | initial_folder=None) |
| + | #transmit line by line to the bot |
| + | print ("Transmitting Message") |
| + | #client.send(message_to_bot.encode()) |
| if event == 'Halt Everything': | | if event == 'Halt Everything': |
| message_to_bot = "SRS" | | message_to_bot = "SRS" |
− | client.send(message_to_bot.encode()) | + | #client.send(message_to_bot.encode()) |
| break | | break |
| if event == 'Send Command': | | if event == 'Send Command': |
| message_to_bot = value['-QUERY-'].rstrip() | | message_to_bot = value['-QUERY-'].rstrip() |
− | client.send(message_to_bot.encode()) | + | #client.send(message_to_bot.encode()) |
− | | + | #------------------------------------------------------------------------- |
− | message_from_bot = (client.recv(4096)).decode() | + | #message_from_bot = (client.recv(4096)).decode() |
| print (message_from_bot) | | print (message_from_bot) |
| if message_from_bot == "RxAck:Engaging Robot Shutdown" : escape = False | | if message_from_bot == "RxAck:Engaging Robot Shutdown" : escape = False |
| | | |
| main_window.close() | | main_window.close() |
− | client.close() | + | #client.close() |
| print ("You ended the Robot Server Session") | | print ("You ended the Robot Server Session") |
| </source> | | </source> |