SlideShare une entreprise Scribd logo
1  sur  48
SENSORS
CPE 490/590 – Smartphone Development
by: Michael T. Shrove
IOS
CMMOTIONMANAGER
• A CMMotionManager object is the gateway to the
motion services provided by iOS.
• These services provide an app with accelerometer data,
rotation-rate data, magnetometer data, and other
device-motion data such as attitude.
• These types of data originate with a device’s
accelerometers and (on some models) its
magnetometer and gyroscope.
TYPES OF MOTION
SENSORS
• Accelerometer
• Gyroscope
• Magnetometer
• Device Motion (Combines all three)
EXAMPLE OF
ACCELEROMETER
EXAMPLE OF GYROSCOPE
EXAMPLE OF PEDOMETER
EXAMPLE OF ALTITUDE
HTTPS://GITHUB.COM/VANDADNP/IOS-8-SWIFT-
PROGRAMMING-COOKBOOK
ANDROID
OVERVIEW
• Android Sensors Overview
• Types of Sensors
• Motion Sensors
• Environmental Sensors
• Position Sensors
• Introduction to Sensor Framework
SENSORS OVERVIEW
• Most Android-powered devices have built-in sensors
that measure motion, orientation, and various
environmental conditions.
• These sensors are capable of providing raw data with
high precision and accuracy, and are useful if you
want to monitor three-dimensional device movement
or positioning, or you want to monitor changes in the
ambient environment near a device.
SENSOR EXAMPLES
• For example, a game might track readings from a
device's gravity sensor to infer complex user gestures
and motions, such as tilt, shake, rotation, or swing.
• Likewise, a weather application might use a device's
temperature sensor and humidity sensor to calculate
and report the dewpoint, or a travel application might
use the geomagnetic field sensor and accelerometer
to report a compass bearing.
TYPES OF SENSORS
• Motion Sensors
• Environmental Sensors
• Position Sensors
MOTION SENSORS
• These sensors measure acceleration forces and
rotational forces along three axes.
• This category includes accelerometers, gravity
sensors, gyroscopes, and rotational vector sensors.
ENVIRONMENT SENSORS
• These sensors measure various environmental
parameters, such as ambient air temperature and
pressure, illumination, and humidity.
• This category includes barometers, photometers, and
thermometers.
POSITION SENSORS
• These sensors measure the physical position of a
device.
• This category includes orientation sensors and
magnetometers.
SENSORS
• You can access sensors available on the device and acquire raw
sensor data by using the Android sensor framework.
• For example, you can use the sensor framework to do the following:
• Determine which sensors are available on a device.
• Determine an individual sensor's capabilities, such as its maximum
range, manufacturer, power requirements, and resolution.
• Acquire raw sensor data and define the minimum rate at which you
acquire sensor data.
• Register and unregister sensor event listeners that monitor sensor
changes.
INTRODUCTION TO
SENSOR FRAMEWORK
• The Android sensor framework lets you access many types of sensors. Some
of these sensors are hardware-based and some are software-based.
• Hardware-based sensors are physical components built into a handset or
tablet device. They derive their data by directly measuring specific
environmental properties, such as acceleration, geomagnetic field strength,
or angular change.
• Software-based sensors are not physical devices, although they mimic
hardware-based sensors. Software-based sensors derive their data from one
or more of the hardware-based sensors and are sometimes called virtual
sensors or synthetic sensors.
• The linear acceleration sensor and the gravity sensor are examples of
software-based sensors.
SENSOR MANAGER
• You can use this class to create an instance of the sensor
service.
• This class provides various methods for accessing and
listing sensors, registering and unregistering sensor event
listeners, and acquiring orientation information.
• This class also provides several sensor constants that are
used to report sensor accuracy, set data acquisition rates,
and calibrate sensors.
SENSOR
• You can use this class to create an instance of a
specific sensor.
• This class provides various methods that let you
determine a sensor's capabilities.
SENSOR EVENT
• The system uses this class to create a sensor event object,
which provides information about a sensor event.
• A sensor event object includes the following information:
• the raw sensor data
• the type of sensor that generated the event
• the accuracy of the data
• the timestamp for the event.
SENSOR EVENTLISTENER
• You can use this interface to create two callback
methods that receive notifications (sensor events)z;
• sensor values change
• sensor accuracy changes.
DEVICES
• Few Android-powered devices have every type of sensor.
• For example, most handset devices and tablets have an
accelerometer and a magnetometer, but fewer devices have
barometers or thermometers.
• Also, a device can have more than one sensor of a given
type.
• For example, a device can have two gravity sensors, each
one having a different range.
MOTION SENSORS
• The Android platform provides several sensors that let
you monitor the motion of a device.
• Two of these sensors are always hardware-based (the
accelerometer and gyroscope), and three of these
sensors can be either hardware-based or software-
based (the gravity, linear acceleration, and rotation
vector sensors).
MOTION SENSORS
• Accelerometer
• Gravity
• Gyroscope
• Linear acceleration
• Rotation Vector
• http://developer.android.com/
guide/topics/sensors/sensors
_motion.html
USING THE ACCELEROMETER
• An acceleration sensor measures the acceleration
applied to the device, including the force of gravity.
• The following code shows you how to get an instance
of the default acceleration sensor:
private SensorManager mSensorManager;
private Sensor mSensor;
...
mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
ACCELEROMETER++
• Conceptually, an acceleration sensor determines the
acceleration that is applied to a device (Ad) by
measuring the forces that are applied to the sensor
itself (Fs) using the following relationship:
• Ad = - ∑Fs / mass
• However, the force of gravity is always influencing the
measured acceleration according to the following
relationship:
• Ad = -g - ∑F / mass
ACCELEROMETER += 1
• For this reason, when the device is sitting on a table (and not
accelerating), the accelerometer reads a magnitude of g = 9.81
m/s2.
• Similarly, when the device is in free fall and therefore rapidly
accelerating toward the ground at 9.81 m/s2, its accelerometer
reads a magnitude of g = 0 m/s2.
• Therefore, to measure the real acceleration of the device, the
contribution of the force of gravity must be removed from the
accelerometer data.
• This can be achieved by applying a high-pass filter.
• Conversely, a low-pass filter can be used to isolate the force of
gravity.
LOW PASS FILTER APPLIED
public void onSensorChanged(SensorEvent event){
// In this example, alpha is calculated as t / (t + dT),
// where t is the low-pass filter's time-constant and
// dT is the event delivery rate.
final float alpha = 0.8;
// Isolate the force of gravity with the low-pass filter.
gravity[0] = alpha * gravity[0] + (1 - alpha) * event.values[0];
gravity[1] = alpha * gravity[1] + (1 - alpha) * event.values[1];
gravity[2] = alpha * gravity[2] + (1 - alpha) * event.values[2];
// Remove the gravity contribution with the high-pass filter.
linear_acceleration[0] = event.values[0] - gravity[0];
linear_acceleration[1] = event.values[1] - gravity[1];
linear_acceleration[2] = event.values[2] - gravity[2];
}
ENVIRONMENTAL SENSORS
• The Android platform provides four sensors that let you monitor
various environmental properties.
• You can use these sensors to monitor relative ambient humidity,
illuminance, ambient pressure, and ambient temperature near an
Android-powered device.
• All four environment sensors are hardware-based and are
available only if a device manufacturer has built them into a
device. With the exception of the light sensor, which most device
manufacturers use to control screen brightness, environment
sensors are not always available on devices.
• Because of this, it's particularly important that you verify at
runtime whether an environment sensor exists before you attempt
to acquire data from it
ENVIRONMENTAL
SENSORS
• Ambient Temperature
• Light
• Pressure
• Relative Humidity
• Temperature
• http://developer.android.com/
guide/topics/sensors/sensors
_environment.html
HOW DOES ENVIRONMENTAL
SENSORS DIFFER?
• Unlike most motion sensors and position sensors, which
return a multi-dimensional array of sensor values for each
SensorEvent, environment sensors return a single sensor
value for each data event.
• For example, the temperature in °C or the pressure in hPa.
• Also, unlike motion sensors and position sensors, which
often require high-pass or low-pass filtering, environment
sensors do not typically require any data filtering or data
processing.
POSITION SENSORS
• The Android platform provides two sensors that let you determine the
position of a device: the geomagnetic field sensor and the orientation
sensor.
• The Android platform also provides a sensor that lets you determine how
close the face of a device is to an object (known as the proximity sensor).
• The geomagnetic field sensor and the proximity sensor are hardware-
based.
• Most handset and tablet manufacturers include a geomagnetic field
sensor.
• Likewise, handset manufacturers usually include a proximity sensor to
determine when a handset is being held close to a user's face (for
example, during a phone call).
• The orientation sensor is software-based and derives its data from the
accelerometer and the geomagnetic field sensor.
POSITION SENSORS
• Magnetic Field
• Orientation
• Proximity
• http://developer.android.
com/guide/topics/sensor
s/sensors_position.html
POSITION SENSORS++
• Position sensors are useful for determining a device's physical
position in the world's frame of reference.
• For example, you can use the geomagnetic field sensor in
combination with the accelerometer to determine a device's
position relative to the magnetic North Pole.
• You can also use the orientation sensor (or similar sensor-based
orientation methods) to determine a device's position in your
application's frame of reference.
• Position sensors are not typically used to monitor device
movement or motion, such as shake, tilt, or thrust
EXAMPLES
GET SENSORMANAGER
GET A LIST OF ALL
SENSORS
GET DEFAULT SENSOR
FOR THE TYPE
MONITORING SENSOR
EVENTS
To monitor raw sensor data you need to implement two
callback methods that are exposed through the
SensorEventListener interface:
• onAccuracyChanged()
• onSensorChanged()
MONITOR SENSOR
EVENTS
• A sensor's accuracy changes
• In this case the system invokes the onAccuracyChanged()
method, providing you with a reference to the Sensor object that
changed and the new accuracy of the sensor.
• A sensor reports a new value
• In this case the system invokes the onSensorChanged()
method, providing you with a SensorEvent object. A
SensorEvent object contains information about the new sensor
data, including: the accuracy of the data, the sensor that
generated the data, the timestamp at which the data was
generated, and the new data that the sensor recorded.
EXAMPLE
QUESTIONS????

Contenu connexe

Tendances

International Journal of Engineering and Science Invention (IJESI)
International Journal of Engineering and Science Invention (IJESI)International Journal of Engineering and Science Invention (IJESI)
International Journal of Engineering and Science Invention (IJESI)inventionjournals
 
Evaluation of dynamics | Gyroscope, Accelerometer, Inertia Measuring Unit and...
Evaluation of dynamics | Gyroscope, Accelerometer, Inertia Measuring Unit and...Evaluation of dynamics | Gyroscope, Accelerometer, Inertia Measuring Unit and...
Evaluation of dynamics | Gyroscope, Accelerometer, Inertia Measuring Unit and...Robo India
 
3 axis accelorometer- ADXL345
3 axis accelorometer- ADXL3453 axis accelorometer- ADXL345
3 axis accelorometer- ADXL345Raghav Shetty
 
Sensor, Transducers and Actuator in Robotics
Sensor, Transducers and Actuator in RoboticsSensor, Transducers and Actuator in Robotics
Sensor, Transducers and Actuator in RoboticsIkram Arshad
 
Hand gesture based wheel chair for disable
Hand gesture based wheel chair for disableHand gesture based wheel chair for disable
Hand gesture based wheel chair for disablevedabobbala
 
Handheld device motion tracking using MEMS gyros and accelerometer
Handheld device motion tracking using MEMS gyros and accelerometerHandheld device motion tracking using MEMS gyros and accelerometer
Handheld device motion tracking using MEMS gyros and accelerometeranusheel nahar
 
Lecture 08 robots and controllers
Lecture 08 robots and controllersLecture 08 robots and controllers
Lecture 08 robots and controllersVajira Thambawita
 
Motion sensing and detection
Motion sensing and detectionMotion sensing and detection
Motion sensing and detectionNirav Soni
 
Accelerometer sensor
Accelerometer sensorAccelerometer sensor
Accelerometer sensorINTAKHAB KHAN
 
Velocity sensors in_robotics
Velocity sensors in_roboticsVelocity sensors in_robotics
Velocity sensors in_roboticsManish Dhiman
 
Proximity sensors
Proximity sensors Proximity sensors
Proximity sensors RajAcharya15
 
Total station Surveying
Total station SurveyingTotal station Surveying
Total station SurveyingKiran M
 

Tendances (20)

MMR sensor
MMR sensorMMR sensor
MMR sensor
 
Imu sensors
Imu sensorsImu sensors
Imu sensors
 
International Journal of Engineering and Science Invention (IJESI)
International Journal of Engineering and Science Invention (IJESI)International Journal of Engineering and Science Invention (IJESI)
International Journal of Engineering and Science Invention (IJESI)
 
Robotic Sensor
Robotic SensorRobotic Sensor
Robotic Sensor
 
Evaluation of dynamics | Gyroscope, Accelerometer, Inertia Measuring Unit and...
Evaluation of dynamics | Gyroscope, Accelerometer, Inertia Measuring Unit and...Evaluation of dynamics | Gyroscope, Accelerometer, Inertia Measuring Unit and...
Evaluation of dynamics | Gyroscope, Accelerometer, Inertia Measuring Unit and...
 
Smart sensors
Smart sensorsSmart sensors
Smart sensors
 
Total station corrections
Total station correctionsTotal station corrections
Total station corrections
 
3 axis accelorometer- ADXL345
3 axis accelorometer- ADXL3453 axis accelorometer- ADXL345
3 axis accelorometer- ADXL345
 
Accelerometer
AccelerometerAccelerometer
Accelerometer
 
Smart sensors
Smart sensorsSmart sensors
Smart sensors
 
Sensor, Transducers and Actuator in Robotics
Sensor, Transducers and Actuator in RoboticsSensor, Transducers and Actuator in Robotics
Sensor, Transducers and Actuator in Robotics
 
Hand gesture based wheel chair for disable
Hand gesture based wheel chair for disableHand gesture based wheel chair for disable
Hand gesture based wheel chair for disable
 
Handheld device motion tracking using MEMS gyros and accelerometer
Handheld device motion tracking using MEMS gyros and accelerometerHandheld device motion tracking using MEMS gyros and accelerometer
Handheld device motion tracking using MEMS gyros and accelerometer
 
Lecture 08 robots and controllers
Lecture 08 robots and controllersLecture 08 robots and controllers
Lecture 08 robots and controllers
 
Motion sensing and detection
Motion sensing and detectionMotion sensing and detection
Motion sensing and detection
 
Accelerometer sensor
Accelerometer sensorAccelerometer sensor
Accelerometer sensor
 
Zeroth review.ppt
Zeroth review.pptZeroth review.ppt
Zeroth review.ppt
 
Velocity sensors in_robotics
Velocity sensors in_roboticsVelocity sensors in_robotics
Velocity sensors in_robotics
 
Proximity sensors
Proximity sensors Proximity sensors
Proximity sensors
 
Total station Surveying
Total station SurveyingTotal station Surveying
Total station Surveying
 

Similaire à Sensors 9

Tk2323 lecture 10 sensor
Tk2323 lecture 10   sensorTk2323 lecture 10   sensor
Tk2323 lecture 10 sensorMengChun Lam
 
Robotics unit3 sensors
Robotics unit3 sensorsRobotics unit3 sensors
Robotics unit3 sensorsJanarthanan B
 
Android Training (Sensors)
Android Training (Sensors)Android Training (Sensors)
Android Training (Sensors)Khaled Anaqwa
 
roboticsunit3sensors and -201013084413.pptx
roboticsunit3sensors and -201013084413.pptxroboticsunit3sensors and -201013084413.pptx
roboticsunit3sensors and -201013084413.pptxDrPArivalaganASSTPRO
 
acceleration and velocity sensor .pptx
acceleration and velocity sensor .pptxacceleration and velocity sensor .pptx
acceleration and velocity sensor .pptxPrasannaBhalerao3
 
Android location and sensors API
Android location and sensors APIAndroid location and sensors API
Android location and sensors APIeleksdev
 
DSR_Unit-5_Sensors.pptx
DSR_Unit-5_Sensors.pptxDSR_Unit-5_Sensors.pptx
DSR_Unit-5_Sensors.pptxPuneetMathur39
 
Sensing & Actuation.pptx
Sensing & Actuation.pptxSensing & Actuation.pptx
Sensing & Actuation.pptxtaruian
 
Track 4 session 3 - st dev con 2016 - pedestrian dead reckoning
Track 4   session 3 - st dev con 2016 - pedestrian dead reckoningTrack 4   session 3 - st dev con 2016 - pedestrian dead reckoning
Track 4 session 3 - st dev con 2016 - pedestrian dead reckoningST_World
 

Similaire à Sensors 9 (20)

Week12.pdf
Week12.pdfWeek12.pdf
Week12.pdf
 
Base sensor
Base sensorBase sensor
Base sensor
 
Generic sensors for the Web
Generic sensors for the WebGeneric sensors for the Web
Generic sensors for the Web
 
Tk2323 lecture 10 sensor
Tk2323 lecture 10   sensorTk2323 lecture 10   sensor
Tk2323 lecture 10 sensor
 
Robotics unit3 sensors
Robotics unit3 sensorsRobotics unit3 sensors
Robotics unit3 sensors
 
Industrial-instrumentation.pptx
Industrial-instrumentation.pptxIndustrial-instrumentation.pptx
Industrial-instrumentation.pptx
 
Android Training (Sensors)
Android Training (Sensors)Android Training (Sensors)
Android Training (Sensors)
 
roboticsunit3sensors and -201013084413.pptx
roboticsunit3sensors and -201013084413.pptxroboticsunit3sensors and -201013084413.pptx
roboticsunit3sensors and -201013084413.pptx
 
Android Sensor System
Android Sensor SystemAndroid Sensor System
Android Sensor System
 
acceleration and velocity sensor .pptx
acceleration and velocity sensor .pptxacceleration and velocity sensor .pptx
acceleration and velocity sensor .pptx
 
Making sense
Making senseMaking sense
Making sense
 
Android location and sensors API
Android location and sensors APIAndroid location and sensors API
Android location and sensors API
 
Ioe prerequisites
Ioe prerequisitesIoe prerequisites
Ioe prerequisites
 
DSR_Unit-5_Sensors.pptx
DSR_Unit-5_Sensors.pptxDSR_Unit-5_Sensors.pptx
DSR_Unit-5_Sensors.pptx
 
Sensor's inside
Sensor's insideSensor's inside
Sensor's inside
 
WRAIR
WRAIRWRAIR
WRAIR
 
Peno sensor
Peno sensorPeno sensor
Peno sensor
 
Sensors in IOT
Sensors in IOTSensors in IOT
Sensors in IOT
 
Sensing & Actuation.pptx
Sensing & Actuation.pptxSensing & Actuation.pptx
Sensing & Actuation.pptx
 
Track 4 session 3 - st dev con 2016 - pedestrian dead reckoning
Track 4   session 3 - st dev con 2016 - pedestrian dead reckoningTrack 4   session 3 - st dev con 2016 - pedestrian dead reckoning
Track 4 session 3 - st dev con 2016 - pedestrian dead reckoning
 

Plus de Michael Shrove

Plus de Michael Shrove (8)

Android and IOS UI Development (Android 5.0 and iOS 9.0)
Android and IOS UI Development (Android 5.0 and iOS 9.0)Android and IOS UI Development (Android 5.0 and iOS 9.0)
Android and IOS UI Development (Android 5.0 and iOS 9.0)
 
Ui 5
Ui   5Ui   5
Ui 5
 
Swift 3
Swift   3Swift   3
Swift 3
 
Location based services 10
Location based services   10Location based services   10
Location based services 10
 
Storage 8
Storage   8Storage   8
Storage 8
 
Java 2
Java   2Java   2
Java 2
 
Course overview 1
Course overview   1Course overview   1
Course overview 1
 
Basics 4
Basics   4Basics   4
Basics 4
 

Sensors 9

  • 1. SENSORS CPE 490/590 – Smartphone Development by: Michael T. Shrove
  • 2. IOS
  • 3. CMMOTIONMANAGER • A CMMotionManager object is the gateway to the motion services provided by iOS. • These services provide an app with accelerometer data, rotation-rate data, magnetometer data, and other device-motion data such as attitude. • These types of data originate with a device’s accelerometers and (on some models) its magnetometer and gyroscope.
  • 4. TYPES OF MOTION SENSORS • Accelerometer • Gyroscope • Magnetometer • Device Motion (Combines all three)
  • 7.
  • 9.
  • 11.
  • 12.
  • 15. OVERVIEW • Android Sensors Overview • Types of Sensors • Motion Sensors • Environmental Sensors • Position Sensors • Introduction to Sensor Framework
  • 16. SENSORS OVERVIEW • Most Android-powered devices have built-in sensors that measure motion, orientation, and various environmental conditions. • These sensors are capable of providing raw data with high precision and accuracy, and are useful if you want to monitor three-dimensional device movement or positioning, or you want to monitor changes in the ambient environment near a device.
  • 17. SENSOR EXAMPLES • For example, a game might track readings from a device's gravity sensor to infer complex user gestures and motions, such as tilt, shake, rotation, or swing. • Likewise, a weather application might use a device's temperature sensor and humidity sensor to calculate and report the dewpoint, or a travel application might use the geomagnetic field sensor and accelerometer to report a compass bearing.
  • 18. TYPES OF SENSORS • Motion Sensors • Environmental Sensors • Position Sensors
  • 19. MOTION SENSORS • These sensors measure acceleration forces and rotational forces along three axes. • This category includes accelerometers, gravity sensors, gyroscopes, and rotational vector sensors.
  • 20. ENVIRONMENT SENSORS • These sensors measure various environmental parameters, such as ambient air temperature and pressure, illumination, and humidity. • This category includes barometers, photometers, and thermometers.
  • 21. POSITION SENSORS • These sensors measure the physical position of a device. • This category includes orientation sensors and magnetometers.
  • 22. SENSORS • You can access sensors available on the device and acquire raw sensor data by using the Android sensor framework. • For example, you can use the sensor framework to do the following: • Determine which sensors are available on a device. • Determine an individual sensor's capabilities, such as its maximum range, manufacturer, power requirements, and resolution. • Acquire raw sensor data and define the minimum rate at which you acquire sensor data. • Register and unregister sensor event listeners that monitor sensor changes.
  • 23. INTRODUCTION TO SENSOR FRAMEWORK • The Android sensor framework lets you access many types of sensors. Some of these sensors are hardware-based and some are software-based. • Hardware-based sensors are physical components built into a handset or tablet device. They derive their data by directly measuring specific environmental properties, such as acceleration, geomagnetic field strength, or angular change. • Software-based sensors are not physical devices, although they mimic hardware-based sensors. Software-based sensors derive their data from one or more of the hardware-based sensors and are sometimes called virtual sensors or synthetic sensors. • The linear acceleration sensor and the gravity sensor are examples of software-based sensors.
  • 24. SENSOR MANAGER • You can use this class to create an instance of the sensor service. • This class provides various methods for accessing and listing sensors, registering and unregistering sensor event listeners, and acquiring orientation information. • This class also provides several sensor constants that are used to report sensor accuracy, set data acquisition rates, and calibrate sensors.
  • 25. SENSOR • You can use this class to create an instance of a specific sensor. • This class provides various methods that let you determine a sensor's capabilities.
  • 26. SENSOR EVENT • The system uses this class to create a sensor event object, which provides information about a sensor event. • A sensor event object includes the following information: • the raw sensor data • the type of sensor that generated the event • the accuracy of the data • the timestamp for the event.
  • 27. SENSOR EVENTLISTENER • You can use this interface to create two callback methods that receive notifications (sensor events)z; • sensor values change • sensor accuracy changes.
  • 28. DEVICES • Few Android-powered devices have every type of sensor. • For example, most handset devices and tablets have an accelerometer and a magnetometer, but fewer devices have barometers or thermometers. • Also, a device can have more than one sensor of a given type. • For example, a device can have two gravity sensors, each one having a different range.
  • 29. MOTION SENSORS • The Android platform provides several sensors that let you monitor the motion of a device. • Two of these sensors are always hardware-based (the accelerometer and gyroscope), and three of these sensors can be either hardware-based or software- based (the gravity, linear acceleration, and rotation vector sensors).
  • 30. MOTION SENSORS • Accelerometer • Gravity • Gyroscope • Linear acceleration • Rotation Vector • http://developer.android.com/ guide/topics/sensors/sensors _motion.html
  • 31. USING THE ACCELEROMETER • An acceleration sensor measures the acceleration applied to the device, including the force of gravity. • The following code shows you how to get an instance of the default acceleration sensor: private SensorManager mSensorManager; private Sensor mSensor; ... mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
  • 32. ACCELEROMETER++ • Conceptually, an acceleration sensor determines the acceleration that is applied to a device (Ad) by measuring the forces that are applied to the sensor itself (Fs) using the following relationship: • Ad = - ∑Fs / mass • However, the force of gravity is always influencing the measured acceleration according to the following relationship: • Ad = -g - ∑F / mass
  • 33. ACCELEROMETER += 1 • For this reason, when the device is sitting on a table (and not accelerating), the accelerometer reads a magnitude of g = 9.81 m/s2. • Similarly, when the device is in free fall and therefore rapidly accelerating toward the ground at 9.81 m/s2, its accelerometer reads a magnitude of g = 0 m/s2. • Therefore, to measure the real acceleration of the device, the contribution of the force of gravity must be removed from the accelerometer data. • This can be achieved by applying a high-pass filter. • Conversely, a low-pass filter can be used to isolate the force of gravity.
  • 34. LOW PASS FILTER APPLIED public void onSensorChanged(SensorEvent event){ // In this example, alpha is calculated as t / (t + dT), // where t is the low-pass filter's time-constant and // dT is the event delivery rate. final float alpha = 0.8; // Isolate the force of gravity with the low-pass filter. gravity[0] = alpha * gravity[0] + (1 - alpha) * event.values[0]; gravity[1] = alpha * gravity[1] + (1 - alpha) * event.values[1]; gravity[2] = alpha * gravity[2] + (1 - alpha) * event.values[2]; // Remove the gravity contribution with the high-pass filter. linear_acceleration[0] = event.values[0] - gravity[0]; linear_acceleration[1] = event.values[1] - gravity[1]; linear_acceleration[2] = event.values[2] - gravity[2]; }
  • 35. ENVIRONMENTAL SENSORS • The Android platform provides four sensors that let you monitor various environmental properties. • You can use these sensors to monitor relative ambient humidity, illuminance, ambient pressure, and ambient temperature near an Android-powered device. • All four environment sensors are hardware-based and are available only if a device manufacturer has built them into a device. With the exception of the light sensor, which most device manufacturers use to control screen brightness, environment sensors are not always available on devices. • Because of this, it's particularly important that you verify at runtime whether an environment sensor exists before you attempt to acquire data from it
  • 36. ENVIRONMENTAL SENSORS • Ambient Temperature • Light • Pressure • Relative Humidity • Temperature • http://developer.android.com/ guide/topics/sensors/sensors _environment.html
  • 37. HOW DOES ENVIRONMENTAL SENSORS DIFFER? • Unlike most motion sensors and position sensors, which return a multi-dimensional array of sensor values for each SensorEvent, environment sensors return a single sensor value for each data event. • For example, the temperature in °C or the pressure in hPa. • Also, unlike motion sensors and position sensors, which often require high-pass or low-pass filtering, environment sensors do not typically require any data filtering or data processing.
  • 38. POSITION SENSORS • The Android platform provides two sensors that let you determine the position of a device: the geomagnetic field sensor and the orientation sensor. • The Android platform also provides a sensor that lets you determine how close the face of a device is to an object (known as the proximity sensor). • The geomagnetic field sensor and the proximity sensor are hardware- based. • Most handset and tablet manufacturers include a geomagnetic field sensor. • Likewise, handset manufacturers usually include a proximity sensor to determine when a handset is being held close to a user's face (for example, during a phone call). • The orientation sensor is software-based and derives its data from the accelerometer and the geomagnetic field sensor.
  • 39. POSITION SENSORS • Magnetic Field • Orientation • Proximity • http://developer.android. com/guide/topics/sensor s/sensors_position.html
  • 40. POSITION SENSORS++ • Position sensors are useful for determining a device's physical position in the world's frame of reference. • For example, you can use the geomagnetic field sensor in combination with the accelerometer to determine a device's position relative to the magnetic North Pole. • You can also use the orientation sensor (or similar sensor-based orientation methods) to determine a device's position in your application's frame of reference. • Position sensors are not typically used to monitor device movement or motion, such as shake, tilt, or thrust
  • 43. GET A LIST OF ALL SENSORS
  • 45. MONITORING SENSOR EVENTS To monitor raw sensor data you need to implement two callback methods that are exposed through the SensorEventListener interface: • onAccuracyChanged() • onSensorChanged()
  • 46. MONITOR SENSOR EVENTS • A sensor's accuracy changes • In this case the system invokes the onAccuracyChanged() method, providing you with a reference to the Sensor object that changed and the new accuracy of the sensor. • A sensor reports a new value • In this case the system invokes the onSensorChanged() method, providing you with a SensorEvent object. A SensorEvent object contains information about the new sensor data, including: the accuracy of the data, the sensor that generated the data, the timestamp at which the data was generated, and the new data that the sensor recorded.