Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Sensors on AndroidChinmayVS @ DroidCON-2011
cvs@droidcon$ who am i• Android >2yrs. Remember           anyone?•            - sensors development. 10million+ units sold...
Sensors on AndroidPART1 : Introduction                                       PART4: Sensor Application development.•   Sen...
“Sense-ors” on Android                A sensor (also called detector) is a device that measures           a physical quant...
“Famous” sensor apps10:16 PM         Sensors on Android   5
Sensors in Android applications             • Use-cases of sensors in apps:             1.   Active-Input             2.  ...
Sensors in Android applications (1/4)• Active input10:16 PM                 Sensors on Android        7
Sensors in Android applications (2/4)• Passive input10:16 PM                 Sensors on Android        8
Sensors in Android applications (3/4)• Active-passive10:16 PM                 Sensors on Android        9
Sensors in Android applications (4/4)• Auto-rotate10:16 PM                 Sensors on Android        10
Sensor Hardware Intro (1/4)• Accelerometer      + ZERO drift      - Relatively slower response10:16 PM                    ...
Sensor Hardware Intro (2/4)• Gyroscope (MEMS)      + Extremely quick response      - Gradual drift with time10:16 PM      ...
Sensor Hardware Intro (3/4)• Compass (Magnetometer)      + Obtain Yaw/Azimuth      + Rotation with the device on a flat su...
Sensor Hardware Intro (4/4)• Light & Proximity10:16 PM              Sensors on Android   14
Android Sensors Frameworks OverviewAndroid App  • Use SensorManager & SensorEventListener              C                  ...
Porting a sensor onto AndroidQ. My board has XYZ sensor. How do I get Android to recognise it? Kernel       Device-drive...
Porting a sensor onto Android (kernel)       Device-driver            Poll/Interrupt? Hybrid-approach = Workqueues      ...
Porting a sensor onto Android (kernel) Workqueues12:09 AM                  Sensors on Android        18
Porting a sensor onto Android (kernel) Early-Suspend hook Input Events12:13 AM                  Sensors on Android      ...
Porting a sensor onto Android (userspace) Sensor-HAL       Adding           – Reference Implementation : http://goo.gl/j...
Sensor Fusion Advantages      –    Faster data samples      –    Less noise in data samples      –    More Accurate data ...
Using Sensors in your app    SensorEvent     http://goo.gl/hWOQu    SensorManager   http://goo.gl/1DRUv12:30 AM           ...
App-dev Tips and tricks Sensor callibration.  1. one-turn deserves another (axes-calib)  2. zero-calib Sensor fusion    ...
App-dev Tips and tricks                                  register sensorlistener                                      acqu...
What Next?• Moving on…      – Sensor Framework on Android 4.0 (ICS)      – Sensor Drivers on Kernel 3.0• Sensor-Fusion    ...
Thank You!!                     Questions?              android-porting        android-developers              android-ker...
Upcoming SlideShare
Loading in …5
×

Sensors on android

25,253 views

Published on

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.

Published in: Technology, Business
  • Be the first to comment

Sensors on android

  1. 1. Sensors on AndroidChinmayVS @ DroidCON-2011
  2. 2. cvs@droidcon$ who am i• Android >2yrs. Remember anyone?• - sensors development. 10million+ units sold.• Presently working @ PathPartnerTech.com10:16 PM Sensors on Android 2
  3. 3. Sensors on AndroidPART1 : Introduction PART4: Sensor Application development.• Sensors on Android Sample android app (code snippets)• Famous sensor apps• Sensors in Android apps PART5: App-dev Tips and tricks• Sensor Hardware intro • Sensor callibration. 1. one-turn deserves another (axes-calib)PART2 : Android Sensor Overview 2. zero-calib• Overview • Sensor fusion (hard-way)• Porting a new sensor onto Android • Invensense (easy-way)• Kernel • Polling rate game/ui/fastest• Sensor "HAL" • When to place Wakelocks • When to register/unregister eventListenerPART3 : Porting tips and tricks• No motion ≠ 0accel• Accel axes 3step calibration• Input devices & events (EV_ABS, EV_REL)10:20 PM Sensors on Android 3
  4. 4. “Sense-ors” on Android A sensor (also called detector) is a device that measures a physical quantity and converts it into a signal which can be read by an observer or by an instrument. 1. ACCELEROMETER 2. GYROSCOPE 3. MAGNETIC_FIELD REAL 4. LIGHT 5. PRESSURE 6. AMBIENT_TEMP 7. RELATIVE_HUMIDITY 8. PROXIMITY VIRTUAL 9. LINEAR_ACCELERATION 10. GRAVITY 11. ROTATION_VECTOR DEPRECEATED 12. TEMPERATURE 13. ORIENTATION10:20 PM Sensors on Android 4
  5. 5. “Famous” sensor apps10:16 PM Sensors on Android 5
  6. 6. Sensors in Android applications • Use-cases of sensors in apps: 1. Active-Input 2. Passive-Input Application developer 3. Active-Passive 4. Auto-Rotate Android window manager10:16 PM Sensors on Android 6
  7. 7. Sensors in Android applications (1/4)• Active input10:16 PM Sensors on Android 7
  8. 8. Sensors in Android applications (2/4)• Passive input10:16 PM Sensors on Android 8
  9. 9. Sensors in Android applications (3/4)• Active-passive10:16 PM Sensors on Android 9
  10. 10. Sensors in Android applications (4/4)• Auto-rotate10:16 PM Sensors on Android 10
  11. 11. Sensor Hardware Intro (1/4)• Accelerometer + ZERO drift - Relatively slower response10:16 PM Sensors on Android 11
  12. 12. Sensor Hardware Intro (2/4)• Gyroscope (MEMS) + Extremely quick response - Gradual drift with time10:16 PM Sensors on Android 12
  13. 13. Sensor Hardware Intro (3/4)• Compass (Magnetometer) + Obtain Yaw/Azimuth + Rotation with the device on a flat surface - Picks-up surrounding magnetic noise10:16 PM Sensors on Android 13
  14. 14. Sensor Hardware Intro (4/4)• Light & Proximity10:16 PM Sensors on Android 14
  15. 15. Android Sensors Frameworks OverviewAndroid App • Use SensorManager & SensorEventListener C OAndroid Framework N D • SensorService & SensorManager T A R TAndroid sensor “HAL” O A L • Links the Kernel-Drivers to the frameworkKernel Drivers • Device drivers to control and gather data from the actual hardware.10:16 PM Sensors on Android 15
  16. 16. Porting a sensor onto AndroidQ. My board has XYZ sensor. How do I get Android to recognise it? Kernel  Device-driver  Board File Userspace  Adding New HAL -OR-  Modifying existing HAL10:16 PM Sensors on Android 16
  17. 17. 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_data12:15 AM Sensors on Android 17
  18. 18. Porting a sensor onto Android (kernel) Workqueues12:09 AM Sensors on Android 18
  19. 19. Porting a sensor onto Android (kernel) Early-Suspend hook Input Events12:13 AM Sensors on Android 19
  20. 20. 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 constructor12:30 AM Sensors on Android 20
  21. 21. 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/OI8sg12:30 AM Sensors on Android 21
  22. 22. Using Sensors in your app SensorEvent http://goo.gl/hWOQu SensorManager http://goo.gl/1DRUv12:30 AM Sensors on Android 22
  23. 23. 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 Wakelocks1:08 AM Sensors on Android 23
  24. 24. App-dev Tips and tricks register sensorlistener acquire wakelock release wakelock unregister sensorlistener1:04 AM Sensors on Android 24
  25. 25. 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) http://goo.gl/ipbrL12:57 AM Sensors on Android 25
  26. 26. Thank You!! Questions? android-porting android-developers android-kernel android-platform CONTACT ME http://goo.gl/kKMOr10:16 PM Sensors on Android 26

×