Intoduction
As all we know there is no support for accelerometer in Windows Phone 7 Emulator. Of course there are projects which are using some hardware such as Wii or XBox 360 controller to emulate mobile device movement. They have one weak point – they needs hardware. Some day, when I had more free time I decided do find some solution for this. After couple of hours I have found one and this is it… I want you to introduce MaciejGrabek.WP7AccelerometerEmulator.
How it works?
Solution consists of three projects:
1. MaciejGrabek.WP7Accelerometer – which is core library to use in your projects. It contains WP7AccelerometerProvider class which provides all functionality given by real Accelerometer from Microsoft.Devices.Sensors ie Start and Stop methods and ReadingChanged event which provides information about gravity for each axis.
2. MaciejGrabek.WP7AccelerometerEmulatorUI – this project allows you to emulate position of phone by simple use of three scrolls for X, Y and Z rotation. It sends all required data to Proxy.
3. MaciejGrabek.WP7AccelerometerEmulatorProxy – this proxy is used to receive data from UI and allows to read it from WP7AccelerometerProvider.
If you running your application on emulator then WP7AccelerometerProvider is trying to read data from Proxy – if something goes wrong on retrieving this data (ex proxy is unavailable) it simply switches into random data mode. You can retry receiving by Stop and Start methods.
How to use it?
It is very simple – like using real accelerometer.
When you create WP7 application first thing what you need to do is adding reference to MaciejGrabek.WP7Accelerometer library (or project). Then create accelerometer object like below:
1 | var acc = new WP7AccelerometerProvider(); |
Now simply add handling to AccelerometerProviderReadingChanged event:
1 2 3 4 5 6 7 | acc.ReadingChanged += OnAccelerometerProviderReadingChanged; private void OnAccelerometerProviderReadingChanged(object sender, WP7AccelerometerReadingEventArgs args) { //do what you want with data ProcessAccelerometerData(args.X, args.Y, args.Z, args.Timestamp); } |
Start WP7AccelerometerProvider and do what you want with received data.
1 2 3 4 5 6 7 8 | try { acc.Start(); } catch (Exception exc) { txtblk.Text = exc.Message; } |
This is all you need to do in application. Now lets see control panel. To do this you need to start MaciejGrabek.WP7AccelerometerEmulatorUI and MaciejGrabek.WP7AccelerometerEmulatorProxy (it should start automatically with MaciejGrabek.WP7AccelerometerEmulatorUI, but if not be sure to do this manually – otherwise you will get random data). Run your WP7 application on emulator and on MaciejGrabek.WP7AccelerometerEmulatorUI mark “Send data to emulator” checkbox and have fun! Result is shown below:
As you can see it is very simple and intuitive to use.
Where to find it?
You can simply download MaciejGrabek.WP7AccelerometerEmulator and use it in your projects. There is of course some demo to see exactly how to use it.
What will appear in future versions?
1. Sometimes You can see Gimbal Lock effect – I am currently trying to solve it
2. Add mouse control for rotation
3. Add movement sequences (you can record movement like shaking, rolling etc, save it, and quick run every time you need)
4. Add additional acceleration for movement (shake etc)
Fell free to comment!
good work, i was thinking about developing something like this. today have seen your article on CodeProject thumbs up will help a good amount of devs.
I’m glad that you liked it
I hope it will help.
[…] This post was mentioned on Twitter by T-Rex. T-Rex said: То что все так хотели, но не знали где взять: Эмулятор акселерометра для эмулятора Windows Phone 7
http://bit.ly/eLrTms #dev #mobile #wp7 […]
[…] http://maciejgrabek.com/projekty/windows-phone-7-accelerometer-emulator-en Emulador de Acelerometro […]
Hey guys,
I recently saw a publication about the use of accelerometers on geology for iphones.
Some of you guys should develop an app like this for WP7
I have checked compass support in WP7 API, but currently there is no such thing (there is Direction but it is fake) :(. I hope they will change it in next release.
It is not working for me.
I am getting random data.
I have also checked the “send data to emulator”.
Can you tell me what I am doing wrong?
Hi!
Please check URL of proxy. Default URL is http://localhost:9876/AccelerometerEmulatorProxy.svc – (Project MaciejGrabek.WP7Accelerometer -> WP7AccelerometerProvider.cs line 31). If you want to change it you can use optional parameter of WP7AccelerometerProvider constructor. Be sure that proxy is running when you are debugging app on emulator.
Quoted by:
http://ch3cooh.jp/index.php/tips/windowsphone7/emulator/accelerometer-simulator-kit/
and
http://d.hatena.ne.jp/ch3cooh393/20110430/1304193974
[…] 4. Use Maciej Grabek’s accelerometer plugin for the emulator. The Code Project, Original source […]
[…] Use Maciej Grabek’s accelerometer plugin for the emulator. The Code Project, Original source […]
hi, i am devloping a speedometer using windows phone accelerometer. my first aim is to get speed on one fixed axis say for e.g. y. But later I plan to change it to all axis. At the moment I plan to take around 50 samples (y axis G valuesfrom accelrometer) and find an average and then convert it to meter/second or km/hour. I know it is not easy comapred to the noise and other factors. Is there some help avilable on this direction. Thanks in advance.
Hi!
I’m not sure if accelerometer is good way to create something that calculates speed. Of course it can be calculated using easy equation, but here this acceleration is not constant so calculations are not exact… Maybe you are thinking about something like this app? In this app your idea is perfect (in my app I’m using over 100 last reads from accelerometer).
I used to be more than happy to seek out this internet-site.I wished to thanks for your time for this wonderful read!! I undoubtedly having fun with every little little bit of it and I have you bookmarked to check out new stuff you blog post.
Thanks for the auspicious writeup. It in fact used to be a leisure
account it. Glance advanced to more introduced agreeable from you!
By the way, how can we communicate?
See contact page
Pretty nice post. I just stumbled upon your blog and wished to say that
I’ve really enjoyed browsing your blog posts. After all I’ll be
subscribing to your feed and I hope you write again very soon!
I’ve been surfing online more than 4 hours today, yet I never found any interesting article like yours. It is pretty worth enough for me. In my view, if all web owners and bloggers made good content as you did, the net will be much more useful than ever before.
my webpage: Rocco
I got this web page from my buddy who shared with me concerning this site and now this
time I am visiting this web page and reading very informative posts at this time.
Hey! Someone in my Facebook group shared this website with us so I
came to take a look. I’m definitely enjoying the information. I’m
book-marking and will be tweeting this to
my followers! Excellent blog and superb design.