如何从 Xbox 360 控制器获取输入?
我正在编写一个需要从 Xbox 360 控制器获取输入的程序。 然后输入将被无线发送到我正在建造的遥控直升机。
到目前为止,我了解到这可以使用 DirectX 中的 XInput 库或 XNA 中的输入框架来完成。
我想知道是否还有其他可用的选择。 我的程序范围相当小,并且必须安装像 DirectX 或 XNA 这样的大型游戏库似乎太过分了。 此外,我希望该程序是跨平台的,而不是特定于微软的。
有没有一种简单的轻量级方法可以使用Python之类的东西来获取控制器输入?
编辑回答一些评论:
该直升机共有 6 个螺旋桨,排列成 3 个同轴对。 基本上,它与这个非常相似,只是它会花费大约 1,000 美元而不是 15,000 美元。 它将使用 Arduino 进行板载处理,并使用 Zigbee 进行无线控制。
选择360控制器是因为它设计精良。 它非常符合人体工程学,并具有所需的所有控制输入。 对于熟悉直升机控制的人来说,左操纵杆将控制集体,右操纵杆控制俯仰和横滚,模拟触发器将控制偏航。 模拟触发器是 360 控制器的一大特色。 PS 和大多数其他人没有它们。
我有一个该项目的网页,但它仍然很稀疏。 不过,我确实计划记录整个设计,所以最终它会很有趣。
http://tricopter.googlecode.com
顺便说一句,为 googlecode 项目提供博客功能会毁掉 Google 吗?
如果可能的话,我希望 360 控制器输入程序能够在 Linux 和 Windows 上运行。 最终,我想将控制器直接连接到嵌入式微控制器板(例如 Arduino),这样我就不必通过计算机,但目前这不是一个高优先级。
I'm writing a program that needs to take input from an XBox 360 controller. The input will then be sent wirelessly to an RC Helicopter that I am building.
So far, I've learned that this can be done using either the XInput library from DirectX, or the Input framework in XNA.
I'm wondering if there are any other options available. The scope of my program is rather small, and having to install a large gaming library like DirectX or XNA seems like excessive. Further, I'd like the program to be cross platform and not Microsoft specific.
Is there a simple lightweight way I can grab the controller input with something like Python?
Edit to answer some comments:
The copter will have 6 total propellers, arranged in 3 co-axial pairs. Basically, it will be very similar to this, only it will cost about $1,000 rather than $15,000. It will use an Arduino for onboard processing, and Zigbee for wireless control.
The 360 controller was selected because it is well designed. It is very ergonomic and has all of the control inputs needed. For those familiar with helicopter controls, the left joystick will control the collective, the right joystick with control the pitch and roll, and the analog triggers will control the yaw. The analog triggers are a big feature for the 360 controller. PS and most others do not have them.
I have a webpage for the project, but it is still pretty sparse. I do plan on documenting the whole design though, so eventually it will be interesting.
http://tricopter.googlecode.com
On a side note, would it kill Google to have a blog feature for googlecode projects?
I would like the 360 controller input program to run in both Linux and Windows if possible. Eventually though, I'd like to hook the controller directly to an embedded microcontroller board (such as Arduino) so that I don't have to go through a computer, but its not a high priority at the moment.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这并不是那么困难。 正如前面提到的,您可以使用 SDL 库来读取 xbox 控制器的状态,然后您可以用它做任何您想做的事情。
有一个 SDL 教程:http://sdl.beuc.net/sdl.wiki/Handling_Joysticks 相当不错有用。
请注意,Xbox 控制器具有以下内容:
其中
即将推出的 SDL v1.3 还将支持力反馈(又名触觉)。
我认为,由于该帖子已有几年历史,您已经做了一些事情,因此这篇文章主要是为了告知未来的访问者。
It is not all that difficult. As the earlier guy mentioned, you can use the SDL libraries to read the status of the xbox controller and then you can do whatever you'd like with it.
There is a SDL tutorial: http://sdl.beuc.net/sdl.wiki/Handling_Joysticks which is fairly useful.
Note that an Xbox controller has the following:
The upcoming SDL v1.3 also will support force feedback (aka. haptic).
I assume, since this thread is several years old, you have already done something, so this post is primarily to inform future visitors.
PyGame 可以读取操纵杆,这就是 X360 控制器在 PC 上显示的内容。
PyGame can read joysticks, which is what the X360 controller shows up as on a PC.
好吧,如果你确实不想添加对 DirectX 的依赖,你可以使用旧的 Windows Joystick API——Windows Multimedia——> 平台 SDK 中的操纵杆参考。
标准的免费跨平台游戏库是 Simple DirectMedia Layer,最初是为了将 Windows 游戏移植到 Unix (Linux) 系统而编写的。 它是一个非常基本的轻量级 API,倾向于支持每个系统上的最小功能子集,并且它具有对大多数主要语言的绑定。 它具有非常基本的操纵杆和游戏手柄支持(例如,没有力反馈),但它可能足以满足您的需求。
Well, if you really don't want to add a dependency on DirectX, you can use the old Windows Joystick API -- Windows Multimedia -> Joystick Reference in the platform SDK.
The standard free cross plaform game library is Simple DirectMedia Layer, originally written to port Windows games to Unix (Linux) systems. It's a very basic, lightweight API that tends to support the minimal subset of features on each system, and it has bindings for most major languages. It has very basic joystick and gamepad support (no force feedback, for example) but it might be sufficient for your needs.
也许 Mono.Xna 库添加了 GamePad 支持,这将提供您正在寻找的跨平台功能:
http://code.google.com/p/monoxna/
就问题而言关于图书馆的重量太重,当然,对于这个选项来说,这可能是真的……但是,它可能为将来做一些漂亮的可视化提供机会。
免责声明:我不熟悉 mono xna 项目的状态,因此它可能还没有添加此功能。 但仍然是一个选择:-)
Perhaps the Mono.Xna library has added GamePad support, which would provide the cross platform functionality you were looking for:
http://code.google.com/p/monoxna/
As far as the concerns about the library being too heavy weight, sure, for this option it may be true ... however, it could open up opportunities to do some nice visualization in the future.
disclaimer: I'm not familiar with the status of the mono xna project, so it may not have added this feature yet. But still, 'tis an option :-)