Jan
21
2009

FYP Technology: Accelerometer Input and Service Discovery

When I checked my email this morning I saw that Apple had activated my iPhone Developer Program account. I set up my certificate, application, device, provisioning profile, and all that other code-signing junk, and got some sample code running on my iPod.

I played around with different values on the simple low-pass filter in the GLGravity demo to see how much it would take to get a clean reading from the accelerometer without sacrificing response time and it turns out the accelerometer is pretty noisy.

Here’s the callback which does the filtering:

- (void)accelerometer:(UIAccelerometer*)accelerometer didAccelerate:(UIAcceleration*)acceleration
{
	//Use a basic low-pass filter to only keep the gravity in the accelerometer values
	accel[0] = acceleration.x * kFilteringFactor + accel[0] * (1.0 - kFilteringFactor);
	accel[1] = acceleration.y * kFilteringFactor + accel[1] * (1.0 - kFilteringFactor);
	accel[2] = acceleration.z * kFilteringFactor + accel[2] * (1.0 - kFilteringFactor);
}

kFilteringFactor is a #define and accel is defined as a class variable:

UIAccelerationValue		accel[3];

kFilteringFactor was 0.1 by default but still still seems to give some jittery output so I ended up with 0.05 being a stable value. In the demo code, this callback is being called at 100Hz. I wonder if there’s a better way of cleaning up the inputs?

I also spent a bit of time with the Bonjour SDK today and have it ready to go on win32. I need to do more playing with it before it’s ready for the iPod, but I don’t anticipate any problems. Any difficulties I have will be with the UI code, not Bonjour. So far it seems to be working really well, and when I register a service on one computer it magically pops up on another without any issues. The biggest problem I had was with the TXT record format. Here’s the example where I finally understood what was going on:

------------------------------------------------------------------- 
| 0x0A | name=value | 0x08 | paper=A4 | 0x12 | Rendezvous Is Cool | 
-------------------------------------------------------------------

What’s happening there is that each entry in the TXT record has its length written to the byte before its first character. DNSServiceRegistrationCreate() does this for you on OS X but I haven’t seen it with the Bonjour SDK. By the way, the Bonjour “SDK” is a header file, a library file, and one (poorly commented) C and one Java example.

Tomorrow I hope to play more with the iPhone SDK, with the objective of getting the iPod’s accelerometer output displayed on the PC.

Written by in: University |

No Comments »

RSS feed for comments on this post. TrackBack URL


Leave a Reply

Powered by WordPress | Theme: Aeros 2.0 by TheBuckmaker.com