sensors on android

26
Sensors on Android ChinmayVS @ DroidCON-2011

Upload: chinmay-v-s

Post on 19-May-2015

20.706 views

Category:

Technology


1 download

DESCRIPTION

A brief introduction to Sensor-Framework on Android. Introduction to sensor hardware: - Accelerometer - Gyroscope - Compass - Light/proximity sensor Control & Data-flow from the h/w Kernel Userspace. How-To: Harness the power of sensors in your Android-application. Provide uniform UX across multiple devices when developing sensor-based Apps. Implement Sensor-fusion in your Android-app. Reduce power consumption of sensors h/w.

TRANSCRIPT

Page 1: Sensors on android

Sensors on Android

ChinmayVS @ DroidCON-2011

Page 2: Sensors on android

cvs@droidcon$ who am i

• Android >2yrs. Remember anyone?

Sensors on Android 2

• - sensors development. 10million+ units sold.

• Presently working @

PathPartnerTech.com

10:16 PM

Page 3: Sensors on android

Sensors on Android

3Sensors on Android

PART1 : Introduction• Sensors on Android

• Famous sensor apps

• Sensors in Android apps

• Sensor Hardware intro

PART2 : Android Sensor Overview• Overview

• Porting a new sensor onto Android

• Kernel

• Sensor "HAL"

PART3 : Porting tips and tricks• No motion ≠ 0accel

• Accel axes 3step calibration

• Input devices & events (EV_ABS, EV_REL)

PART4: Sensor Application development.Sample android app (code snippets)

PART5: App-dev Tips and tricks• Sensor callibration.

1. one-turn deserves another (axes-calib) 2. zero-calib

• Sensor fusion (hard-way)

• Invensense (easy-way)

• Polling rate game/ui/fastest

• When to place Wakelocks

• When to register/unregister eventListener

10:20 PM

Page 4: Sensors on android

“Sense-ors” on Android

1. ACCELEROMETER

2. GYROSCOPE

3. MAGNETIC_FIELD

4. LIGHT

5. PRESSURE

6. AMBIENT_TEMP

7. RELATIVE_HUMIDITY

8. PROXIMITY

9. LINEAR_ACCELERATION

10. GRAVITY

11. ROTATION_VECTOR

12. TEMPERATURE

13. ORIENTATION

Sensors on Android 4

VIRTUAL

REAL

DEPRECEATED

A sensor (also called detector) is a device that measuresa physical quantity and converts it into a signal which can be read by

an observer or by an instrument.

10:20 PM

Page 5: Sensors on android

“Famous” sensor apps

Sensors on Android 510:16 PM

Page 6: Sensors on android

Sensors in Android applications

• Use-cases of sensors in apps:1. Active-Input

2. Passive-Input

3. Active-Passive

4. Auto-Rotate

Sensors on Android 6

Application developer

Android window manager

10:16 PM

Page 7: Sensors on android

Sensors in Android applications (1/4)

Sensors on Android 7

• Active input

10:16 PM

Page 8: Sensors on android

Sensors in Android applications (2/4)

• Passive input

Sensors on Android 810:16 PM

Page 9: Sensors on android

Sensors in Android applications (3/4)

• Active-passive

Sensors on Android 910:16 PM

Page 10: Sensors on android

Sensors in Android applications (4/4)

• Auto-rotate

Sensors on Android 1010:16 PM

Page 11: Sensors on android

Sensor Hardware Intro (1/4)

• Accelerometer

Sensors on Android 11

+ ZERO drift- Relatively slower response

10:16 PM

Page 12: Sensors on android

Sensor Hardware Intro (2/4)

• Gyroscope (MEMS)

Sensors on Android 12

+ Extremely quick response- Gradual drift with time

10:16 PM

Page 13: Sensors on android

Sensor Hardware Intro (3/4)

• Compass (Magnetometer)

Sensors on Android 13

+ Obtain Yaw/Azimuth+ Rotation with the device on a flat surface- Picks-up surrounding magnetic noise

10:16 PM

Page 14: Sensors on android

Sensor Hardware Intro (4/4)

• Light & Proximity

Sensors on Android 1410:16 PM

Page 15: Sensors on android

Android Sensors Frameworks Overview

Android App

• Use SensorManager & SensorEventListener

Android Framework

• SensorService & SensorManager

Android sensor “HAL”

• Links the Kernel-Drivers to the framework

Kernel Drivers

• Device drivers to control and gather data from the actual hardware.

Sensors on Android 15

C

O

N

T

R

O

L

D

A

T

A

10:16 PM

Page 16: Sensors on android

Porting a sensor onto Android

Kernel Device-driver

Board File

Userspace Adding New HAL

-OR-

Modifying existing HAL

Sensors on Android 16

Q. My board has XYZ sensor. How do I get Android to recognise it?

10:16 PM

Page 17: Sensors on android

Porting a sensor onto Android (kernel)

Device-driver Poll/Interrupt? Hybrid-approach = Workqueues

Early-suspend hook

input_report_abs() / input_report_rel()

Board File Interrupt, GPIO, SPI/I2C-lines

Axes-remap to device axes platform_data

Sensors on Android 1712:15 AM

Page 18: Sensors on android

Porting a sensor onto Android (kernel)

12:09 AM Sensors on Android 18

Workqueues

Page 19: Sensors on android

Porting a sensor onto Android (kernel)

Early-Suspend hook

12:13 AM Sensors on Android 19

Input Events

Page 20: Sensors on android

Porting a sensor onto Android (userspace)

Sensor-HAL

Adding– Reference Implementation : http://goo.gl/jjF3l

– Sensor-HAL implemented in : android/device/<vendor>/<device>/libsensors

– Generates library : system/lib/hw/sensors.<TARGET_BOARD_PLATFORM>.so

Modifying– Update sensors.cpp in sSensorList[]

– Derive a new sensor object, Include appropriate file

– Update i/p dev name in constructor

Sensors on Android 2012:30 AM

Page 21: Sensors on android

Sensor Fusion

Advantages– Faster data samples

– Less noise in data samples

– More Accurate data samples

– Advanced Sensor data (Gestures, Glyphs, Shake-count, Step-count)

Disadvantage– Higher power consumption

Implement inside App– Register multiple sensor-listeners.

– Correlate-data.

Implement using Custom-Library– android/device/sample/frameworks/PlatformLibrary http://goo.gl/OI8sg

Sensors on Android 2112:30 AM

Page 22: Sensors on android

Using Sensors in your app

Sensors on Android 22

http://goo.gl/hWOQuSensorEvent

http://goo.gl/1DRUvSensorManager

12:30 AM

Page 23: Sensors on android

App-dev Tips and tricks

Sensor callibration. 1. one-turn deserves another (axes-calib) 2. zero-calib

Sensor fusion Hard-way

Easy-way (Invensense ) http://goo.gl/bHmDe

Polling rate ui/normal/game/fastest?

When to register/unregister eventListener

When to place Wakelocks

Sensors on Android 231:08 AM

Page 24: Sensors on android

App-dev Tips and tricks

1:04 AM Sensors on Android 24

register sensorlistener

unregister sensorlistener

acquire wakelock

release wakelock

Page 25: Sensors on android

What Next?

• Moving on…– Sensor Framework on Android 4.0 (ICS)

– Sensor Drivers on Kernel 3.0

• Sensor-Fusion– App / library

– Unified Kernel driver(sensors-class)

• Calorie-counter/Diet Advisor“You spent 800calories since breakfast. Have a Greek-salad and a cup of milk…”

• Location-fix without GPS (using sensors wink-wink)

Sensors on Android 25

http://goo.gl/ipbrL

12:57 AM

Page 26: Sensors on android

Thank You!!

Questions?

Sensors on Android 26

http://goo.gl/kKMOrCONTACT ME

android-porting android-developers

android-kernel android-platform

10:16 PM