Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
50 lines (43 sloc) 1.23 KB
import sys, pygame
import xmlrpc.client
from pygame.locals import *
# Initialise pygame
pygame.init()
size = width, height = 1000, 800
black = 0, 0, 0
clock = pygame.time.Clock()
pygame.joystick.init()
joysticks = [pygame.joystick.Joystick(x) for x in range(pygame.joystick.get_count())]
print(str(len(joysticks)) + " joysticks detected.")
for joystick in joysticks:
joystick.init()
name = joystick.get_name()
print("Joystick found: " + name)
screen = pygame.display.set_mode(size)
ball = pygame.image.load("ball.gif")
ballrect = ball.get_rect()
# Initialise RPC
server = xmlrpc.client.ServerProxy("http://192.168.1.103:8000")
# Event loop
speed = [0,0]
while 1:
i = 0
for event in pygame.event.get():
if event.type == QUIT:
sys.exit()
# Get joypad input
if event.type == JOYAXISMOTION:
if event.axis == 0:
speed[0] = int(event.value * 10)
elif event.axis == 1:
speed[1] = int(event.value * 10)
ballrect = ballrect.move(speed)
screen.fill(black)
screen.blit(ball, ballrect)
pygame.display.flip()
if i % 60 == 0:
print("sending move command: "+str(speed))
server.move_robot(speed[0], speed[1])
print("sent move command: "+str(speed))
clock.tick(60)
i += 1