My favorites | Sign in
Project Logo
                
Search
for
Updated Sep 28, 2008 by otto.chrons
Home  
Home of Accelerometer Simulator

Introduction

Accelerometer Simulator is an iPhone/iPod Touch application that transfers accelerometer data from the device to your computer using UDP protocol.

Use cases

The main use case for the application is to allow iPhone application developers to create applications that require accelerometer, without having to do all the debugging on the actual device. By inserting two files into their project, they can use the Accelerometer Simulator to provide accelerometer data to their application when debugging on the iPhone simulator.

Second use case is to use your iPhone accelerometer to control something else on another device (such as your MacBook or PC).

Finally you can use the receiver part and write your own data generation application to, for example, execute predefined accelerometer datasets on your application.

Usage

  1. Check-out a copy of the source into your XCode development environment
  2. Open the AccSim.xcodeproj project file
  3. Make changes to Info.plist bundle identifier to match your development certificate. This step is required to install the application on your own iPhone/iPod touch device
  4. Build the application, targeting iPhone device
  5. Run the application on the device.

The application has two views: Accelerometer and Network. The Accelerometer view looks like this

Here you can switch between the actual sensor and manual operation modes. The sliders show the current accelerometer values. In the manual mode you can slide these yourself, generating accelerometer data manually. Note that in the manual mode you can generate data that would not be possible to generate with the HW sensor.

In the second view (tap the bottom tap bar to activate) you can configure network settings.

When the application starts, network is set to OFF and no data is being sent. Switching it to ON opens the gates and the application begins sending UDP packets to the network. By feault it uses broadcast mode, which means that all devices in the same network (such as your WLAN) will receive the packets. In case you plan to run multiple simulators in the same network, you should switch to unicast mode and specify the target IP address manually. You may also change the port to something else if you wish (remember to change it on the receiving end as well).

Now that AccSim is sending accelerometer data, it's time to setup someone receiving it.

Embedding into your application

To embed Accelerometer Simulator capabilities into your own application, simply add the AccelerometerSimulation.h and AccelerometerSimulation.m files from the Simulator classes directory into your project. Then in the source file where you configure UIAccelerometer, simply add

#import "AccelerometerSimulation.h"

This will override the default behaviour of UIAccelerometer when run on the iPhone simulator. When building for device, nothing is changed in your application.

After compiling and running your application on the simulator, it should now be receiving accelerometer data from the AccSim application running on your device.

Should you need to use a different UDP port, you have to edit the AccelerometerSimulaton.m file and change the line

#define kAccelerometerSimulationPort 10552

Other usages

If you want to use the AccSim application for other purposes, check out the testaccsim.py Python-example. It prints out the messages sent by AccSim. The format of messages is following:

ACC: <deviceid>,<timestamp>,<x>,<y>,<z>

The deviceid is the unique device id of iPhone, used to identify different sources if there are many (think of a crowd of iPhone users controlling a single game on a big screen...) Next is timestamp and acceleration values for x,y and z. These are derived directly from UIAcceleration.


Comment by heltena, Dec 05, 2008

Hello,

Please, can you put this app in the apple store?

Comment by karanvasudeva, Dec 29, 2008

It'd be great to have this in the app store!

Comment by karanvasudeva, Jan 06, 2009

Hey,

Thanks for sharing your code! I hooked this up to my macbook's internal accelerometer (using UniMotion?):

http://ifiddling.blogspot.com/2009/01/dummy2.html

Best, Karan

Comment by dumitrescu, Jan 09, 2009

This is way too cool! I can finally provide decent looking movies for my accelerometer based games! Thanks a bunch, man!

Comment by stefeo, Jan 10, 2009

Thanks for sharing! Is anyone aware of an equivalent for multitouch, sending touches from the device to the simulator? (I need more than the pinch and drag that are available on the simulator)

Comment by desaro, Feb 17, 2009

I made a TCP client that handles accelerometer and multi-touch. The only problem is that it is designed to work with SIO2, so it would need a bit of tweaking to work for general programs.

Comment by tom.w.elliott, Mar 11, 2009

This is fantastic! Thanks for sharing such a useful tool, I had it all hooked up and running on my apps within a few minutes.

Comment by mgrinich, Mar 16, 2009

Does anybody know why this stops streaming when the iPhone goes into "sleep" mode? Even if it's setup to run in the background via jailbreaking, the data still stops.

Comment by David.Aaron.Katz, Mar 19, 2009

I am having an issue with the timestamps coming over to the python script. When I average them, I am getting a 10% reduction on the frequency of the accelerometer update that is coded in. Also, it occasionally will lose a record.

Comment by alex.sherwin, Apr 20, 2009

Is this not working anymore?

I'm using iPhone SDK 3.1.2, iPhone Simulator running iPhone OS 2.2.1

I've got the AccSim? application running on an iPhone 3G and iPod Touch 16GB 1st Gen just fine, and included the simulator .h and .m files in my project(s) just fine, and I can see the "getAccelerometer" function get called by placing a NSLog statement there in the simulator, but the delegate never makes any callbacks in the simulator at all

Switching to the device(s) works just fine...

Comment by litzomatic, May 22, 2009

Works great! Thanks for the code.

Comment by solaja, May 23, 2009

Nice and easy, worked the very first time. Thanks a bunch. As others have pointed out, the only logical extension to this project is to add touchesBegin/touchesEnd support, then it'll be perfect. Also, the ability to save network preferences would be nice. But hey, it's open source, so I might contribute these changes if I ever put them in myself.

Thanks alot. Beers on me.

Comment by sfl...@gmail.com, Jun 14, 2009

Very clever, here some suggestions how it could evolve even better (if only apple picked up): http://fraggle.squarespace.com/blog/2009/6/14/doing-game-using-accelerometer-on-the-iphone-dont-miss-that.html

Comment by paperprototype, Jul 10, 2009

Thank you very much. I think that this is going to prove a life saver for me.

Comment by jeremypjoseph, Aug 13, 2009

Anyone know how many bytes are in each portion of the message. ie. it sends a 76 byte array across udp and it's split into those 5 messages. id, timestamp, x,y,z

how many bytes make up each portion?

Also anyone made a windows server for accepting this? I'm working on that now in c#.

Comment by jberghoff, Sep 08, 2009

Has anybody been able to get this to work with PhoneGap?? I'm not having any luck. Thanks.

Comment by baggyrabbit, Oct 24, 2009

I'm just wondering how exactly i download this. I've followed the link etc. but it doesn't take me to any sort of page... Is the link dead? Is it actually possible to download this?


Sign in to add a comment
Hosted by Google Code