The accelerometer is a built-in component for measuring the acceleration of any mobile device. Motions like swinging, tilting, rotating, shaking is detected using accelerometer. The value of XYZ is used to calculate and detect the motions. Besides mobile, the accelerometer is used to measure vibration on cars, machines, buildings, process control systems and safety installations.
Biologically it is used by researchers to quantify the rate at which an animal is dissipating energy in the wild by determining the limb-stroke frequency and overall dynamic body acceleration. In some medical applications, the accelerometer is deployed in pedometer for counting each step of a person involved in physical trainings like running, jogging, etc. Accelerometer used in navigator measures the motion of the person and shows the pointer in the map (as in Google map application).
Table of Contents
How to Measure Acceleration?
The accelerometer in the mobile device provides the XYZ coordinate values, which is used to measure the position and the acceleration of the device. The XYZ coordinate represents direction and position of the device at which acceleration occurred. The rotation direction and position are measured using gyroscope sensors that are found in the Android devices. The mobile device rest in the Earth includes the acceleration due to gravity (g = 9.81m/s2) and the acceleration value. The accelerometer values provided by the device normally includes the gravity as well. Accelerometer along with the linear acceleration and gyroscope will provide results close to accuracy. Linear acceleration does not include the gravity. The accelerometer value is passed into the low/high pass filters for refining the result, based on the application that has been used.
Using Accelerometer in Android Devices
The onCreate code below is for initializing the sensor manager and accelerometer sensor.
sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); sensor = sensorManager.getSensorList(Sensor.TYPE_ACCELEROMETER).get(0);
Register the sensor listener which captures the acceleration. Register in GAME mode to measure higher acceleration suits for game development, or use NORMAL mode to measure normal acceleration, or use the FASTEST mode to measure data as fast as possible.
sensorManager.registerListener(accelerationListener,sensor, SensorManager.SENSOR_DELAY_GAME);
Now the Listener is created to capture the acceleration data,
private SensorEventListener accelerationListener = new SensorEventListener() { @Override public void onAccuracyChanged(Sensor sensor, int acc) { } @Override public void onSensorChanged(SensorEvent event) { final float alpha = 0.8f; //gravity is calculated here gravityV[0] = alpha * gravityV[0] + (1 - alpha) * event.values[0]; gravityV[1] = alpha * gravityV[1] + (1 - alpha)* event.values[1]; gravityV[2] = alpha * gravityV[2] + (1 - alpha) * event.values[2]; //acceleration retrieved from the event and the gravity is removed x = event.values[0] - gravityV[0]; y = event.values[1] - gravityV[1]; z = event.values[2] - gravityV[2]; } }
All operations are done in “onSensorChanged” function. Initially the gravity is calculated so that it can be removed from acceleration values, if needed. The gravity is removed especially for accuracy in measurement of acceleration; the difference in acceleration is less when compared to readings with gravity.
The XYZ value changes for every acceleration (for every 20 ms). So the iteration of values passed into a low/high pass filter will provide the range for walking, running, jogging, etc.
1.Applications
List of field applications that use accelerometer:
- Engineering – Car, machines, buildings
- Biology – Animal dynamic body acceleration
- Industry – Turbines, pumps, fans, compressors
- Building and structures – Moving loads on bridges, earthquakes and aftershocks
- Medical application – pedometer, CRP D-Padz
- Transport – Intelligent compaction rollers, trains to detect tilts
- Volcanology – Motion of magma in active volcanoes
- Consumer electronics – Display screens, hard disk
2. Limitations
The accelerometer sensor/component is device-centric (according to manufacturer), so the accuracy of the acceleration values differs from device to device. So before building an application, you should have built your device with accelerometer by the same manufacturer. Limitations are there; but they vary based on environmental conditions.
Our Research
Contus has done a lot of research on “accelerometer in Android devices” to detect driving acceleration values. We have detected acceleration while driving for some devices like Nexus and Samsung devices. As a result, we deployed an innovative android application named “Life Saver” for one of our client. The research is not yet completed; also, we plan to give it a try in iPhones in the near future.
Maybe be more precise what is ‘gravityV’ array? How it’s init, what are initial values, etc…