forked from Telos4/RoboRally
36 lines
1.1 KiB
Python
36 lines
1.1 KiB
Python
import socket
|
|
import pygame
|
|
|
|
rc_socket = socket.socket()
|
|
rc_socket.connect(('192.168.4.1', 1234)) # connect to robot
|
|
|
|
pygame.init()
|
|
pygame.display.set_mode()
|
|
|
|
while True:
|
|
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:
|
|
u1 = 0.0
|
|
u2 = 0.0
|
|
print("key released, resetting: ({},{})".format(u1, u2))
|
|
rc_socket.send('({},{})\n'.format(u1, u2))
|