开发者

Android acclerometer mouse

I am planning to develop an accelerometer b开发者_开发技巧ased mouse on the android platform. the mobile device which i plan to use is htc nexus one. the cursor should move as the mobile is moved is space. will that be difficult compard to movement wrt gravity?


this is hard to answer due to way you have phrased the question.

What is it you are wanting to use the mouse for? If you are trying to move the mouse on a computer, you will need to also create a software package that the PC can run that has the ability to set the position of the mouse.

The accelerators in phones detect, obviously, acceleration, usually in the x y and Z axis. If you lay your phone on the table, you will notice the phone is under 1g (lower all or capital case should that be?). This is actually 1g of acceleration, even though it is not accelerating you still have it. You can detect the roll of a phone by recording how the component of this 1g differs in the three axis. ie you have equal g force in the x and z axis and zero in the y, then you can 'assume' the phone is being held at a 45 degree angle.

When the sum of the components is not equal to 1g, your know your phone is actually accelerating. However, you need to know the position of your phone. Due to a delightfully painful way maths works, if you work out the differential of the differential of the acceleration of your phone (in each axis) you should have the position. The exact way you work out position from acceleration is more then I can think of in the morning, but the relation ships are fairly simple to convert to/from, if you keep a constant for them all, which you can, TIME!


Old question, but still relevant to newer hardware, so here goes...

Your biggest problem is the fact that an accelerometer alone can't tell the difference between acceleration due to motion and acceleration due to gravity and tilting. To isolate out motion, you need a second sensor. Your problem is very much like the one that people building Segway-like balancing robots face, and the solution is pretty much the same as well:

  1. A gyroscope. I believe the Samsung Galaxy S phones have gyros, but I'm not sure whether they're "real" MEMS gyros, or just simulated somehow in a way that might not be up to the task.

  2. The camera. This is an untested theory of mine, but if you could somehow either reflect enough light off the desk with the flash (on phones with LED flash), or perhaps used a mousepad with some glow-in-the-dark pattern, and you could force the camera to do low-res videocapture when it knows it's out of focus, you could probably do pattern-recognition on the blurry unfocused blobs well enough to determine whether the phone is moving or stationary, and possibly get some sense of velocity and/or direction. Combine the low-quality data from the realtime blurry camera video stream with the relatively high-res data from the accelerometers, and you might have something that works.

However, before you even bother with 1 or 2, make sure you're ready to tackle the bigger problem: emulation of a HID bluetooth mouse. It's possible (but might require a rooted phone), and at least one app in Android Market does it, but it's not a trivial task. You aren't going to solve THIS problem in an afternoon, and you should probably try to solve it at least well enough to emulate a fake mouse and convincingly pair it to a computer expecting a real bluetooth mouse before you even bother with the accelerometer problem. Both are high-risk, so don't try to completely finish one task before starting the other, but don't spend too much time on either until you've got a fairly good grip on the problem's scope and know what you're getting into.

There IS an alternative, if bluetooth HID is too much... there are quite a few open source projects that involve skipping bluetooth HID, and just using it as a serial port communicating with a server running on the PC (or tethered directly via usb with ADB). AFAIK, none of them have particularly good phone-as-mouse capabilities, unless you consider using the phone as a touchpad to be "mouse".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜