<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Connorhd &#187; accelerometer</title>
	<atom:link href="http://connorhd.co.uk/tag/accelerometer/feed/" rel="self" type="application/rss+xml" />
	<link>http://connorhd.co.uk</link>
	<description>Interesting stuff.</description>
	<lastBuildDate>Sat, 30 Mar 2013 23:35:16 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>TapeMeasure &#8211; Another Android experiment</title>
		<link>http://connorhd.co.uk/2010/03/23/tapemeasure-another-android-experiment/</link>
		<comments>http://connorhd.co.uk/2010/03/23/tapemeasure-another-android-experiment/#comments</comments>
		<pubDate>Tue, 23 Mar 2010 23:58:17 +0000</pubDate>
		<dc:creator>Connorhd</dc:creator>
				<category><![CDATA[Projects]]></category>
		<category><![CDATA[accelerometer]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[project]]></category>

		<guid isPermaLink="false">http://connorhd.co.uk/?p=158</guid>
		<description><![CDATA[I have again become interested in what you can do with Android applications. After some discussion with a housemate (who actually owns an Android, unlike me) about augmented reality applications and how they could be easily done (to some degree) if you could reasonably accurately track a phones location in a building (something that is [...]]]></description>
			<content:encoded><![CDATA[<p>I have again become interested in what you can do with Android applications. After some discussion with <a href="http://www.sinjakli.co.uk/">a housemate</a> (who actually owns an Android, unlike me) about augmented reality applications and how they could be easily done (to some degree) if you could reasonably accurately track a phones location in a building (something that is hard to do with GPS).  I wanted to see if the phones <a href="http://en.wikipedia.org/wiki/Accelerometer">accelerometer</a> could be used (at least for short distances) to work out how a phone had moved since entering a building. Rather than attempt to make an augmented reality app, I decided to go for a slightly easier project of making a tape measure, i.e. an app that could measure distance by moving the phone. Before anyone thinks this will actually be useful I should point out that this was a rather complete failure and the resulting app is fairly useless. However, the code may be useful to anyone looking at writing an Android app that uses any of the internal sensors, it would also be interesting to see if any other phones (I only tested the app on a G1) are any more successful.</p>
<p>So straight to the code, after (briefly) reading the Android documentation it seemed there was very little info about using the sensors, so I turned to Google, this article looked like what I wanted and linked to <a href="http://github.com/eburke/android_game_examples/blob/f09fa73e7012e6ae379180613d3db829fcd09a0f/GameExamples/src/com/stuffthathappens/games/Accel.java">this code</a> which is the basis of my app. So I updated the code to use the non-deprecated API, changing its functionality slightly and ended up with:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">uk.co.connorhd.android.tapemeasure</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.app.Activity</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.os.Bundle</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.hardware.Sensor</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.hardware.SensorEvent</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.hardware.SensorEventListener</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.hardware.SensorManager</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.view.View</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.view.View.OnClickListener</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.widget.Button</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.widget.TextView</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> TapeMeasure <span style="color: #000000; font-weight: bold;">extends</span> Activity <span style="color: #000000; font-weight: bold;">implements</span> SensorEventListener,
		OnClickListener <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">private</span> SensorManager sensorMgr<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> Sensor sensorAccel<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> TextView accuracyLabel<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> TextView xLabel, yLabel, zLabel<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Button</span> calibrateButton<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">float</span> moved <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">float</span> speed <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">float</span> accel <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">float</span> accelDiff <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">float</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> a<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">long</span> lastUpdate <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">float</span> curAccel <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> accelUpdates <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
	@Override
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onCreate<span style="color: #009900;">&#40;</span>Bundle savedInstanceState<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">onCreate</span><span style="color: #009900;">&#40;</span>savedInstanceState<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		setContentView<span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">layout</span>.<span style="color: #006633;">main</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		accuracyLabel <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>TextView<span style="color: #009900;">&#41;</span> findViewById<span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">accuracy_label</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		xLabel <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>TextView<span style="color: #009900;">&#41;</span> findViewById<span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">x_label</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		yLabel <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>TextView<span style="color: #009900;">&#41;</span> findViewById<span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">y_label</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		zLabel <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>TextView<span style="color: #009900;">&#41;</span> findViewById<span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">z_label</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		calibrateButton <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Button</span><span style="color: #009900;">&#41;</span> findViewById<span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">calibrate_button</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		calibrateButton.<span style="color: #006633;">setOnClickListener</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	@Override
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> onPause<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">onPause</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		sensorMgr.<span style="color: #006633;">unregisterListener</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>, sensorAccel<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		sensorMgr <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	@Override
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> onResume<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">onResume</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		sensorMgr <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>SensorManager<span style="color: #009900;">&#41;</span> getSystemService<span style="color: #009900;">&#40;</span>SENSOR_SERVICE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		sensorAccel <span style="color: #339933;">=</span> sensorMgr.<span style="color: #006633;">getSensorList</span><span style="color: #009900;">&#40;</span>Sensor.<span style="color: #006633;">TYPE_ACCELEROMETER</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">boolean</span> accelSupported <span style="color: #339933;">=</span> sensorMgr.<span style="color: #006633;">registerListener</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>, sensorAccel,
				SensorManager.<span style="color: #006633;">SENSOR_DELAY_FASTEST</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>accelSupported<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #666666; font-style: italic;">// on accelerometer on this device</span>
			sensorMgr.<span style="color: #006633;">unregisterListener</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>, sensorAccel<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			accuracyLabel.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">string</span>.<span style="color: #006633;">no_accelerometer</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onClick<span style="color: #009900;">&#40;</span><span style="color: #003399;">View</span> v<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>v <span style="color: #339933;">==</span> calibrateButton<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #666666; font-style: italic;">// Clicked button</span>
			moved <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
			speed <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
			accelDiff <span style="color: #339933;">=</span> accel<span style="color: #339933;">+</span>accelDiff<span style="color: #339933;">;</span>
			accel <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onAccuracyChanged<span style="color: #009900;">&#40;</span>Sensor sensor, <span style="color: #000066; font-weight: bold;">int</span> accuracy<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// this method is called very rarely, so we don't have to</span>
		<span style="color: #666666; font-style: italic;">// limit our updates as we do in onSensorChanged(...)</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>sensor.<span style="color: #006633;">getType</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> Sensor.<span style="color: #006633;">TYPE_ACCELEROMETER</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">switch</span> <span style="color: #009900;">&#40;</span>accuracy<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">case</span> SensorManager.<span style="color: #006633;">SENSOR_STATUS_UNRELIABLE</span><span style="color: #339933;">:</span>
				accuracyLabel.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">string</span>.<span style="color: #006633;">accuracy_unreliable</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">case</span> SensorManager.<span style="color: #006633;">SENSOR_STATUS_ACCURACY_LOW</span><span style="color: #339933;">:</span>
				accuracyLabel.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">string</span>.<span style="color: #006633;">accuracy_low</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">case</span> SensorManager.<span style="color: #006633;">SENSOR_STATUS_ACCURACY_MEDIUM</span><span style="color: #339933;">:</span>
				accuracyLabel.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">string</span>.<span style="color: #006633;">accuracy_medium</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">case</span> SensorManager.<span style="color: #006633;">SENSOR_STATUS_ACCURACY_HIGH</span><span style="color: #339933;">:</span>
				accuracyLabel.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">string</span>.<span style="color: #006633;">accuracy_high</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onSensorChanged<span style="color: #009900;">&#40;</span>SensorEvent event<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">int</span> sensorType <span style="color: #339933;">=</span> event.<span style="color: #006633;">sensor</span>.<span style="color: #006633;">getType</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>sensorType <span style="color: #339933;">==</span> Sensor.<span style="color: #006633;">TYPE_ACCELEROMETER</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			a <span style="color: #339933;">=</span> event.<span style="color: #006633;">values</span><span style="color: #339933;">;</span>
			accel <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">float</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Math</span>.<span style="color: #006633;">sqrt</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>a<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">*</span>a<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span>a<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">*</span>a<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span>a<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">*</span>a<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span>SensorManager.<span style="color: #006633;">GRAVITY_EARTH</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span>accelDiff<span style="color: #339933;">;</span>
			curAccel <span style="color: #339933;">+=</span> accel<span style="color: #339933;">;</span>
			accelUpdates<span style="color: #339933;">++;</span>
&nbsp;
			<span style="color: #000066; font-weight: bold;">long</span> curTime <span style="color: #339933;">=</span> event.<span style="color: #006633;">timestamp</span> <span style="color: #339933;">-</span> lastUpdate<span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>curTime <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">1000000000</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				curAccel <span style="color: #339933;">=</span> curAccel<span style="color: #339933;">/</span>accelUpdates<span style="color: #339933;">;</span>
				speed <span style="color: #339933;">+=</span> curAccel<span style="color: #339933;">*</span>curTime<span style="color: #339933;">*</span>10e<span style="color: #339933;">-</span>10<span style="color: #339933;">;</span>
				moved <span style="color: #339933;">+=</span> speed<span style="color: #339933;">*</span>curTime<span style="color: #339933;">*</span>10e<span style="color: #339933;">-</span>10<span style="color: #339933;">;</span>
&nbsp;
				lastUpdate <span style="color: #339933;">=</span> event.<span style="color: #006633;">timestamp</span><span style="color: #339933;">;</span>
&nbsp;
				xLabel.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span>.<span style="color: #006633;">format</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Moved: %+2.20f&quot;</span>, moved<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				yLabel.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span>.<span style="color: #006633;">format</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Speed: %+2.20f&quot;</span>, speed<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				zLabel.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span>.<span style="color: #006633;">format</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Accel: %+2.20f Time:  %+2.3f&quot;</span>, curAccel, curTime<span style="color: #339933;">*</span>10e<span style="color: #339933;">-</span>10<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				curAccel <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
				accelUpdates <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This calculates the current acceleration of the phone, subtracts gravity (which is added to the raw data), then derives the speed and distance travelled. The calibrate button resets the speed and distance, and assumes the phone is not moving, generating a bias to add to the acceleration in the case of the phones accelerometer being badly calibrated. If you want to try the app it can be downloaded and installed from <a href="http://connorhd.co.uk/files/TapeMeasure.apk">here</a>. I suggest launching the app, placing the phone on a stable surface and pressing calibrate, if you get any interesting results let me know.</p>
<p>Despite the phone reporting the accelerometer accuracy as &#8220;high&#8221; (with no description of what high means) and returning values in excess of 10 significant figures,  the acceleration data with the phone sat on a table varied in the range of about 0.5m/s^2 (although this did appear to change depending on the room I was in). This resulted in a massively wrong distance value very quickly increasing to several metres without moving the phone, making any kind of testing almost impossible. It seems the current purpose of accelerometers is to work out if some violent action (such as shaking) has happened to the phone, and not anything much more interesting. All in all a bit of a waste of time, but maybe future phones will have better sensors, and hopefully someone will find the code snippet above useful.</p>
]]></content:encoded>
			<wfw:commentRss>http://connorhd.co.uk/2010/03/23/tapemeasure-another-android-experiment/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
