Lecture 4: Sensors Topics: Motion, Position, and Environmental Sensors Date: Feb 11, 2016.

Slides:



Advertisements
Similar presentations
Android Application Development Tutorial. Topics Lecture 4 Overview Overview of Sensors Programming Tutorial 1: Tracking location with GPS and Google.
Advertisements

Programming with Android: System Services Luca Bedogni Marco Di Felice Dipartimento di Scienze dell’Informazione Università di Bologna.
Programming with Android: Activities
Sensors.  Hardware devices that take measurements of the physical environment  Some examples  3-axis Accelerometer  3-axis Magnetic field sensor 
Cosc 5/4730 Input Keyboard, touch, and Accelerometer.
Introduction to Smartphone Sensors
Android sensors.
CS378 - Mobile Computing Sensing and Sensors. Sensors "I should have paid more attention in Physics 41" Most devices have built in sensors to measure.
CS378 - Mobile Computing Sensing and Sensors. Sensors "I should have paid more attention in Physics 41" Most devices have built in sensors to measure.
Android Sensors & Async Callbacks Jules White Bradley Dept. of Electrical and Computer Engineering Virginia Tech
Introduction to Mobile Sensing with Smartphones Uichin Lee April 22, 2013.
Programming Mobile Applications with Android September, Albacete, Spain Jesus Martínez-Gómez.
Getting Started with Android APIs Ivan Wong. Motivation - “Datasheet” - Recently exposed to what’s available in Android - So let’s see what API’s are.
Cosc 5/4730 Input Keyboard, touch, and Accelerometer.
Mobile Application Development Selected Topics – CPIT 490
Lecture # 9 Hardware Sensor. Topics 2  SensorManger & Sensor  SensorEvent & SensorEventListener  Example Application.
Mobile Programming Lecture 9 Bound Service, Location, Sensors, IntentFilter.
1 Localization and Sensing Nilanjan Banerjee Mobile Systems Programming (Acknowledgement: Jules White) University of Arkansas Fayetteville, AR
Sensing. Possible sensors on devices – Documented in SensorEvent class Accelerometer (m/s 2 ) – acceleration in x, y, z axes Magnetic Field (micro Tesla)
Doodlz App Android How to Program © by Pearson Education, Inc. All Rights Reserved.
Cosc 5/4730 Broadcast Receiver. Broadcast receiver A broadcast receiver (short receiver) – is an Android component which allows you to register for system.
1 CMSC 628: Introduction to Mobile Computing Nilanjan Banerjee Introduction to Mobile Computing University of Maryland Baltimore County
Android Programming-Activity Lecture 4. Activity Inside java folder Public class MainActivity extends ActionBarActivity(Ctrl + Click will give you the.
Sensors – Part I SE 395/595.
로봇을 조종하자 3/4 UNIT 17 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 스마트 폰의 센서를 사용할 수 있다. 2.
CS378 - Mobile Computing Sensing and Sensors Part 2.
Location. GPS Global Positioning System – At least 4 satellites typically used 3 required extra for error detection and altitude typically accurate within.
Mobile Device Development Camera and Sensors Dr.YingLiang Ma.
Android Boot Camp Demo Application – Part 1. Development Environment Set Up Download and install Java Development Kit (JDK) Download and unzip Android.
Sensors in android. App being more applicable Keeping track of your heart beat while jogging. Pointing the phone camera towards the night sky to know.
Android vs. JavaScript 建國科技大學資管系 饒瑞佶 2013/5. JavaScript call Java By JavascriptInterface 將 native code 寫在 JavascriptInterface 內,例 如取得方位的程式 透過 WebView.
Sensors Nasrullah Khan Niazi. Using Device Sensors The Android SDK provides access to raw data from sensors on the device.The sensors,and their precision.
Sensors For Mobile Phones  Ambient Light Sensor  Proximity Sensor  GPS Receiver Sensor  Gyroscope Sensor  Barometer Sensor  Accelerometer Sensor.
CS378 - Mobile Computing Sensing and Sensors Part 2.
Android Alert Dialog. Alert Dialog Place Button to open the dialog. public class MainActivity extends ActionBarActivity { private static Button button_sbm;
Lecture 5: Location Topics: Google Play Services, Location API Date: Feb 16, 2016.
CPE 490/590 – Smartphone Development
CHAPTER 8 Sensors and Camera. Chapter objectives: Understand Motion Sensors, Environmental Sensors and Positional Sensors Learn how to acquire measurement.
Mobile Software Development for Android - I397 IT COLLEGE, ANDRES KÄVER, WEB:
CS371m - Mobile Computing Sensing and Sensors.
The Doodlz app enables you to paint by dragging one or more fingers across the screen. The app provides options for setting the drawing color.
Android Android Sensors Android Sensors: – Accelerometer – Gravity sensor – Linear Acceleration sensor – Magnetic Field sensor – Orientation.
Sensors in Android.
Vijay Kumar Kolagani Dr. Yingcai Xiao
Lecture 4: Sensors Topics: Motion, Position, and Environmental Sensors
Lecture 5: Location Topics: Google Play Services, Location API
Lecture 5: Location Topics: Google Play Services, Location API.
Broadcast receivers.
Android – Event Handling
Lecture 4: Sensors Topics: Motion, Position, and Environmental Sensors.
What's Happening Today Working with Images
Sensors, maps and fragments:
Vijay Kumar Kolagani Dr. Yingcai Xiao
CS499 – Mobile Application Development
CS371m - Mobile Computing Sensing and Sensors.
CIS 470 Mobile App Development
Vijay Kumar Kolagani Dr. Yingcai Xiao
CIS 470 Mobile App Development
Activities and Intents
Android Topics Sensors Accelerometer and the Coordinate System
Android Programming Tutorial
CIS 493/EEC 492 Android Sensor Programming
Lecture 4: Sensors Topics: Motion, Position, and Environmental Sensors.
CIS 493/EEC 492 Android Sensor Programming
Lecture 5: Location Topics: Google Play Services, Location API.
Mobile Programming Sensors in Android.
SE4S701 Mobile Application Development
Activities, Fragments, and Intents
Mobile Programming Broadcast Receivers.
CIS 694/EEC 693 Android Sensor Programming
Presentation transcript:

Lecture 4: Sensors Topics: Motion, Position, and Environmental Sensors Date: Feb 11, 2016

References (study these)

Sensors Overview 1.Motion Sensors 2.Position Sensors 3.Environmental Sensors

Examples 1.Motion Sensors Measure acceleration and rotational forces. e.g., accelerometers, gravity sensors, gyroscopes, and rotational vector sensors. 2.Position Sensors Measure the physical position of a device e.g., orientation sensors and magnetometers 3.Environmental Sensors Measure various environmental parameters e.g., barometers, photometers, and thermometers.

Types of Sensors SensorHW/SWNotesUse TYPE_ACCELEROMETERHW(A x, A y, A z ) + g; ms 2 Shake, Tilt TYPE_AMBIENT_TEMPERATUREHW*C TYPE_GRAVITYSW/HWg = (g x, g y, g z ); ms 2 Shake, Tilt TYPE_GYROSCOPEHWω = (ω x, ω y, ω z ) rad/sSpin, Turn TYPE_LIGHTHWIllumination; lxBrightness control TYPE_LINEAR_ACCELERATIONSW/HW(A x, A y, A z ); no g; ms 2 TYPE_MAGNETIC_FIELDHW(B x, B y, B z ) µTCompass TYPE_ORIENTATIONSW3 axis rotation; matrixDevice position TYPE_PRESSUREHWhPa or mbarAir pressure TYPE_PROXIMITYHWcm; distant from screenPhone position TYPE_RELATIVE_HUMIDITYHWhumidity (%)Dew point TYPE_ROTATION_VECTORSW/HWDevice’s rotation vector TYPE_TEMPERATUREHW*C

Android Sensor Framework 1.Check Availability What sensors do I have? 2.Get Information e.g., maximum range, manufacturer, power requirements, and resolution. 3.Get Values e.g., raw sensor data, minimum rate. 4.Register/unregister for Sensor Events

Four Relevant Classes 1.SensorManager: Create an instance of the sensor service. Accessing and listing sensors. Registering and unregistering sensor event listeners. Acquiring orientation information. Report sensor accuracy, set data acquisition rates, and calibrate sensors. 2.Sensor: Create an instance of a specific sensor. Determine a sensor's capabilities.

Four Relevant Classes 3.SensorEvent Carries information about a sensor event: Raw data, sensor type, accuracy, timestamp 4.SensorEventListener Two callback methods that receive notifications: onSensorChanged() and onAccuracyChanged()

Working with Sensors Step 1: Get the SensorManger from system services. Step 2: Get the Sensor (or a list) from the manager. private SensorManager sm; private Sensor s; private List l; sm = (SensorManager) getSystemService (Context.SENSOR_SERVICE); l = sm.getSensorList(Sensor.TYPE_ALL); s = sm.getDefaultSensor(Sensor.TYPE_LIGHT); Returns “null” if no proximity sensor

Working with Sensors Step 3 (optional): Get information about a Sensor. s.getName(); s.getMaximumRange(); s.getResolution(); s.getMinDelay(); s.getPower(); s.getVendor(); s.getVersion();

Working with Sensors Step 4: Implement and Register SensorEventListener public class MainActivity extends AppCompatActivity implements SensorEventListener{ private SensorManager sm; private Sensor s; private List protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); sm = (SensorManager) getSystemService(Context.SENSOR_SERVICE); l = sm.getSensorList(Sensor.TYPE_ALL); s = sm.getDefaultSensor(Sensor.TYPE_LIGHT); sm.registerListener(this, s, ); public void onSensorChanged(SensorEvent event) { public void onAccuracyChanged(Sensor sensor, int accuracy) { } }

Code Practice: Show a list of available sensors on the device. Get Gravity Sensor readings. Report them at 1 second interval. Now, add another sensor, e.g., Light Sensor. Report light sensor at 0.5 second interval.

Good Practices: Check sensor before using. Declare in the manifest. Unregister at onPause(), register at onResume(). if(sm.getDefaultSensor(Sensor.TYPE_LIGHT) == null) { //Display sensor not available message. protected void onPause() { super.onPause(); sm.unregisterListener(this); protected void onResume() { super.onResume(); sm.registerListener(this, s, ); }

Good Practices: Don’t block onSensorChanged() Choose sensor delays public void onSensorChanged(SensorEvent event) { //Not a place to solve an NP-hard problem here*. } *it’s a joke