[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[pygame] Joystick centering



I'm using a Logitech gamepad with PyGame and I've found that there are serious problems with centering.

Using the code below to print out x and y values from the right-hand joystick on the gamepad, I get the numbers below. There are a couple of spurious values in there, especially at the beginning:

1) Why is the first measurement (-1.0, -1.0)?
2) Why does the first down/right movement contain jitter like:

(0.999969482421875, 0.999969482421875)
(-0.21435546875, -0.428619384765625)
(0.999969482421875, 0.999969482421875)
(-0.48724365234375, -0.2222900390625)

3) Why does recentering after the first movement end up pointing up and left?

(-1.0, -1.0)
(-1.0, -0.51806640625)
(-0.42498779296875, -0.51806640625)
(-0.587493896484375, -0.590362548828125)
(-0.54998779296875, -0.445770263671875)
(-0.54998779296875, -0.530120849609375)

It doesn't appear to be a problem with the gamepad itself, because after twiddling the joystick around for a while, the problem goes away until I restart the program. I am using the Mac OSX binary distro of PyGame 1.8.0.

Malcolm

----
import pygame
from pygame.locals import *

pygame.init()
pygame.joystick.init()
if (not pygame.joystick.get_count()):
   print "No Joystick available. Quitting."
   exit

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

ox = 0.0
oy = 0.0
button = 0

while 1:
    pygame.event.pump()

    x = joystick.get_axis(2)
    y = joystick.get_axis(3)

    if (x != ox or y != oy):
        print (x,y)
        ox = x
        oy = y

    obutton = button
    button = joystick.get_button(0)

    if (button and not obutton):
        print "Here"

--- annotated output  ---
Start with joystick centred
(-1.0, -1.0)
(0.0040283203125, 0.00390625)

Move down and right
(0.00408935546875, 0.00390625)
(0.999969482421875, 0.00390625)
(-9.1552734375e-05, 0.003997802734375)
(0.999969482421875, 0.999969482421875)
(0.599945068359375, 0.999908447265625)
(0.999969482421875, 0.999969482421875)
(0.999969482421875, 0.7777099609375)
(0.99993896484375, 0.999969482421875)
(0.999969482421875, 0.999969482421875)
(0.111053466796875, 0.2940673828125)
(0.999969482421875, 0.999969482421875)
(-0.21435546875, -0.428619384765625)
(0.999969482421875, 0.999969482421875)
(-0.48724365234375, -0.2222900390625)
(0.999969482421875, 0.999969482421875)
(-0.428619384765625, -0.4400634765625)
(0.999969482421875, 0.999969482421875)
(-0.49212646484375, -0.40631103515625)
(0.999969482421875, 0.999969482421875)
(-0.670928955078125, -0.590423583984375)
(0.999969482421875, 0.999969482421875)
(-0.6304931640625, -0.56005859375)
(0.999969482421875, 0.999969482421875)
(-0.761505126953125, -0.9180908203125)
(0.999969482421875, 0.999969482421875)
(-0.983642578125, 0.999969482421875)
(0.999969482421875, 0.999969482421875)

Recenter
(0.999969482421875, 0.93695068359375)
(0.398345947265625, 0.259796142578125)
(-1.0, -1.0)
(-1.0, -0.51806640625)
(-0.42498779296875, -0.51806640625)
(-0.587493896484375, -0.590362548828125)
(-0.54998779296875, -0.445770263671875)
(-0.54998779296875, -0.530120849609375)

Move up and left
(-0.587493896484375, -0.530120849609375)
(-0.587493896484375, -0.54217529296875)
(-0.600006103515625, -0.54217529296875)
(-0.600006103515625, -0.626495361328125)
(-0.699981689453125, -0.73492431640625)
(-0.837493896484375, -0.89154052734375)
(-1.0, -1.0)

Recenter
(-1.0, -0.960784912109375)
(-1.0, -0.937255859375)
(-0.6549072265625, -0.537261962890625)
(0.00390625, -0.035308837890625)
(0.0352783203125, 0.00390625)

Move down and right
(0.05096435546875, 0.00390625)
(0.05096435546875, 0.011749267578125)
(0.105865478515625, 0.058807373046875)
(0.23919677734375, 0.105865478515625)
(0.372528076171875, 0.1607666015625)
(0.55291748046875, 0.231353759765625)
(0.7568359375, 0.278411865234375)
(0.945068359375, 0.309783935546875)
(0.999969482421875, 0.33331298828125)
(0.999969482421875, 0.372528076171875)
(0.999969482421875, 0.42742919921875)
(0.999969482421875, 0.4744873046875)
(0.999969482421875, 0.52154541015625)
(0.999969482421875, 0.576446533203125)
(0.999969482421875, 0.63134765625)
(0.999969482421875, 0.67840576171875)
(0.999969482421875, 0.74114990234375)
(0.999969482421875, 0.796051025390625)
(0.999969482421875, 0.890167236328125)
(0.999969482421875, 0.96075439453125)
(0.999969482421875, 0.999969482421875)

Recenter
(0.999969482421875, 0.96075439453125)
(0.80389404296875, 0.74114990234375)
(-0.301971435546875, -0.349029541015625)
(0.05096435546875, -0.0274658203125)
(0.00390625, 0.074493408203125)
(0.027435302734375, 0.05096435546875)
(0.027435302734375, 0.00390625)
(0.0352783203125, 0.00390625)




-- "Our age is not willing to stop with faith, with its miracle of turning water into wine, it goes further, it turns wine into water." -- Soren Kierkegaard, "Fear and Trembling"