Regarding Joystick

shreyas shah shreyas22 at gmail.com
Mon Feb 16 16:27:14 EST 2009


Hi ,

I have figured out a code with the help of archives in pygame ....

can anyone help me with controlling the speed of joystick ... i am going to
integrate joystick with a PTZ camera ... i was wondering if there are any
functions which can help me control the speed of camera and by controlling
motion of joystick


#! /usr/bin/env python

import pygame
from pygame import locals




jlist = [] # global joystick list


class Joystick:


    def __init__(self):
        pygame.init()
        self.nbJoy = pygame.joystick.get_count()

        for n in range(self.nbJoy):
            pygame.joystick.Joystick(n).init()

        try:
            for n in range(pygame.joystick.get_count()): #
                stick = pygame.joystick.Joystick(n)
                jlist.append(stick) # create a joystick instance
                stick.init() # init instance
                # report joystick charateristics #
                print '-'*20
                print 'Enabled joystick: ' + stick.get_name()
                print 'it has the following devices :'
                print '--> buttons : '+ str(stick.get_numbuttons())
                print '--> balls : '+ str(stick.get_numballs())
                print '--> axes : '+ str(stick.get_numaxes())
                print '--> hats : '+ str(stick.get_numhats())
                print '-'*20
        except pygame.error:
            print 'pygame.error, no joystick found.'





    def main(self):


    #    init() # init pygame and joystick system


        while 1: # endless loop

            for e in pygame.event.get(): # iterate over event stack


                if e.type == pygame.locals.JOYAXISMOTION: # 7
                    for j in jlist:
                        for n in range(j.get_numaxes()):
                            print 'moved axe num '+str(n)+' : ' +
str(j.get_axis(n))
                            print '-'*10 # separation


                elif e.type == pygame.locals.JOYBALLMOTION: # 8
                    for j in jlist:
                        for n in range(j.get_numballs()):
                            print 'moved ball num '+str(n)+' : '+
str(j.get_ball(n))
                            print '-'*10 # separation


                elif e.type == pygame.locals.JOYHATMOTION: # 9
                    for j in jlist:
                        for n in range(j.get_numhats()):
                            print 'moved hat num '+str(n)+' : '+
str(j.get_hat(n))
                            print '-'*10 # separation


                elif e.type == pygame.locals.JOYBUTTONDOWN: # 10
                    for j in jlist:
                        for n in range(j.get_numbuttons()):
                            if j.get_button(n) : # if this is down
                                print 'down button num '+str(n)+' : '+
str(j.get_button(n))
                                print '-'*10 # separation

                elif e.type == pygame.locals.JOYBUTTONUP: # 11
                    for j in jlist:
                        for n in range(j.get_numbuttons()):
                            print 'up button num '+str(n)+' : '+
str(j.get_button(n))
                            print '-'*10 # separation


if __name__ == '__main__':
    j = Joystick()
    j.main()


thanks
shreyas






On Thu, Feb 12, 2009 at 11:36 PM, Banibrata Dutta <banibrata.dutta at gmail.com
> wrote:

> AFAIK, the mechanism / API / protocol to actuate the Camera's tilt, pan,
> zoom functions are not standardized (happy to be corrected there!), so even
> if you find something, it'd most likely be something very specific to a
> particular device.
> As for Joystick usage, I remember seeing one thread on that couple of
> months back, so searching thru the archive should give you leads.
>
> On Fri, Feb 13, 2009 at 3:33 AM, shreyas shah <shreyas22 at gmail.com> wrote:
>
>> Hi ,
>>
>> I am trying to control the motion of the camera with help of joystick , i
>> need some basic functionality where if i move a joystick to left the camera
>> moves to the left . Can anyone help me with that ?
>>
>> Thanks
>> Shreyas
>>
>>
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
>>
>
>
> --
> regards,
> Banibrata
> http://www.linkedin.com/in/bdutta
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090216/6228079a/attachment-0001.html>


More information about the Python-list mailing list