Android sensor-motion sensor (4)

Source: Internet
Author: User

Linear Acceleration Sensor

The linear accelerometer uses a three-dimensional vector to provide the acceleration of each coordinate axis in the device coordinate system, but does not include gravity. The following code shows how to obtain the default linear acceleration sensor instance:

Private sensormanager msensormanager;

Private sensor msensor;

...

Msensormanager = (sensormanager) getsystemservice (context. sensor_service );

Msensor = msensormanager. getdefasensensor (sensor. type_linear_acceleration );

Conceptually, this sensor provides acceleration data based on the following relationships:

Linear acceleration = acceleration-gravity Acceleration
This sensor is usually used to obtain acceleration data without gravity impact. For example, you can use this sensor to see how fast your car is running. The linear accelerometer always has an offset. You need to delete this offset. The easiest way to do this is to create a calibration process in your application. During the calibration, you can ask the user to put the device on the desktop, read the offset of all three axes, and then subtract the corresponding offset from the data read from the accelerometer to obtain linear acceleration.
The coordinate system of the sensor is the same as that of the acceleration sensor. Its measurement unit is (m/s2 ).
Rotating Vector Sensor
The rotation vector uses a combination of angles and axes to represent the orientation of the device, that is, the angle θ of the device's rotation around the axis (X, Y, or Z. The following code shows how to obtain the default rotating vector sensor instance:
privateSensorManager mSensorManager;
privateSensor mSensor;
...
mSensorManager =(SensorManager) getSystemService(Context.SENSOR_SERVICE);
mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR);
The three rotating vector elements are expressed in the following forms:
x*sin(θ/2)
y*sin(θ/2)
z*sin(θ/2)
 
Sin (θ/2) is the number of rotations, and the orientation of the rotation axis is the direction of the rotation vector.
The three rotating vector elements are equal to one element (COS (θ/2), x * sin (θ/2), y * sin (θ/2 ), the last three parts of z * sin (θ/2. The element of the Rotated Vector is non-unit. The definition of the X, Y, and Z axes is the same as that of the accelerometer. The reference coordinate system is defined by direct orthogonal basis (1)

Figure 1. coordinate system used by the rotating vector sensor

This coordinate system has the following features:

1. the X axis is defined by the vector product yxz. It is tangent to the ground at the current position of the device and points to the east;

2. the Y axis is tangent to the ground at the current position of the device and points to the Arctic of the geomagnetic field.

3. Z points to the sky and perpendicular to the ground.

The android SDK provides an example application that demonstrates how to use a rotating vector sensor. This instance application is located in the API demos code (OS-rotationvectordemo)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.