joy_controller.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 import os
00004 
00005 import rospy
00006 import roslib
00007 
00008 roslib.load_manifest("jsk_pr2_startup")
00009 
00010 from sensor_msgs.msg import Joy
00011 
00012 class JoyController():
00013     def __init__(self):
00014         rospy.Subscriber("/joy", Joy, self.joy_callback)
00015         self.previous_joy = None
00016         rospy.spin()
00017 
00018     def joy_callback(self, joy):
00019         self.joy = joy
00020         self.joy_execute()
00021         self.previous_joy = joy
00022 
00023     def joy_execute(self):
00024         if self.check_pushed(0):
00025             print "0 is pushed"
00026         pass
00027 
00028     def check_pushed(self, index):
00029         if self.previous_joy != None and index < len(self.joy.buttons):
00030             if self.previous_joy.buttons[index] == 0 and self.joy.buttons[index] == 1:
00031                 return True
00032         return False
00033 
00034 if __name__ =='__main__':
00035     rospy.init_node('joy_controller', anonymous=True)
00036     joy_controller = JoyController()


jsk_pr2_startup
Author(s):
autogenerated on Sat Jul 1 2017 02:43:24