Python 与 Wiimote 使用 pywiiuse 模块

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/481943/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 20:12:37  来源:igfitidea点击:

Python with Wiimote using pywiiuse module

pythonwiimotewii

提问by

After seeing the abilities and hackibility of wiimotes I really want to use it in my 'Intro to programming' final. Everyone must make a python program and present it to the class.

在看到 wiimotes 的能力和可修改性后,我真的很想在我的“编程入门”决赛中使用它。每个人都必须制作一个python程序并展示给全班。

I want to make a game with pygame incorporating a wiimote. I found pywiiusewhich is a very basic wrapper for the wiiuselibrary using c types.

我想用 pygame 制作一个包含 wiimote 的游戏。我发现pywiiuse是使用 c 类型的wiiuse库的一个非常基本的包装器。

I can NOT get anything beyond LEDs and vibrating to work. Buttons, IR, motion sensing, nothing. I've tried different versions of wiiuse, pywiiuse, even python. I can't even get the examples that came with it to run. Here's the code I made as a simple test. I copied some of the example C++ code.

除了 LED 和振动之外,我无法获得任何东西。按钮、红外线、动作感应,什么都没有。我试过不同版本的wiiuse、pywiiuse,甚至python。我什至无法运行它附带的示例。这是我作为简单测试编写的代码。我复制了一些示例 C++ 代码。

from pywiiuse import *
from time     import sleep

#Init
wiimotes = wiiuse_init()

#Find and start the wiimote
found    = wiiuse_find(wiimotes,1,5)

#Make the variable wiimote to the first wiimote init() found
wiimote  = wiimotes.contents

#Set Leds
wiiuse_set_leds(wiimote,WIIMOTE_LED_1)

#Rumble for 1 second
wiiuse_rumble(wiimote,1)
sleep(1)
wiiuse_rumble(wiimote,0)

#Turn motion sensing on(supposedly)
wiiuse_motion_sensing(wiimote,1)

while 1:
    #Poll the wiimotes to get the status like pitch or roll
    if(wiiuse_poll(wiimote,1)):
        print 'EVENT'

And here's the output when I run it.

这是我运行它时的输出。

wiiuse version 0.9
wiiuse api version 8
[INFO] Found wiimote [assigned wiimote id 1].
EVENT
EVENT
Traceback (most recent call last):
  File "C:\Documents and Settings\Nick\Desktop\wiimotetext.py", line 26, in <mod
ule>
    if(wiiuse_poll(wiimote,1)):
WindowsError: exception: access violation reading 0x00000004

It seems each time I run it, it prints out EVENT 2-5 times until the trace back. I have no clue what to do at this point, I've been trying for the past two days to get it working.

似乎每次我运行它时,它都会打印出 EVENT 2-5 次,直到回溯。我现在不知道该怎么做,过去两天我一直在努力让它发挥作用。

Thanks!

谢谢!

回答by Tim Swast

I updated the pywiiuse wrapper. It didn't seem to be made for the latest version of wiiuse (0.12 at the time of this answer), since much of it just wouldn't work in the current iteration.

我更新了 pywiiuse 包装器。它似乎不是为最新版本的 wiiuse 制作的(这个答案时为 0.12),因为它的大部分内容在当前迭代中不起作用。

I've got the package and some example scripts posted here: http://code.google.com/p/pywiiuse/downloads/list

我在这里发布了包和一些示例脚本:http: //code.google.com/p/pywiiuse/downloads/list

You should also just be able to do

你也应该能够做到

easy_install wiiuse

Since I've also hosted it on pypi.

因为我也在 pypi 上托管了它。

回答by Kugel

I've been working with wiimotelibfor .NET and it is pretty stable. And contains also wii remote extensions like nunchcuk and other.

我一直在为 .NET使用wiimotelib,它非常稳定。并且还包含 wii 远程扩展,如 nunchcuk 和其他。

回答by mgalgs

I know your class is over by now, but for anyone else looking, cwiid is really nice. Installed in Ubuntu like so:

我知道你的课现在已经结束了,但对于其他人来说,cwiid 真的很好。像这样安装在Ubuntu中:

apt-get install libcwiimote-dev python-cwiid

Or get the latest from github.

或者从github获取最新的。

Reading wiimote sensors (like pitch from accelerometer) is super easy:

读取 wiimote 传感器(如加速度计的音高)非常容易:

import cwiid
print 'place wiimote in discoverable mode (press 1 and 2)...'
wiimote = cwiid.Wiimote()
wiimote.rpt_mode = cwiid.RPT_ACC
#wiimote.state dict now has an acc key with a three-element tuple
print 'pitch: %d' % (wiimote.state['acc'][cwiid.Y])

回答by borismus

For those still looking, I found and documented a simple easy way of pairing with the Wii Remote with python using the lightblue library. I tested it on OS X, but it should work cross platform (ie. on Linux)

对于那些仍在寻找的人,我发现并记录了一种使用 lightblue 库将 Wii Remote 与 python 配对的简单方法。我在 OS X 上测试过,但它应该可以跨平台工作(即在 Linux 上)

Here's my writeup: http://smus.com/prototyping-wii-remote-python/

这是我的文章:http://smus.com/prototyping-wii-remote-python/

回答by borismus

Been searching for a set of Python wrappers to the Wiimote for almost two days now, here's my summary of the state of the art:

近两天来一直在为 Wiimote 寻找一组 Python 包装器,这是我对现有技术的总结:

pywiimote (from Google): roughly half-finished, didn't compile when I downloaded the latest version (r52), has some nice ideas, but will require significant investment to get working.

pywiimote(来自谷歌):大约完成了一半,当我下载最新版本(r52)时没有编译,有一些不错的想法,但需要大量投资才能工作。

pywiiuse (above): nice in theory,

pywiiuse(上图):理论上很好,

cwiid: not actively developed, only for Linux (not able to compile under Cygwin).

cwiid:未积极开发,仅适用于 Linux(无法在 Cygwin 下编译)。

In summary -- there's nothing off the shelf right now (3/24/2009). Will keep surveying ...

总之——现在没有现成的东西(2009 年 3 月 24 日)。将继续调查...

--Bryan

——布莱恩

回答by borismus

Change your python version to 2.5.2 I believe it will work now

将您的 python 版本更改为 2.5.2 我相信它现在可以工作了

回答by Skeolan

pywiimoteon Google Code might be helpful, if the library you found is failing out on you... give it a try if you have the time.

Google Code 上的pywiimote可能会有所帮助,如果您发现的库在您身上失败了……如果您有时间,请尝试一下。

It seems like a pretty new offering, though, and may not be any better.

不过,这似乎是一个非常新的产品,而且可能不会更好。

Good luck!

祝你好运!

回答by Skeolan

I'll risk missing the point by suggesting you take a look at WiimoteWhiteboard Java version by Uwe Schmidt

我会建议您查看 Uwe Schmidt 的 WiimoteWhiteboard Java 版本,从而冒着错过重点的风险

http://www.uweschmidt.org/wiimote-whiteboard

http://www.uweschmidt.org/wiimote-whiteboard

It uses the WiiRemoteJ library for Java.

它使用 Java 的 WiiRemoteJ 库。

I have tried unsuccessfully in the past to use Python implementations because they were either incomplete or non-functional. Maybe by examining Schmidt's working version in Java you can determine what is missing in Python.

过去我曾尝试使用 Python 实现失败,因为它们要么不完整,要么不起作用。也许通过检查 Schmidt 在 Java 中的工作版本,您可以确定 Python 中缺少什么。

Good luck with your class.

祝你上课好运。