<?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; project</title>
	<atom:link href="http://connorhd.co.uk/tag/project/feed/" rel="self" type="application/rss+xml" />
	<link>http://connorhd.co.uk</link>
	<description>Interesting stuff.</description>
	<lastBuildDate>Wed, 24 Mar 2010 15:53:01 +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, <a href="http://stuffthathappens.com/blog/2009/03/15/android-accelerometer/">this article</a> 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>3</slash:comments>
		</item>
		<item>
		<title>node_debug &#8211; A debugging console over HTTP</title>
		<link>http://connorhd.co.uk/2010/01/25/node_debug-a-debugging-console-over-http/</link>
		<comments>http://connorhd.co.uk/2010/01/25/node_debug-a-debugging-console-over-http/#comments</comments>
		<pubDate>Mon, 25 Jan 2010 23:40:24 +0000</pubDate>
		<dc:creator>Connorhd</dc:creator>
				<category><![CDATA[Projects]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[node.js]]></category>
		<category><![CDATA[planet compsoc]]></category>
		<category><![CDATA[project]]></category>

		<guid isPermaLink="false">http://connorhd.co.uk/?p=43</guid>
		<description><![CDATA[I&#8217;d also like to use my blog to write about a few of my personal projects. Many of these aren&#8217;t very useful and very few actually reach any usable state, however I feel node_debug is actually something quite useful.
Before reading this post you should probably know what node.js is.
node_debug allows you to evaluate statements and view their [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;d also like to use my blog to write about a few of my personal projects. Many of these aren&#8217;t very useful and very few actually reach any usable state, however I feel node_debug is actually something quite useful.</p>
<p>Before reading this post you should probably know what <a href="http://nodejs.org">node.js</a> is.</p>
<p><a href="http://github.com/Connorhd/node_debug">node_debug</a> allows you to evaluate statements and view their result (much like a <a href="http://en.wikipedia.org/wiki/Read-eval-print_loop">REPL</a>) from your favourite browser (assuming your favourite browser isn&#8217;t IE). It also allows you to browse objects if the result of your statement is an object, for example the global object in node is <code>process</code> so executing <code>process;</code> will return a browsable tree structure of the global scope.</p>
<p><a href="http://connorhd.co.uk/wp-content/uploads/2010/01/node_debug11.png"><img class="alignnone size-full wp-image-48" title="node_debug screenshot 1" src="http://connorhd.co.uk/wp-content/uploads/2010/01/node_debug11.png" alt="" width="447" height="324" /></a></p>
<p>Additionally it exports a log function that allows you to asynchronously output to any active console, for example <code>setTimeout(function () { debug.log("Hello") }, 5000);</code> will output <strong>Hello</strong> to any open consoles after 5 seconds, allowing useful debug output when using asynchronous functions.</p>
<p><a href="http://connorhd.co.uk/wp-content/uploads/2010/01/node_debug21.png"><img class="alignnone size-full wp-image-49" title="node_debug screenshot 2" src="http://connorhd.co.uk/wp-content/uploads/2010/01/node_debug21.png" alt="" width="448" height="323" /></a></p>
<p>To get started using node_debug you need to have a server running node, and to grab the latest node_debug from github. There is an example.js included to show how you would include it in your own scripts, the idea being you can simply include this in your own project in order to easily debug issues.</p>
<p>Future features I would like to add include:</p>
<ul>
<li>A debug.scope object that allows you to import other objects into the debuggers scope (currently only the global scope is available which can cause confusion due to closures in JavaScript hiding a lot of variables from the debugger).</li>
<li>debug.error/warn/info functions in line with the browser console object provided by firebug.</li>
<li>Detect disconnection from node and attempt reconnection.</li>
<li>Caching of asynchronous messages that can be shown when connecting to the console, in order to log things without having an active browser window all the time.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://connorhd.co.uk/2010/01/25/node_debug-a-debugging-console-over-http/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
