17 BUTTON_INDICES = [58, 59,
20 32, 33, 34, 35, 36, 37, 38, 39,
21 48, 49, 50, 51, 52, 53, 54, 55,
22 64, 65, 66, 67, 68, 69, 70, 71]
23 AXIS_INDICES = [16, 17, 18, 19, 20, 21, 22, 23,
24 0, 1, 2, 3, 4, 5, 6, 7]
28 rospy.init_node(
'nanokontrol_joy')
29 pub = rospy.Publisher(
'/nanokontrol/joy', Joy, latch=
True)
32 devices = pygame.midi.get_count()
34 rospy.logerr(
"No MIDI devices detected")
36 rospy.loginfo(
"Found %d MIDI devices" % devices)
39 input_dev = int(sys.argv[1])
41 rospy.loginfo(
"no input device supplied. will try to use default device.")
42 input_dev = pygame.midi.get_default_input_id()
44 rospy.logerr(
"No default MIDI input device")
46 rospy.loginfo(
"Using input device %d" % input_dev)
48 controller = pygame.midi.Input(input_dev)
49 rospy.loginfo(
"Opened it")
52 m.axes = [ 0 ] * len(AXIS_INDICES)
53 m.buttons = [ 0 ] * len(BUTTON_INDICES)
57 while not rospy.is_shutdown():
58 m.header.stamp = rospy.Time.now()
62 while controller.poll():
64 data = controller.read(1)
65 rospy.loginfo(
"%s" % data)
70 button_index = control[1]
72 for bi, i
in zip(BUTTON_INDICES, range(len(BUTTON_INDICES))):
73 if button_index == bi:
79 for bi, i
in zip(AXIS_INDICES, range(len(AXIS_INDICES))):
80 if button_index == bi:
81 m.axes[i] = control[2] / 127.0
91 if __name__ ==
'__main__':
94 except rospy.ROSInterruptException: