Go to the documentation of this file.00001 import roslib; roslib.load_manifest('joy_listener')
00002 import rospy
00003 from sensor_msgs.msg import Joy
00004
00005 class JoyListener(dict):
00006 def __init__(self, wait_time=1.0, joy_topic='/joy'):
00007 self.wait_time = wait_time
00008 self.sub = rospy.Subscriber(joy_topic, Joy, self.joy_cb, queue_size=1)
00009 self.last_time = rospy.Time(0)
00010 self.axes_cb = None
00011
00012 def joy_cb(self, msg):
00013 buttons = msg.buttons
00014 now = rospy.Time.now()
00015 if (now- self.last_time ).to_sec() < self.wait_time:
00016 return
00017
00018 for button, function in self.iteritems():
00019 if buttons[button]:
00020 self.last_time = now
00021 function()
00022 break
00023
00024 if self.axes_cb:
00025 self.axes_cb(msg.axes)
00026
00027 PS3_BUTTONS = ['select', 'left_joy', 'right_joy', 'start', 'up', 'right', 'down', 'left', 'l2', 'r2', 'l1', 'r1', 'triangle', 'circle', 'x', 'square', 'ps3']
00028 def PS3(name):
00029 return PS3_BUTTONS.index(name)
00030
00031
00032 WII_BUTTONS = ['1', '2', 'a', 'b', '+', '-', 'left', 'right', 'up', 'down', 'home']
00033
00034 def WII(name):
00035 return WII_BUTTONS.index(name)