2019-04-13 12:30:30 +00:00
|
|
|
import socket
|
2019-04-14 20:07:47 +00:00
|
|
|
import pygame
|
2019-04-13 12:30:30 +00:00
|
|
|
|
2019-04-14 20:23:34 +00:00
|
|
|
pygame.init()
|
|
|
|
pygame.display.set_mode((640, 480))
|
|
|
|
|
2019-04-13 12:30:30 +00:00
|
|
|
rc_socket = socket.socket()
|
2019-04-14 20:23:34 +00:00
|
|
|
try:
|
|
|
|
rc_socket.connect(('192.168.4.1', 1234)) # connect to robot
|
|
|
|
except socket.error:
|
|
|
|
print("could not connect to socket")
|
2019-04-13 12:30:30 +00:00
|
|
|
|
2019-04-14 20:07:47 +00:00
|
|
|
|
|
|
|
while True:
|
|
|
|
events = pygame.event.get()
|
|
|
|
for event in events:
|
|
|
|
if event.type == pygame.KEYDOWN:
|
|
|
|
if event.key == pygame.K_LEFT:
|
2019-05-05 09:01:40 +00:00
|
|
|
u1 = 1.0
|
|
|
|
u2 = -1.0
|
2019-04-14 20:07:47 +00:00
|
|
|
print("turn left: ({},{})".format(u1, u2))
|
|
|
|
elif event.key == pygame.K_RIGHT:
|
2019-05-05 09:01:40 +00:00
|
|
|
u1 = -1.0
|
|
|
|
u2 = 1.0
|
2019-04-14 20:07:47 +00:00
|
|
|
print("turn right: ({},{})".format(u1, u2))
|
|
|
|
elif event.key == pygame.K_UP:
|
2019-05-05 09:01:40 +00:00
|
|
|
u1 = -1.0
|
|
|
|
u2 = -1.0
|
2019-04-14 20:07:47 +00:00
|
|
|
print("forward: ({},{})".format(u1, u2))
|
|
|
|
elif event.key == pygame.K_DOWN:
|
2019-05-05 09:01:40 +00:00
|
|
|
u1 = 1.0
|
|
|
|
u2 = 1.0
|
2019-04-14 20:07:47 +00:00
|
|
|
print("forward: ({},{})".format(u1, u2))
|
|
|
|
rc_socket.send('({},{})\n'.format(u1, u2))
|
|
|
|
elif event.type == pygame.KEYUP:
|
2019-05-05 08:26:30 +00:00
|
|
|
u1 = 0
|
|
|
|
u2 = 0
|
2019-04-14 20:07:47 +00:00
|
|
|
print("key released, resetting: ({},{})".format(u1, u2))
|
|
|
|
rc_socket.send('({},{})\n'.format(u1, u2))
|