Android Sensors. CPRE 388 Fall 2015 Iowa State University



Similar documents
Android Sensors. XI Jornadas SLCENT de Actualización Informática y Electrónica

Sensors & Motion Sensors in Android platform. Minh H Dang CS286 Spring 2013

Android Sensor Programming. Weihong Yu

Using the Android Sensor API

Android Framework. How to use and extend it

ELET4133: Embedded Systems. Topic 15 Sensors

ANDROID APPS DEVELOPMENT FOR MOBILE AND TABLET DEVICE (LEVEL II)

CS 403X Mobile and Ubiquitous Computing Lecture 6: Maps, Sensors, Widget Catalog and Presentations Emmanuel Agu

Developing Sensor Applications on Intel Atom Processor-Based Android* Phones and Tablets

Objective. Android Sensors. Sensor Manager Sensor Types Examples. Page 2

06 Team Project: Android Development Crash Course; Project Introduction

Using Sensors on the Android Platform. Andreas Terzis Android N00b

! Sensors in Android devices. ! Motion sensors. ! Accelerometer. ! Gyroscope. ! Supports various sensor related tasks

E0-245: ASP. Lecture 16+17: Physical Sensors. Dipanjan Gope

App Development for Smart Devices. Lec #5: Android Sensors

Programming Mobile Applications with Android

Using Extensions or Cordova Plugins in your RhoMobile Application Darryn

Obsoleted chapter from The Busy Coder's Guide to Advanced Android Development

Android app development course

Module 1: Sensor Data Acquisition and Processing in Android

Fitness Motion Recognition

Android Concepts and Programming TUTORIAL 1

Designing An Android Sensor Subsystem Pitfalls and Considerations

Android Programming Lecture 18: Menus Sensors 11/11/2011

Lab 1 (Reading Sensors & The Android API) Week 3

Arduino & Android. A How to on interfacing these two devices. Bryant Tram

Tegra Android Accelerometer Whitepaper

HP TouchPad Sensor Setup for Android

Graduate presentation for CSCI By Janakiram Vantipalli ( Janakiram.vantipalli@colorado.edu )

Performance issues in writing Android Apps

Mobilelogging: Assessing Smartphone Sensors for Monitoring Sleep Behaviour

Android. Mobile Computing Design and Implementation. Application Components, Sensors. Peter Börjesson

Sensor Fusion Mobile Platform Challenges and Future Directions Jim Steele VP of Engineering, Sensor Platforms, Inc.

Pedometer Project 1 Mr. Michaud /

CSE476 Mobile Application Development. Yard. Doç. Dr. Tacha Serif Department of Computer Engineering Yeditepe University

Internal Services. CSE 5236: Mobile Application Development Instructor: Adam C. Champion Course Coordinator: Dr. Rajiv Ramnath

Introduction to NaviGenie SDK Client API for Android

How to Convert 3-Axis Directions and Swap X-Y Axis of Accelerometer Data within Android Driver by: Gang Chen Field Applications Engineer

Sensors and Cellphones

How to develop your own app

WEARIT DEVELOPER DOCUMENTATION 0.2 preliminary release July 20 th, 2013

Developing Android Apps for BlackBerry 10. JAM854 Mike Zhou- Developer Evangelist, APAC Nov 30, 2012

Acellus Natural 3D Tablet

Motion Sensing with mcube igyro Delivering New Experiences for Motion Gaming and Augmented Reality for Android Mobile Devices

Lecture 1 Introduction to Android

Frameworks & Android. Programmeertechnieken, Tim Cocx

Android Geek Night. Application framework

Kathy Au Billy Yi Fan Zhou Department of Electrical and Computer Engineering University of Toronto { kathy.au, billy.zhou }@utoronto.

Android Basics. Xin Yang

AN APPLYING OF ACCELEROMETER IN ANDROID PLATFORM FOR CONTROLLING WEIGHT

Making Android Motion Applications Using the Unity 3D Engine

AUTOMATIC HUMAN FREE FALL DETECTION USING ANDROID

Use It Free: Instantly Knowing Your Phone Attitude

SENSORS ON ANDROID PHONES. Indian Institute of Technology Kanpur Commonwealth of Learning Vancouver

Android Development Tutorial. Nikhil Yadav CSE40816/ Pervasive Health Fall 2011

Using the Adafruit Unified Sensor Driver. Created by Kevin Townsend

Effective Use of Android Sensors Based on Visualization of Sensor Information

ECE 455/555 Embedded System Design. Android Programming. Wei Gao. Fall

ELDERLY SUPPORT - ANDROID APPLICATION FOR FALL DETECTION AND TRACKING TEJITHA RUDRARAJU. B.E, Anna University, India, 2011 A REPORT

IOS EYE4 APP User Manual

Application Note IMU Visualization Software

Admin. Mobile Software Development Framework: Android Activity, View/ViewGroup, External Resources. Recap: TinyOS. Recap: J2ME Framework

Creating a List UI with Android. Michele Schimd

Android and OpenGL. Android Smartphone Programming. Matthias Keil. University of Freiburg

AdFalcon Android SDK Developer's Guide. AdFalcon Mobile Ad Network Product of Noqoush Mobile Media Group

Android For Java Developers. Marko Gargenta Marakana

Android on Intel Course App Development - Advanced

Mobile App Sensor Documentation (English Version)

Android Sensors This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License. CC-BY Google

Introduction to Android SDK Jordi Linares

Quick Start Guide ActiGraph GT9X Link + ActiLife

The BSN Hardware and Software Platform: Enabling Easy Development of Body Sensor Network Applications

Iotivity Programmer s Guide Soft Sensor Manager for Android

UNMANNED AERIAL VEHICLE (UAV) SAFETY SYSTEM USING ANDROID APP

International Journal of Advanced Research in Computer Science and Software Engineering

UI Performance Monitoring

Frequently Asked Questions (FAQs)

Transcription:

Android Sensors CPRE 388 Fall 2015 Iowa State University

What are sensors? Sense and measure physical and ambient conditions of the device and/or environment Measure motion, touch pressure, orientation, environmental conditions, gravity Example Motion measurement (gestures) Tilt, rotate, toss, swing Can use for interactive games to change animation characteristics in response to type of motion Example Accelerometer and geomagnetic field sensor to infer direction in a compass or travel app

Sensors in Android Three major categories Motion Sensors Measures acceleration and rotation along three axes Example accelerometers, gravity sensors, gyroscopes, and rotational vector sensors Environmental sensors Measures environmental parameters ambient air temperature and pressure, illumination, and humidity. Position sensors Measures the physical position of a device orientation sensors and magnetometers

Sensors in Android Two types Hardware sensors Physical components built into the device Data derived by direct measurement Accelerometer, Ambient temperature Software or Virtual sensors Not physical devices but mimic hardware based sensors Data derived from one or more hardware sensors Linear acceleration sensor, gravity sensor

Sensor Type Description Common Uses TYPE_ACCELEROMETER TYPE_AMBIENT_TEMPER ATURE TYPE_GRAVITY TYPE_GYROSCOPE TYPE_LIGHT Hardware Hardware Software or Hardware Hardware Hardware Measures the acceleration force in m/s 2 that is applied to a device on all three physical axes (x, y, and z), including the force of gravity. Measures the ambient room temperature in degrees Celsius ( C). See note below. Measures the force of gravity in m/s 2 that is applied to a device on all three physical axes (x, y, z). Measures a device's rate of rotation in rad/s around each of the three physical axes (x, y, and z). Measures the ambient light level (illumination) in lx. Motion detection (shake, tilt, etc.). Monitoring air temperatures. Motion detection (shake, tilt, etc.). Rotation detection (spin, turn, etc.). Controlling screen brightness.

TYPE_LINEAR_ACCELERAT ION Software or Hardware Measures the acceleration force in m/s 2 that is applied to a device on all three physical axes (x, y, and z), excluding the force of gravity. Monitoring acceleration along a single axis. TYPE_MAGNETIC_FIELD Hardware Measures the ambient geomagnetic field for all three physical axes (x, y, z) in μt. Creating a compass. TYPE_ORIENTATION Software Measures degrees of rotation that a device makes around all three physical axes (x, y, z). As of API level 3 you can obtain the inclination matrix and rotation matrix for a device by using the gravity sensor and the geomagnetic field sensor in conjunction with the getrotationmatrix() method. Determining device position.

Android Sensor Framework Get raw data from sensors Change sensor parameters Sampling frequency Determine which sensors are available Determine sensor's specs Manufacturer, resolution, power needs Set up sensor event listeners to monitor changes

Android sensor framework Part of android.hardware package Classes and interfaces to access sensors

Android sensor framework classes SensorManager class to create an instance of the sensor service methods for accessing and listing sensors registering and unregistering sensor event listeners Determine sensor accuracy, set data acquisition rates, and calibrate sensors Sensor create an instance of a specific sensor determine a sensor's capabilities

Android sensor framework classes SensorEvent create a sensor event object provide the raw sensor data, the type of sensor that generated the event, the accuracy of the data, and the timestamp for the event SensorEventListener Two callback methods methods called when receiving notifications (sensor events) when sensor values change or when sensor accuracy changes

Primary API functionality Identifying sensors and sensor capabilities identify all of the sensors that are present on a device disable app features which rely on unavailable sensors Monitor sensor events acquire raw sensor data sensor event occurs every time a sensor detects a change in the parameters it is measuring Four parameters per event name of the sensor that triggered the event timestamp for the event accuracy of the event raw sensor data that triggered the event.

What sensors are in my device? Identify sensors get a reference to the system sensor service List all the sensors Instance of sensor service private SensorManager msensormanager; msensormanager = (SensorManager) getsystemservice(context.sensor_service); List<Sensor> devicesensors = msensormanager.getsensorlist(sensor.type_all); List all the sensors in the device

What sensors are in my device? is there a default sensor of the given type? If there is more than one sensor of a type, one of them is designated as default. if (msensormanager.getdefaultsensor(sensor.type_magnetic_field)!= null){ // Success! There's a magnetometer. TYPE_GYROSCOPE, TYPE_LINEAR_ACCELERATION, or TYPE_GRAVITY

Sensor Capabilities & Attributes Sensor class public methods to determine the capabilities and attributes of individual sensors. Useful if you want your application to behave differently based on which sensors or sensor capabilities are available on a device. getresolution(), getmaximumrange(), getpower()

msensormanager = (SensorManager) getsystemservice(context.sensor_service); if (msensormanager.getdefaultsensor(sensor.type_gravity)!= null){ List<Sensor> gravsensors = msensormanager.getsensorlist(sensor.type_gravity); for(int i=0; i<gravsensors.size(); i++) { if ((gravsensors.get(i).getvendor().contains("google Inc.")) && (gravsensors.get(i).getversion() == 3)){ // Use the version 3 gravity sensor. msensor = gravsensors.get(i);

else{ // Use the accelerometer. if (msensormanager.getdefaultsensor(sensor.type_accelerometer)!= null){ msensor = msensormanager.getdefaultsensor(sensor.type_accelerometer); else{ // Sorry, there are no accelerometers on your device. // You can't play this game.

Monitor sensor events implement two callback methods onaccuracychanged() and onsensorchanged() exposed through the SensorEventListener interface sensor's accuracy changes system invokes the onaccuracychanged() method reference to the Sensor object that changed the new accuracy of the sensor Accuracy is represented by one of four status constants: SENSOR_STATUS_ACCURACY_LOW, SENSOR_STATUS_ACCURACY_ME DIUM, SENSOR_STATUS_ACCURACY_HIGH, or SENSOR_STATUS_UNRELIABLE sensor reports a new value system invokes the onsensorchanged() method reference to SensorEvent object contains information about the new sensor data

public class SensorActivity extends Activity implements SensorEventListener { private SensorManager msensormanager; private Sensor mlight; @Override public final void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); msensormanager = (SensorManager) getsystemservice(context.sensor_service); mlight = msensormanager.getdefaultsensor(sensor.type_light);

Monitor sensor events @Override public final void onaccuracychanged(sensor sensor, int accuracy) { // Do something here if sensor accuracy changes. @Override public final void onsensorchanged(sensorevent event) { // The light sensor returns a single value. // Many sensors return 3 values, one for each axis. float lux = event.values[0]; // Do something with this sensor value. Reference to Sensor object Reference to Sensor event object raw data, time stamp, accuracy, type of sensor

@Override protected void onresume() { super.onresume(); msensormanager.registerlistener(this, mlight, SensorManager.SENSOR_DELAY_NORMAL); @Override protected void onpause() { super.onpause(); msensormanager.unregisterlistener(this); int SENSOR_DELAY_FASTEST int SENSOR_DELAY_GAME int SENSOR_DELAY_NORMAL int SENSOR_DELAY_UI get sensor data as fast as possible (0 µs) rate suitable for games (20000 µs) rate (default) suitable for screen orientation changes (200000 µs) rate suitable for the user interface (60000 µs)

Detecting Sensor at Run Time private SensorManager msensormanager;... msensormanager = (SensorManager) getsystemservice(context.sensor_service); if (msensormanager.getdefaultsensor(sensor.type_pressure)!= null){ // Success! There's a pressure sensor. else { // Failure! No pressure sensor. Disable the UI that depends on pressure sensor

Uses Feature For google play, use uses feature in manifest <uses feature android:name="android.hardware.sensor.accelerometer" android:required="true" />

Sensor Coordinate System sensor framework uses a standard 3 axis coordinate system coordinate system is defined relative to the device's screen device is held in its default orientation default orientation the X axis is horizontal and points to the right the Y axis is vertical and points up the Z axis points toward the outside of the screen face. ve Z coordinates behind the screen the sensor's coordinate system never changes as the device moves Accelerometer, Gyroscope, gravity sensor, linear acceleration sensor, geomagnetic field sensor

Putting it all together Accelerometer public class sensorexample extends Activity implements SensorEventListener { private SensorManager sensensormanager; private Sensor senaccelerometer; @Override protected void oncreate(bundle savedinstancestate) { Reference to system sensor service Reference to default accelerometer Need to check if it exists super.oncreate(savedinstancestate); setcontentview(r.layout.activity_sensorexample); sensensormanager = (SensorManager) getsystemservice(context.sensor_service); senaccelerometer = sensensormanager.getdefaultsensor(sensor.type_accelerometer); sensensormanager.registerlistener(this, senaccelerometer, SensorManager.SENSOR_DELAY_NORMAL); Register the listener to call back when sensor event occurs

Called when accelerometer registers a new event such as motion along any axis @Override public void onsensorchanged(sensorevent sensorevent) { Sensor mysensor = sensorevent.sensor; if (mysensor.gettype() == Sensor.TYPE_ACCELEROMETER) { float x = sensorevent.values[0]; Acceleration values along float y = sensorevent.values[1]; the three axis float z = sensorevent.values[2]; @Override public void onaccuracychanged(sensor sensor, int accuracy) {

protected void onpause() { super.onpause(); sensensormanager.unregisterlistener(this); Important Sensors drain battery resource. Sensors keep acquiring data during onpause if not unregistered Re register Sensorevent listener to continue acquiring data during onresume protected void onresume() { super.onresume(); sensensormanager.registerlistener(this, senaccelerometer, SensorManager.SENSOR_DELAY_NORMAL);