You are on page 1of 30

Android Sensors

by
Stefan Varga, Michal Kostic
touchqode.com
jsug.at
University of Technology Vienna
October 25
th
2010
hy sensors!
2
"
#
A$$lications

%esi&ing screen ' tilt

(nviron)ent ad*+st)ent of a$$s, +ser co)fort


Ad*+st)ent in cine)a, $rediction of )ove)ent

,a)ing

A%

A% ,a)ing

A% -avigation

.ar codes

,eo / tagging, grafitti, reco)endations00

-et1or2 of ob*ects, locations and $eo$le, "3 social

,iant distrib+ted sensor syste)


-oise )a$$ing

00 And anything yo+ can i)agine4


5
5resentation O+tline
10 6ntrod+ction 7 A56
20 Si)$le sensors
"0 5osition
#0 8a)era
50 Abo+t +s / to+ch9ode0co)
:
Operating
System
2Q10
Units
2Q10 Market
Share (!
Sy)bian 25,";:0; #102
%6M .lac2.erry 11,22;0; 1;02
Android 10,:0:01 1<02
iOS ;,<#"00 1#02
Microsoft
indo1s Mobile
",0=:0# 500
<
Android "
rd
in sales
So+rce> htt$>''1110gartner0co)'it'$age0*s$!id?1#2101"
Overvie1 of android $hones
;
fro) 1eb so+rces @ )ight not be co)$lete, $l+s so)e brands have several versions of their $hones 1ith different h1 set+$sA
A56 B60C

5ac2age> android0hard1are

8lasses>

SensorManager / android service

Sensor / s$ecific sensor

Sensor(vent / s$ecific event of the sensor ? data


=
A56 / eDa)$le set+$
$+blic class MainActivity eDtends Activity i)$le)ents Sensor"#ent$istener E
00
$rivate SensorManager s) ? n+llF
4
$+blic void on8reateB.+ndle saved6nstanceStateC E
00
sm % (SensorManager! getSystemSer#ice(S"&SO'(S"')*+"!,
G
$rotected void on%es+)eBC E
00
HistISensorJ ty$edSensors ? sm.getSensor$ist(Sensor.-./"($*01-!,
'' also> TK5(LAHH
if Bty$edSensors ?? n+ll MM ty$edSensors0si&eBC I? 0C 4 error4
sm.register$istener(this2 typedSensors.get(0!2
SensorManager.S"&SO'(3"$4.(04M"!,
'' %ates> S(-SO%L3(HAKLNAST(ST, S(-SO%L3(HAKL,AM(,
'' S(-SO%L3(HAKL-O%MAH, S(-SO%L3(HAKLU6
G
G
10
A56 / eDa)$le $rocessing event
$+blic class MainActivity eDtends Activity i)$le)ents Sensor"#ent$istener E
00
$rivate float c+rrentVal+eF
$rivate long lastU$dateF
4
$+blic void onSensor8hangedBSensor"#ent e#entC E
current)a5ue % e#ent.#a5ues607,
lastU$date ? event0ti)esta)$F
G
00
G
6t is reco))ended not to +$date U6 directlyA
11
A56 / eDa)$le clean+$
$+blic class MainActivity eDtends Activity i)$le)ents Sensor"#ent$istener E
4
$rotected void on5a+seBC E
4
sm.unregister$istener(this!,
G
4
$rotected void onSto$BC E
4
sm.unregister$istener(this!,
G
00
G
12
Hight sensor

Sensor0TK5(LH6,OT

val+esP0Q ? a)bient light level in S6 l+D +nits

SensorManagerRs constants

H6,OTL8HOU3K> 100

H6,OTLNUHHMOO-> 0025

H6,OTL-OLMOO-> 00001

H6,OTLOV(%8AST> 1000000 Bclo+dyC

H6,OTLSOA3(> 2000000

H6,OTLSU-H6,OT> 11000000

H6,OTLSU-H6,OTLMAS> 12000000

H6,OTLSU-%6S(> #0000
1"
5roDi)ity sensor

Sensor0TK5(L5%OS6M6TK

val+esP0Q> 5roDi)ity sensor distance )eas+red


in centi)eters Bso)eti)es binary near@farC
1#
Te)$erat+re sensor

Sensor0TK5(LT(M5(%ATU%(

val+esP0Q ? te)$erat+re
15
5ress+re sensor

Sensor0TK5(L5%(SSU%(

val+esP0Q ? $ress+re

no constants
1:
5osition sensors
1<
Magnetic sensor

Sensor0TK5(LMA,-(T68LN6(H3

val+esP"Q ? in )icro@Tesla B+TC, )agnetic field


in the S, K and T aDis

SensorManagerRs constants

MA,-(T68LN6(H3L(A%TOLMAS> :000

MA,-(T68LN6(H3L(A%TOLM6-> "000
1;
Accelero)eter sensor

TK5(LA88(H(%OM(T(%

Val+esP"Q ? )'sU2, )eas+re the acceleration


a$$lied to the $hone )in+s the force of
gravity BD, y, &C

,%AV6TKL(A%TO, ,%AV6TKLVU56T(%,
,%AV6TKLMA%S, ,%AV6TKLM(%8U%K,
,%AV6TKLMOO-, ,%AV6TKL-(5TU-(
1=
Orientation sensor

TK5(LO%6(-TAT6O-

3e$recated

B+se getOrientation BfloatPQ %, floatPQ res+ltCC

Val+esP"Q / BA&i)+th, 5itch, %ollC / angles 0@":0

a&i)+th, rotation aro+nd the T aDis

$itch, rotation aro+nd the S aDis

roll, rotation aro+nd the K aDis

3ifferent fro) $lane ya1, $itch, roll


Bdifferent aDes and cloc21ise@nessC
20
,yrosco$e sensor

TK5(L,K%OS8O5(

Meas+re the orientation of a device

3etect all rotations, b+t only fe1 $hones have it

Val+esPQ / i5hone gives radians'sec0, and )a2es it $ossible to get


the rotation )atriD
21
Accelero)eter vs0 ,yrosco$e

Accelero)eter

senses linear )ove)ent, b+t 1orse rotations, good for tilt


detection,

3oes not 2no1 difference bet1een gravity and linear


)ove)ent, sha2ing, *itter can be filtered o+t, b+t the
delay is added

,yrosco$e

)eas+re all ty$es of rotation

not )ove)ent

does not a)$lify hand *itter

A7, ? both rotation and )ove)ent trac2ing $ossible


22
Oo1 to +se the data / the )aths

SensorManager0get%otationMatriDB
)atriD%, )atriD6,
)atriDAccelero)eter, )atriDMagneticCF

)atriD% / rotation )atriD %

device coordinates @J 1orldWs coordinates

%
t
? %
@1

)atriD6 @ inclination )atriD 6

rotation aro+nd the S aDis

get6nclination B6C / co)$+tes geo)agnetic inclination


angle in radians
2"
Oo1 to +se the data / eDa)$le
floatPQ )atriD% ? ne1 floatP=QF
floatPQ )atriD6 ? ne1 floatP=QF
SensorManager.get'otationMatri8(
matri8'2 matri8*2
matri84cce5erometer2 matri8Magnetic!,
floatPQ loo2ing3ir ? MyMath"30)atriDM+lti$lyB)atriD%,
ne1 floatPQ E000f, 000f, @100fG, "CF
floatPQ to$3ir ? MyMath"30)atriDM+lti$lyB)atriD%,
ne1 floatPQ E100f, 000f, 000fG, "CF
,HU0gl+Hoo2AtBgl,
00#f X loo2ing3irP0Q, 00#f X loo2ing3irP1Q, 00#f X loo2ing3irP2Q,
loo2ing3irP0Q, loo2ing3irP1Q, loo2ing3irP2Q,
to$3irP0Q, to$3irP1Q, to$3irP2QCF
2#
O$en ,H

The rotation )atriD can be +sed 1ith o$en ,H

3irectly load into g5$oadMatri89(95oat672 int!

ith so)e co)$+tations g5u$ook4t(..!


25
S$ecial cases

UneD$ected res+lts

free fall

north $ole

acceleration

other so+rces of )agnetic field $resent


2:
Accelero)eter noise @ si)$le
const float 2NilteringNactor ? 001fF ''$lay 1ith this val+e +ntil satisfied
float accelP"QF '' $revio+s iteration
''acceleration0D,0y,0& is the in$+t fro) the sensor
accelP0Q ? acceleration0D X 2NilteringNactor 7 accelP0Q X B100f @ 2NilteringNactorCF
accelP1Q ? acceleration0y X 2NilteringNactor 7 accelP1Q X B100f @ 2NilteringNactorCF
accelP2Q ? acceleration0& X 2NilteringNactor 7 accelP2Q X B100f @ 2NilteringNactorCF
res+lt0D ? acceleration0D @ accelP0QF
res+lt0y ? acceleration0y @ accelP1QF
res+lt0& ? acceleration0& @ accelP2QF
%et+rn res+ltF
2<
Accelero)eter noise @ notes

6f it is too slo1 to ada$t to s+dden change in


$osition, do )ore ra$id changes 1hen
angleBaccel, accelerationC is bigger

Ko+ can thro1 a1ay single val+es that are 1ay


o+t of average0

The MaccM does not have to e9+al MgM A

Kala)an filters / too co)$licated!


2;
8alibration

5hone laying on the table rarely gives P0, 0, @1Q


on accelero)eter

Adding negative vectors is not the right idea

Usef+l sol+tion is the +se of rotation )atriD


2=
A$$s to $lay 1ith

Any co)$ass a$$

6 li2e the YMarine 8o)$assZ

Sensor reading a$$s

6tRs si)$le / )a2e yo+r o1n

So)e are at androidsensors0co)


"0

You might also like