14 node_name =
"simple_joy" 16 node_name = sys.argv[1]
18 rospy.init_node(node_name)
19 pub = rospy.Publisher(
"/" + node_name +
"/joy", Joy, latch=
True)
22 pygame.joystick.init()
23 devices = pygame.joystick.get_count()
25 rospy.logerr(
"No Joystick devices detected")
27 rospy.loginfo(
"Found %d Joystick devices" % devices)
33 input_dev = int(sys.argv[2])
35 joy_name = sys.argv[2]
37 rospy.loginfo(
"no input device supplied. will try to use default device.")
39 rospy.loginfo(
"Using input device %d" % input_dev)
43 controller = pygame.joystick.Joystick(input_dev)
45 for i
in range(pygame.joystick.get_count()):
46 if joy_name
in pygame.joystick.Joystick(i).get_name():
47 controller = pygame.joystick.Joystick(i)
49 if controller ==
None:
50 rospy.logerr(
"No Joystick controller generated")
54 axes = controller.get_numaxes()
55 buttons = controller.get_numbuttons()
56 hats = controller.get_numhats()
58 rospy.loginfo(
"Opened it")
62 m.buttons = [ 0 ] * buttons
67 while not rospy.is_shutdown()
and done==
False:
68 m.header.stamp = rospy.Time.now()
70 for event
in pygame.event.get():
71 if event.type == pygame.QUIT:
73 if event.type == pygame.JOYBUTTONDOWN:
75 if event.type == pygame.JOYBUTTONUP:
78 for i
in range( axes ):
79 axis = controller.get_axis( i )
82 for i
in range( buttons ):
83 button = controller.get_button( i )
86 for i
in range( hats ):
87 hat = controller.get_hat( i )
92 if __name__ ==
'__main__':
95 except rospy.ROSInterruptException: