• Advertisement
Sign in to follow this  

Joypad in Python/Pygame

This topic is 3226 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm using a simple...
while True: 
   for event in pygame.event.get():
      print event 
      if event.type == QUIT:
         pygame.display.quit()
         sys.exit(0)
      elif event.type == KEYDOWN and event.key == K_ESCAPE:
         pygame.display.quit()
         sys.exit(0)
...to test the inputs on my joypad, and I notice the values printed aren't as simple as I had hoped they would be. Namely, I press "UP", "DOWN", "LEFT", "RIGHT" in turn and I get: <Event(7-JoyAxisMotion {'joy': 0, 'value': -1.000030518509476, 'axis': 1})> <Event(7-JoyAxisMotion {'joy': 0, 'value': -3.0518509475997192e-005, 'axis': 1})> <Event(7-JoyAxisMotion {'joy': 0, 'value': 1.0, 'axis': 1})> <Event(7-JoyAxisMotion {'joy': 0, 'value': -3.0518509475997192e-005, 'axis': 1})> <Event(7-JoyAxisMotion {'joy': 0, 'value': -1.000030518509476, 'axis': 0})> <Event(7-JoyAxisMotion {'joy': 0, 'value': -3.0518509475997192e-005, 'axis': 0})> <Event(7-JoyAxisMotion {'joy': 0, 'value': 1.0, 'axis': 0})> <Event(7-JoyAxisMotion {'joy': 0, 'value': -3.0518509475997192e-005, 'axis': 0})> Will these values be the same on other PCs and other joypads? In other words, is it safe to use something like "if value == -1.000030518509476:". If not, will these values always be close enough to -1, 0 and 1 so that a simple nearest integer approximation will work for all of them (e.g. there aren't any pads that use 1 for "UP", 2 for "CENTRE" and 3 for "DOWN")? Otherwise, I can't see any way of avoiding having an in-game callibration.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Dirichlet
Will these values be the same on other PCs and other joypads? In other words, is it safe to use something like "if value == -1.000030518509476:". If not, will these values always be close enough to -1, 0 and 1 so that a simple nearest integer approximation will work for all of them (e.g. there aren't any pads that use 1 for "UP", 2 for "CENTRE" and 3 for "DOWN")?

The only guarantees are that each axis is independent, and represents a linear spectrum (although the distribution of measurements across that spectrum, even for digital pads, is not necessarily linear). A small amount of jitter may also exist at the neutral (center) position.

Quote:
Otherwise, I can't see any way of avoiding having an in-game callibration.

Yes. In-game calibration is necessary to support the majority of joysticks available.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement