2019-05-06 20:23:31 +00:00
|
|
|
import socket
|
|
|
|
import pygame
|
|
|
|
|
|
|
|
pygame.init()
|
|
|
|
pygame.display.set_mode((640, 480))
|
|
|
|
|
|
|
|
rc_socket = socket.socket()
|
|
|
|
try:
|
2019-06-05 06:06:11 +00:00
|
|
|
rc_socket.connect(('192.168.1.101', 1234)) # connect to robot
|
2019-05-06 20:23:31 +00:00
|
|
|
except socket.error:
|
|
|
|
print("could not connect to socket")
|
|
|
|
|
|
|
|
|
|
|
|
while True:
|
2019-06-05 06:06:11 +00:00
|
|
|
u1 = 0
|
|
|
|
u2 = 0
|
2019-05-06 20:23:31 +00:00
|
|
|
events = pygame.event.get()
|
|
|
|
for event in events:
|
|
|
|
if event.type == pygame.KEYDOWN:
|
|
|
|
if event.key == pygame.K_LEFT:
|
|
|
|
u1 = 1.0
|
|
|
|
u2 = -1.0
|
|
|
|
print("turn left: ({},{})".format(u1, u2))
|
|
|
|
elif event.key == pygame.K_RIGHT:
|
|
|
|
u1 = -1.0
|
|
|
|
u2 = 1.0
|
|
|
|
print("turn right: ({},{})".format(u1, u2))
|
|
|
|
elif event.key == pygame.K_UP:
|
|
|
|
u1 = -1.0
|
|
|
|
u2 = -1.0
|
|
|
|
print("forward: ({},{})".format(u1, u2))
|
|
|
|
elif event.key == pygame.K_DOWN:
|
|
|
|
u1 = 1.0
|
|
|
|
u2 = 1.0
|
|
|
|
print("forward: ({},{})".format(u1, u2))
|
|
|
|
rc_socket.send('({},{})\n'.format(u1, u2))
|
|
|
|
elif event.type == pygame.KEYUP:
|
|
|
|
print("key released, resetting: ({},{})".format(u1, u2))
|
|
|
|
rc_socket.send('({},{})\n'.format(u1, u2))
|