1

下面是带有按钮和motionplus 设置为报告模式的wii motionplus 控制器的输出。我试过像用电路板或加速度计一样询问它,即。但它似乎总是抛出错误,所以我决定把它当作一个字符串来处理。

{'led': 1, 'rpt_mode': 130, 'ext_type': 4, 'motionplus': {'angle_rate': (8195, 8284, 8167)}, 'buttons': 0, 'rumble': 0, 'error': 0, 'battery': 74}

所有的数字都随着时间不断变化。

下面是试图整理它的代码:

import cwiid, time, re
#Some stuff here for connecting wiimotem create object, etc.

    #Grab state as string,split by whitespace and put into list:
    splitit = str(wm.state).split()
    #Output list
    wmp_out = []
    #Scan across splitit list
    for x in splitit:
        #Remove all non numeric characters from element in list
        s_dat = re.compile(r'[^\d.]+').sub('',x)
        #append to output only if element contains something (i.e. number)
        if len(s_dat) != 0: wmp_out.append(s_dat)
        else: pass
        #Output to screen
        print testarr[3], " ", testarr[4], " ", testarr[5]
    time.sleep(0.1)

还有其他人有更好的方法吗?我需要存储在列表中的三个motionplus 值。我已经看到这些值在极端旋转时达到 0,因此阈值或不会削减它。特别是我对整个 re.compile() 函数非常粗略......目前它会删除除小数位以外的所有内容。

4

0 回答 0