Download presentation
Presentation is loading. Please wait.
Published byArthur Dalton Modified over 6 years ago
1
Android Topics Sensors Accelerometer and the Coordinate System
Accelerometer and Force Detecting Movement as a Gesture Explore a Shake motion In-class App: Shake!
2
Sensors Android devices come with a varied set of embedded sensors.
Collectively, sensors enable the creation of applications across a wide range of domains, such as gaming and healthcare.
3
What is a Sensor A sensor is a component that can measure a physical quantity. Examples of Physical Measurements: Tilt of a device Sudden movement A sensor converts a physical measurement into a signal that can be interpreted by an application.
4
Typical Sensor touchscreens accelerometers gyroscopes cameras
NOTE: A camera-based application is often enhanced by the use of an accelerometer. The orientation changes as the user rotates their device.
5
Accelerometer An accelerometer is a motion sensor.
A motion event is registered when a user moves, shakes, or tilts a device. An accelerometer provides feedback based on the coordinate system.
6
Accelerometer and the Coordinate System
The coordinate system of an Android device is defined relative to the screen of the device in its default orientation. For example, the default mode of an Android mobile phone is typically the portrait orientation. The x-axis runs in the direction of the short side of the screen. The y-axis runs in the direction of the long side of the screen and the z-axis points out of the screen.
7
Accelerometer and Force
Force = Mass * Acceleration When the accelerometer measures a zero force, the device is either still or moving at a constant speed. When the acceleration of the device is increased, such as a quick jerk of the hand, the accelerometer registers an increase in force.
8
Accelerometer and Gravity
The accelerometer can efficiently report the combined effect of gravity. It may be necessary to remove the impact of gravity from the accelerometer readings.
9
How does the Accelerometer works
The accelerometer made up of three accelerometers, one for each axis— x, y, and z. Combining all three accelerometers lets you detect accelerated force in any direction. Detecting the forces applied to a device requires the collection of accelerated movement on all three axes. This movement is measured in meters per second squared. The linear acceleration can be converted into a g-force measurement by neutralizing gravity. SensorManager.GRAVITY_EARTH. To compute a directionless g-force measurement, the Pythagorean theorem can be applied to the different acceleration axes readings.
10
Explore a Shake Action in an App
11
How would you define a “shake” action?
A “forceful” action with no specified direction. A period of rest that follows the force.
12
How is a Shake different from a Bump?
Is the force a shake or an accidental movement of the device?
13
Shake vs. Bump Determine a threshold of force - trial and error.
Compute the force and evaluate if it registers at or above the specified threshold.
14
Basic Shake Action App Considerations
Detecting a shake motion requires the use of an accelerometer. Detecting this action requires a “uses feature” to be specified in the manifest file: <uses-feature> A shake action will be a directionless force.
15
Review: How will the app use the accelerometer?
The accelerometer will measure acceleration force of the device. Acceleration force is the rate of change of the velocity of the device. Accelerometer will measure the force in meters per second squared (m/s 2 ).
16
Acceleration Forces Static? or Dynamic?
17
Static Acceleration Forces
Acceleration forces may be static, like the constant force of gravity. By measuring the amount of static acceleration due to gravity, you can find out the angle the device is tilted at with respect to the earth.
18
Dynamic Acceleration Forces
Acceleration forces may be dynamic – caused by moving or vibrating the accelerometer. By sensing the amount of dynamic acceleration, you can analyze the way the device is moving.
19
Detecting a Shake Action Gesture
This action must produce a threshold of force equal to (meters per second per second) The force will then be followed by a time lapse of 500 (milliseconds)
20
Collection of Sensor Values
Axes values are retrieved from a sensor event array: X- axis force : sensorEvent.values[0] Y- axis force : sensorEvent.values[1] Z- axis force : sensorEvent.values[1]
21
Convert each accelerometer measurement into a G-Force
Remove Earth’s gravity xForce = xForce - SensorManager.GRAVITY_EARTH yForce = yForce - SensorManager.GRAVITY_EARTH zForce = zForce - SensorManager.GRAVITY_EARTH
22
Compute Directionless Force
xForce2 + yForce2 + zForce2 xForce2 + yForce2 + zForce2 xForce2 + yForce2 + zForce2
23
What is SensorEventListener? Explore the Android documentation.
24
What is SensorEventListener?
Answer: An Interface
25
What Abstract methods are required for a SensorEventListener?
26
What Abstract methods are required for a SensorEventListener?
onSensorChanged() onAccuracyChanged()
27
Complete the Lab 7 App Construct an app that toggles a lightbulb on and off when the user shakes or jerks their device. Lab 7 NOTE: Complete all exercises from Lab 7.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.