00001 #! /usr/bin/python 00002 # Copyright (c) 2009, Willow Garage, Inc. 00003 # All rights reserved. 00004 # 00005 # Redistribution and use in source and binary forms, with or without 00006 # modification, are permitted provided that the following conditions are met: 00007 # 00008 # * Redistributions of source code must retain the above copyright 00009 # notice, this list of conditions and the following disclaimer. 00010 # * Redistributions in binary form must reproduce the above copyright 00011 # notice, this list of conditions and the following disclaimer in the 00012 # documentation and/or other materials provided with the distribution. 00013 # * Neither the name of the Willow Garage, Inc. nor the names of its 00014 # contributors may be used to endorse or promote products derived from 00015 # this software without specific prior written permission. 00016 # 00017 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00018 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00019 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00020 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00021 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00022 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00023 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00024 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00025 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00026 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00027 # POSSIBILITY OF SUCH DAMAGE. 00028 00029 # Author: Stuart Glaser 00030 00031 import time 00032 import fcntl 00033 from math import pi 00034 00035 import roslib 00036 roslib.load_manifest('infinity_pedals') 00037 import rospy 00038 from joy.msg import * 00039 00040 import atexit 00041 atexit.register(rospy.signal_shutdown, 'exit') 00042 00043 rospy.init_node('infinity_pedals', disable_signals=True) 00044 00045 pub_joy = rospy.Publisher(rospy.get_name() + '/joy', Joy) 00046 00047 def main(): 00048 device = '/dev/hidraw1' 00049 try: 00050 device = rospy.get_param(rospy.get_name() + '/device') 00051 except: 00052 rospy.logerr("No device given: %s" % rospy.get_name()) 00053 return 00054 00055 with open(device, 'rb') as fhid: 00056 while True: 00057 buf = fhid.read(2) 00058 input = [ord(c) for c in buf] 00059 msg = Joy(buttons = [0] * 3) 00060 for i in range(3): 00061 if (1<<i) & input[0] != 0: 00062 msg.buttons[i] = True 00063 pub_joy.publish(msg) 00064 00065 if __name__ == '__main__': 00066 try: 00067 main() 00068 except KeyboardInterrupt: 00069 pass