martedì 8 maggio 2012

Controllare joypad da Python

Sto cerando di modificare il mio joypad (un Tust GM-1300) per pilotare un piccolo ROV telecomandato con scheda Arduino. Per fare cio' avevo la necessita' di leggere i dati dal joypad e convertirli su una seriale.
Il modo piu' semplice si e' rivelato essere usare Python/Pygame che rileva in modo assolutamente trasparente il joypad USB


Attenzione: per il seguente programma e' necessario che sia presente nella stessa directory dello script Python anche il file pycurse.py che si scarica da questo indirizzo
--------------------------------------------------------------------------------------------
import pygame
import pygcurse

pygame.init()
win = pygcurse.PygcurseWindow(40, 25, 'Rov Controller')

j = pygame.joystick.Joystick(0)
j.init()

try:
    while True:
        pygame.event.pump()
        win.write("Tot.assi : "+str(j.get_numaxes()), x=2, y=1)
        win.write("Tot.pulsanti : "+str(j.get_numbuttons()), x=2, y=2)
        win.write("Asse 1 : "+str(j.get_axis(0)), x=2, y=3)
        win.write("Asse 2 : "+str(j.get_axis(1)), x=2, y=4)
        win.write("Asse 3 : "+str(j.get_axis(2)), x=2, y=5)
        win.write("Asse 4 : "+str(j.get_axis(3)), x=2, y=6)
       
        win.write("Pulsante 1 : "+str(j.get_button(0)), x=2, y=7)
        win.write("Pulsante 2 : "+str(j.get_button(1)), x=2, y=8)
        win.write("Pulsante 3 : "+str(j.get_button(2)), x=2, y=9)
        win.write("Pulsante 4 : "+str(j.get_button(3)), x=2, y=10)
        win.write("Pulsante 5 : "+str(j.get_button(4)), x=2, y=11)
        win.write("Pulsante 6 : "+str(j.get_button(5)), x=2, y=12)
        win.write("Pulsante 7 : "+str(j.get_button(6)), x=2, y=13)
  

except KeyboardInterrupt:
    j.quit()




Nessun commento:

Posta un commento

FTP Bash script

 Uno script rubato su stack overflow per fare l'upload automatico su FTP senza criptazione   #!/bin/sh HOST='ftp.xxxxx.altervista.or...