Thursday, July 2, 2009

Sensor Graph + OpenGL ES

I am starting work on a simple app called Sensor Graph that will be able to graph and log sensor data to a text file(there is a tricorder and API demo apps that draw graphs of the sensors, but none that can log data as far I have found). This will be useful for analysis of the sensitivity of the sensors and to model things like the possiblity of using the accelerometer for dead reckoning. My current idea is to set up a track that I can slide the phone back and forth on and then see how accurately I can compute the position from the acceleration data. If 1d works good then I will test out moving the phone in 2d with no rotation. It will also be able to analyze how quickly the magnetometer reacts to changes in orientation. Most of the existing compass apps have the output filtered to reduce noise so they react slower than should be possible.

Since my game will be opengl I am making the Sensor Graph in opengl as well. With the abundance of simple API examples and GLSurfaceView getting it up and running has been easy. However the lack of an immediate mode in OpenGL ES is holding me up for now. I haven't found any examples programs doing dynamic generation of geometry, so I am trying a bunch of different things now trying to get something to show up on the screen, not sure why it's not working yet.

Sunday, June 28, 2009

Testing the GPS

The quality of the built in GPS receiver in the G1 has been kind of a let down. This past weekend I was helping pick up trash along a highway and decided to leave My Tracks going while walking up and down the highway. The first complaint was the time to fix, it seemed like something around 3 minutes(definetely worse than the 75 seconds in the spec) , on a perfectly clear day while standing out in the open. Using the GPS Status 2 app it would report 6 satellites quickly but still take forever to get an actual location fix.

The second issue was the quality of the GPS signal after I put the phone in my pocket, the location would somtimes jump around 5-10 meters at a time. This is fine for just locating yourself on a street, but when walking up and down a road it makes the distance measured meaningless. It really doesn't hold a candle to a dedicated SIRFStar 3 USB GPS unit. Although it would do better if it had been mounted with a fixed view of the sky rather than in my pocket. I'm not sure if the hard plastic shell I put on the phone cuts down on GPS reception or not.

Tuesday, June 23, 2009

Got a phone!

With the announcement that the MT3G wouldn't be available until the beginning of august it really didn't make sense to wait for it and still try to make something for the ADC, so I went ahead and got a G1 yesterday. It's not nearly as clunky as I had imagined for some reason. So far the best app I have played with is the google sky map

The first app I plan on making will be called SensorGraph, which will allow you to log/graph a sensor's values over time and either just display them or write them out to a file on the sd card for later analysis. There are a few apps already that will show a graph of values but not do exactly what I need. With this app I will better be able to analyze how good the magnetometer reacts to see if it will work for my game idea.

Friday, June 19, 2009

Calculating orientation

After looking at the API the getRotationMatrix method is really simple, it just assumes the acceleratometer data indicates down(only precisely true when you aren't moving it at all) and then the cross product of down and the geomagnetic reading gives you a vector pointing east. Another cross prouct between down and easy gives you a vector pointing north. Normalize them and then they make up the rotation matrix.

Typically aligning one coordinate system to another by a rotation to just match a unit vector means there are an infinite number of possible rotations. IE you could spin the coordinate system about that vector and any rotation would satisfy the constraints. But for my game I can add the constraint that they are holding the phone in landscape view and not rotating it, so rotation around the Z axis is 0, and I only need to find rotation around Y and Z to calculate the orientation.

So the equation representing the rotation of the device is M' = Rx * Ry * M, where M' is the measured magnetic field in the coordinate frame of the device and M is the reference magnetic field given by the WMM.

Expanding this out yields(where sx,cx,sy,cy are sin(x), cos(x)...):

[M'x] [cy, 0, -sy] [Mx]
[M'y]=[sx*sy, cx, sx*cy]*[My]
[M'z] [cx*sy,-sx, cx*cy] [Mz]

[M'x] [Mx*cy - Mz*sy]
[M'y]=[My*cx + (Mz*cy + Mx*sy)*sx]
[M'z] [(Mz*cy + Mx*sy)*cx - My*sx]

Using some handy trig identities you can use the M'x line to solve for y and then substitute that in either of the other two equations to solve for x. ie for y it would be

y = asin(-M'x/sqrt(Mz^2+Mx^2)) + atan(Mx/Mz)

A = (Mz*cy + Mx*sy)
x = asin(M'y/sqrt(A^2+My^2)) - atan(My/A)

Although this method requires 2 asin and 1 atan calculations, so I'm not sure how fast/stable this approach will be.

Wednesday, June 17, 2009


While waiting for the myTouch to come out I have been researching the magnetometer in the G1. I haven't been able to find any information on people who have done tests on how fast/accurate it is. The only examples I have seen are the augmented reality browsers that most likely simply use the SENSOR_ORIENTATION.

For the purposes of the game I have in mind depending on the accelerometer to help calculate the orientation of the phone won't really work if the user is moving the phone around quickly while playing. So the basic problem is simply to find the rotation that aligns the magnetometer data with what the magnetic field at that location should be ( calculated by ).

Right now I'm trying to figure out how exactly the getRotationMatrix method in the SensorManager class works, it uses the magnetometer and accelerometer data to produce the orientation without even needing the WMM data;a=blob;f=core/java/android/hardware/

Sunday, June 14, 2009

Starting a new project

Hello, this blog will chronicle my adventures in learning and making Android applications. Currently I've just been playing with the 1.5 SDK and I'm waiting for the Tmobile myTouch 3g(G2/HTC Magic/Google Ion) to be released before picking one up. Hopefully it will come out in time for me to get something together for the Android Developer Challenge.

My main interest is in developing games and using the accelerometer/compass for interesting things, but I can't really play around with those until I get an android phone to experiment on. When I do I will work on testing out some dead reckoning ideas using the sensors.

I've read over some of Professional Android Application Development and just ordered Unlocking Android, I will post up a review of each after I finish going over them.