Absolute position tracking using iPhone magnetometer

IMG_1918
Standard

A recent project I was working on required absolute positioning and while waiting for Valves lighthouse and Facebooks to open source it’s tracking solutions I thought I’d take a primitive stab at EM (electro magnetic) positioning using a phone magnetometer purely for the purpose of learning the challenges involved. I’m an experienced software developer and a hobbyist hardware hacker, so I tried solving most problems using software where possible .

EM tracking has an advantage over optical tracking over that it doesn’t need line of sight but most optical tracking systems have overcome this limitation by using two base stations.

All professional EM tracking solutions like products from Polhemus, Ascension and Razor Hydra all use alternating EM fields and a receiving coil to measure induced currents and this allows for turning out or filtering out everything except for the carrier frequency. The down side is the you need more complex hardware/circuits like signal generators/oscillators for the transmitter and with op-amps with high/low pass filters etc on the receiver.

So for stage one I decided to just use the magnetometer sensor on my phone and see how far I can get. As the first step I made a quick prototype using my phone, a relay switch for the transmitter coil and a 9v battery. Due to inverse square law of magnetic field propagation I was only able to get accurate readings up to a centimeter or two.

IMG_1911

Always try brute force first, I had to push as much current as possible and needed a bigger coil to create a much stronger magnetic field. First part is easy, 9v batteries are cheap and connect 4 in series and voila you have 36v.

The later is tricky while the EM field generated goes up with number of turns, the longer wire also increases the resistance which decreasing the current passing through. I ended up using a 100MH inductor with 76 Ohm which seems to be a good balance between generated EM field and resistance. This setup created a strong enough field to be detectable up to 5-6 cm which was enough for my project.

The coil would overheat quickly which can be solved by pulsing the coil only long enough for the magnetometer to register it, which turned out to be around 20ms for the one on iPhone 6. Trilateration in 3d requires three points of reference so I got three of these coils transmitting 20ms seconds at a time with the help of a ATTiny and a few MOSFETS.


IMG_1915

Due to the lack of wired open input/output ports on the iPhone and lack of wifi/bluetooth on the AtTiny I decided to use a sync cycle to figure out coil is transmitting.

Transmit pulses would be evenly spaced with a empty pulse used as a sync pulse. The rest was signal processing on the iphone, which turned out to be a lot harder than I thought it would be but creating a system to record and playback data so I can rerun and debug with exact dataset helped a lot. Also adding a real time charts and a 3d scene to the iphone app was a great way to visualise what was going on. Another good way to compare the results of two methods (eg: different noise filtering algorithms) was to record videos of each one runnng in the simulator with test data and play it back side by side.

Simulator Screen Shot 31 Aug 2016, 7.39.26 PM

Since the phone is moving all the time, which changes the earth’s magnetic field, each reading had to be normalised against the background using the interquartile_mean.

In order to identify which coil is transmitting, find the highest peak and then find 3 other transmissions equal distance from it, since the time between pulses are known constant, this will give us 4 values and the lowest one will be the sync cycle which can be used to figure out which pulse came from which coil.

GRAPH

Now the intensity at x distance from each coil can be turned into distance from coil based on inverse square law. This is finally used to trilateration and find the absolute coordinates in 3d space relative to the transmitters.

So how well does it track? The answer is not very well, but in true sprit of brute forcing with more power, I ordered some, more accurate MLX90393 magnetometers and hope to combine input from all 3 for a more accurate result and also ordered some A23 12v batteries to push the voltage up to 48v which should improving tracking around the edges.

One more video: https://youtu.be/EHWGtElzWaY

iOS app swift source code:
https://github.com/chris-gunawardena/Absolute-position-EM-tracking-using-iPhone-magnetometer

Arduino Transmitter source code:

Todo:
Just .

References:

https://hackaday.io/project/11865-3d-magnetic-field-scanner
http://rose.eu.org/2014/tag/plume
https://web.archive.org/web/20151002101421/http://home.comcast.net/~traneus/dry_model_1_isca_tracker_electronics.htm

http://www.abrazol.com/books/signals/
https://trmm.net/Lighthouse
https://en.wikipedia.org/wiki/Trilateration
https://www.engineeringforchange.org/uploads/activity/183/183/295/1311176446080/Extremely_low_frequency_electromagnetic_field_detectors_intermediate_Report.pdf
http://www.na-mic.org/Wiki/index.php/Open_Source_Electromagnetic_Trackers
https://airwebreathe.org.uk/doku.php?id=fpga_fan_controller
https://hackaday.io/project/12352-low-field-mri-continued

Planning Poker with WebGL and three.js

WebGL three.js planning poker
Standard

It’s been almost 2 years since the Planning poker mobile web app and a lot has changed in the web landscape. WebGL has become a standard in desktop and mobile browsers and there are lot of great frameworks like three.js, babylon.js and x3dom. So I decided to recreate the planning poker app using thee.js. I picked three.js mainly because it seems to be the more popular framework with more documentation and resources available online. It took me awhile to learn all the best ways of doings things and gotchas but ones I did, I was impressed by the performance and how well it worked on mobile.

You can now see the end result at http://chris-gunawardena.github.io/planning-poker/
Full source available at https://github.com/chris-gunawardena/planning-poker

Planning Poker is a estimating technique used by scrum teams to make faster and more accurate estimations using a deck of cards. Now instead of looking for a deck of cards, all you have to do is open http://chris-gunawardena.github.io/planning-poker/ on your mobile phone 🙂

Prepend commit messages with JIRA issue number from branch name

git commits
Standard

Prepending JIRA issue number to commit messages lets you link all commits to a JIRA issue. This makes it possible to view what issues are in a build in bamboo.

Copy the file below to \.git\hooks and it will automatically commit messages with the JIRA issue number from branch name.
Branch name can be anything like “JIRA-1234 some text here”.

JIRA Agile timelapse

cric-aus-jira-timelapse.mov
Standard

I was really taken up by this timelapse video of a physical scrum board, but unfortunately we had a virtual JIRA board at the time. So using CasperJS/PhantomJS/SpookyJS (headless browser screen capture), NodeJS/Heroku (backend), AngularJS/Bootstrap (fontend), imgur (image hosting) and  Uptime Robot (scheduling) I was able to whip up a poor mans timelapse for virtual JIRA boards using only free tiers of services.

Uptime Robot performs a health check on the url /api/projects/take_screenshots every 15 minutes, which is mapped to take_screenshots() function in the projects controller.  This function logs into JIRA using CasperJS, navigates to the Scrum/Kanban board and takes a screenshot.

This screenshot then gets uploaded via the imgur.com api and the returned url gets inserted back into mongoDB.

AngularJS retrieves each project with it’s captured screenshot urls to display them in a Bootstrap carousel.

TODO: Create videos from the screenshots and upload to youtube.

This is an open source project, so feel free to fork and send pull requests.

Debugging client/server requests with req.uest.info

Screen Shot 2014-12-21 at 12.55.31 pm
Standard

req.uest.info is an open source online debugging tool for capturing and displaying  requests from clients in JSON without the need for a server, built using Node, MongoDB, Express, Angular & Socket.io.

The demo http://submit-request.herokuapp.com/ is currently hosted on Heroku. Simply set your form or application submit url to http://submit-request.herokuapp.com/submit/ and view the submission data.

When a REST request is made to /submit url the node express route/handler re-transmits/pushes the data to all connected clients using socket.io emit.

This message is handled on the client side by the angular socket.io service.

On row click, the data is passed through a json syntax highlighter and displayed.

TODO: Currently requests are visible to all by default, I’m working on allowing logged in users to make private requests from a set of IP addresses. The user authenticating and IP address management is already implemented using MongoDB and passport.js. What’s left is to search for the ip address when a request arrives, then if a match is found, send the request only to the users connected client. (ip address of each logged in client will have to be stored with their socket connection).

This was a fun experiment in the MEAN stack and socket.io. Javascript and it’s developer tools (npm,bower,yeoman,jade,bootstrap,etc) are maturing fast enabling rapid development of projects like these in a few nights rather than months.

Feel free give feedback in the comments below or to submit a pull request/fork.

Automated regression testing of JIRA stories

Screen Shot 2014-05-23 at 2.44.19 am
Standard

Intro

When a story is ‘done’ and ‘on the bus’, it’s expected to stay that way until go live. When working in a large team that share a code base, it’s common to break each others stuff.

Automated regression testing has long existed in most applications but for many web sites because it’s impossible to write tests to verify if a website was being displayed correctly. Today opensource tools like Wraith, Huxley, PhantomCSS, PhotoBox etc solve this issue using screencapture comparison techneques.

What will this post help me do?

Automate website regression testing for agile teams that use JIRA. This will prevent you from committing code that can undo previously completed stories.

JIRA stories are used to add test URLs. Every team member can view them which help increase test coverage.

Continue reading

Phone-embed.info

Screen Shot 2014-05-07 at 11.33.28 pm
Standard

This started out as a quick project to interactively showcase my mobile portfolio, but turned into a project on it’s own taking a few days to complete. This allows you to embed a mobile site at any size while maintaining the scale of its contents.

You can try it now at http://chris-gunawardena.github.io/iphone-embed/

Github project page:
https://github.com/chris-gunawardena/iphone-embed

Continue reading for an example. Continue reading