Lecture 4: Sensors Topics: Motion, Position, and Environmental Sensors.

Slides:



Advertisements
Similar presentations
Programming with Android: System Services Luca Bedogni Marco Di Felice Dipartimento di Scienze dell’Informazione Università di Bologna.
Advertisements

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.
App Inventor You are going to use App Inventor to make an application for your phone Smart Phone ‘s can hold many entertaining apps due to the amount of.
Android Sensors & Async Callbacks Jules White Bradley Dept. of Electrical and Computer Engineering Virginia Tech
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.
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)
App Inventor You are going to use App Inventor to make an application for your phone Smart Phone ‘s can hold many entertaining apps due to the amount of.
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.
Mobile Device Development Camera and Sensors Dr.YingLiang Ma.
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.
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.
App Inventor You are going to use App Inventor to make an application for your phone Smart Phone ‘s can hold many entertaining apps due to the amount of.
Sensors For Mobile Phones  Ambient Light Sensor  Proximity Sensor  GPS Receiver Sensor  Gyroscope Sensor  Barometer Sensor  Accelerometer Sensor.
App Inventor You are going to use App Inventor to make an application for your phone Smart Phone ‘s can hold many entertaining apps due to the amount of.
App Inventor You are going to use App Inventor to make an application for your phone Smart Phone ‘s can hold many entertaining apps due to the amount of.
CS378 - Mobile Computing Sensing and Sensors Part 2.
Lecture 4: Sensors Topics: Motion, Position, and Environmental Sensors Date: Feb 11, 2016.
App Inventor You are going to use App Inventor to make an application for your phone Smart Phone ‘s can hold many entertaining apps due to the amount of.
CPE 490/590 – Smartphone Development
App Inventor You are going to use App Inventor to make an application for your phone Smart Phone ‘s can hold many entertaining apps due to the amount of.
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
App Inventor You are going to use App Inventor to make an application for your phone Smart Phone ‘s can hold many entertaining apps due to the amount of.
App Inventor You are going to use App Inventor to make an application for your phone Smart Phone ‘s can hold many entertaining apps due to the amount of.
App Inventor You are going to use App Inventor to make an application for your phone Smart Phone ‘s can hold many entertaining apps due to the amount of.
Android – Event Handling
Mobile Software Development for Android - I397
Lecture 4: Sensors Topics: Motion, Position, and Environmental Sensors.
Walk n’ Play Group #8 - Team Murali Krishna Goli Viswanath Patimalla
What's Happening Today Working with Images
Vijay Kumar Kolagani Dr. Yingcai Xiao
CS499 – Mobile Application Development
App Inventor You are going to use App Inventor to make an application for your phone Smart Phone ‘s can hold many entertaining apps due to the amount of.
Mobile Handset Sensors
CS371m - Mobile Computing Sensing and Sensors.
CIS 470 Mobile App Development
Vijay Kumar Kolagani Dr. Yingcai Xiao
CIS 470 Mobile App Development
Android Topics Sensors Accelerometer and the Coordinate System
Android Programming Tutorial
CIS 493/EEC 492 Android Sensor Programming
CIS 493/EEC 492 Android Sensor Programming
Android Intents & 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
Mobile Programming Broadcast Receivers.
CIS 694/EEC 693 Android Sensor Programming
CIS 694/EEC 693 Android Sensor Programming
Presentation transcript:

Lecture 4: Sensors Topics: Motion, Position, and Environmental Sensors

Sensors Overview Motion Sensors Position Sensors Environmental Sensors

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

Types of Sensors Sensor HW/SW Notes Use TYPE_ACCELEROMETER HW (Ax, Ay, Az) + g; ms2 Shake, Tilt TYPE_AMBIENT_TEMPERATURE 0C TYPE_GRAVITY SW/HW g = (gx, gy, gz); ms2 TYPE_GYROSCOPE ω = (ωx, ωy, ωz) rad/s Spin, Turn TYPE_LIGHT Illumination; lx Brightness control TYPE_LINEAR_ACCELERATION (Ax, Ay, Az); no g; ms2 TYPE_MAGNETIC_FIELD (Bx, By, Bz) µT Compass TYPE_ORIENTATION SW 3 axis rotation; matrix Device position TYPE_PRESSURE hPa or mbar Air pressure TYPE_PROXIMITY cm; distant from screen Phone position TYPE_RELATIVE_HUMIDITY humidity (%) Dew point TYPE_ROTATION_VECTOR Device’s rotation vector TYPE_TEMPERATURE

Types of Sensors Sensor HW/SW Notes Use TYPE_ACCELEROMETER HW (Ax, Ay, Az) + g; ms2 Shake, Tilt TYPE_AMBIENT_TEMPERATURE 0C TYPE_GRAVITY SW/HW g = (gx, gy, gz); ms2 TYPE_GYROSCOPE ω = (ωx, ωy, ωz) rad/s Spin, Turn TYPE_LIGHT Illumination; lx Brightness control TYPE_LINEAR_ACCELERATION (Ax, Ay, Az); no g; ms2 TYPE_MAGNETIC_FIELD (Bx, By, Bz) µT Compass TYPE_ORIENTATION SW 3 axis rotation; matrix Device position TYPE_PRESSURE hPa or mbar Air pressure TYPE_PROXIMITY cm; distant from screen Phone position TYPE_RELATIVE_HUMIDITY humidity (%) Dew point TYPE_ROTATION_VECTOR Device’s rotation vector TYPE_TEMPERATURE

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

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

Four Relevant Classes SensorEvent SensorEventListener Carries information about a sensor event: Raw data, sensor type, accuracy, timestamp 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<Sensor> l; sm = (SensorManager) getSystemService (Context.SENSOR_SERVICE); l = sm.getSensorList(Sensor.TYPE_ALL); s = sm.getDefaultSensor(Sensor.TYPE_LIGHT); Returns “null” if no light 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<Sensor> l; @Override 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, 1000000); } @Override public void onSensorChanged(SensorEvent event) { } @Override public void onAccuracyChanged(Sensor sensor, int accuracy) { } }

Good Practices: Check sensor before using. Declare <uses-feature> in the manifest. Unregister at onPause(), register at onResume(). if(sm.getDefaultSensor(Sensor.TYPE_LIGHT) == null) { //Display sensor not available message. } <uses-feature android:name="android.hardware.sensor.accelerometer" android:required="true" /> @Override protected void onPause() { super.onPause(); sm.unregisterListener(this); } @Override protected void onResume() { super.onResume(); sm.registerListener(this, s, 1000000); }

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

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.

References (study these) https://developer.android.com/guide/topics/sensors/sensors_overview https://developer.android.com/guide/topics/sensors/sensors_motion https://developer.android.com/guide/topics/sensors/sensors_position https://developer.android.com/guide/topics/sensors/sensors_environment https://www.quora.com/What-are-all-the-sensors-used-in-smartphones-and- explain-its-purpose-and-its-working