本文整理汇总了Python中sensor_msgs.msg.Joy.axes[index]方法的典型用法代码示例。如果您正苦于以下问题:Python Joy.axes[index]方法的具体用法?Python Joy.axes[index]怎么用?Python Joy.axes[index]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sensor_msgs.msg.Joy
的用法示例。
在下文中一共展示了Joy.axes[index]方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from sensor_msgs.msg import Joy [as 别名]
# 或者: from sensor_msgs.msg.Joy import axes[index] [as 别名]
def main():
global joy
pygame.midi.init()
rospy.init_node('midi_joy')
# parse the arg
argv = rospy.myargv()
if len(argv) == 0:
rospy.logfatal("You need to specify config yaml file")
sys.exit(1)
config_file = argv[1]
joy_pub = rospy.Publisher("/joy", Joy, queue_size=10)
autorepeat_rate = rospy.get_param("~autorepeat_rate", 0)
if autorepeat_rate == 0:
r = rospy.Rate(1000)
else:
r = rospy.Rate(autorepeat_rate)
with open(config_file, "r") as f:
config = yaml.load(f)
# open the device
controller = openMIDIInputByName(config["device_name"])
joy = Joy()
joy.axes = [0.0] * len(config["analogs"])
# automatically mapping to buttons from axes if it has NOTE_OFF or NOTE_ON MIDI commands
button_configs = [c for c in config["analogs"]
if c[0] == MIDICommand.NOTE_ON or c[0] == MIDICommand.NOTE_OFF]
if config.has_key("output"):
out_controller = openMIDIOutputByName(config["device_name"])
s = rospy.Subscriber("~set_feedback", JoyFeedbackArray, lambda msg: feedback_array_cb(out_controller, config, msg))
joy.buttons = [0] * len(button_configs)
while not rospy.is_shutdown():
joy.header.stamp = rospy.Time.now()
p = False
while controller.poll():
data = controller.read(1)
for elem_set in data:
p = True
(command, ind, val) = MIDIParse(elem_set)
try:
index = config["analogs"].index((command, ind))
joy.axes[index] = val
if command == MIDICommand.NOTE_ON or command == MIDICommand.NOTE_OFF:
button_index = button_configs.index((command, ind))
if val == 0.0:
joy.buttons[button_index] = 0
else:
joy.buttons[button_index] = 1
except:
rospy.logwarn("unknown MIDI message: (%d, %d, %f)" % (command, ind, val))
if (autorepeat_rate != 0) or p:
joy_pub.publish(joy)
r.sleep()