#define Sensor_type_accelerometer 1
//acceleration
#define Sensor_type_magnetic_field 2//Magnetic
#define Sensor_type_orientation 3//Direction
#define SENSOR_TYPE_GYROSCOPE 4//gyroscope
#define Sensor_type_light 5//light sensor
#define SENSOR_TYPE_PRESSURE 6//pressure
#define Sensor_type_temperature 7//Temperature
#define Sensor_type_proximity 8//near
#define Sensor_type_gravity 9//Gravity
#define Sensor_type_ Linear_acceleration 10//linear acceleration
#define Sensor_type_rotation_vector 11//rotation vector
1 Acceleration Sensor
The accelerometer, also called g-sensor, returns the acceleration values of the X, Y, and z triaxial axes.
The value contains the effect of gravity, the unit is m/s^2.
Put the phone flat on the desktop, the X axis defaults to the 0,y axis default 0,z axis default 9.81.
Turn the phone down on the desktop, and the z-axis is-9.81.
Tilt the phone to the left and the x-axis to positive.
Tilt the phone to the right with a negative x-axis.
Tilt the phone up and the Y axis is negative.
Tilt the phone down and the y-axis is positive.
The accelerometer may be the most mature MEMS product, and there are many kinds of accelerometer in the market.
The commonly used accelerometer in mobile phone is Bosch (Bosch) BMA series, AMK 897X series, St LIS3X series, etc.
These sensors generally provide ±2g to ±16g acceleration measurement range, using I2C or SPI interface and MCU connected, data accuracy less than 16bit.
2 Magnetic Sensors
The magnetic sensor is referred to as m-sensor and returns the environmental magnetic field data of x, Y and Z axes.
The unit of this value is the micro-Tesla (Micro-tesla), which is expressed in UT.
Units can also be Gauss (Gauss), 1tesla=10000gauss.
There is generally no independent magnetic sensor on the hardware, and the magnetic data is provided by the electronic Compass Sensor (E-COMPASS).
The Electronic Compass Sensor also provides the following direction sensor data.
3 Direction Sensor
The direction sensor is referred to as o-sensor, returns the angle data of the three axes, the unit of direction data is the angle.
In order to obtain the accurate angle data, the e-compass need to obtain the g-sensor data,
After the calculation of production o-sensor data, you can only get the horizontal direction of the angle.
The directional sensor provides three data, namely azimuth, pitch and roll.
Azimuth: Azimuth, returns the angle between the magnetic north and the Y axis at a horizontal time, ranging from 0° to 360°.
0°= North, 90°= East, 180°= South, 270°= West.
The angle between the pitch:x axis and the horizontal plane, ranging from -180° to 180°.
When the z axis rotates to the y-axis, the angle is positive.
The angle between the roll:y axis and the horizontal plane, for historical reasons, ranges from -90° to 90°.
The angle is positive when the x axis moves to the z-axis.
The electronic compass needs to be calibrated before acquiring the correct data, usually with a 8-word calibration method.
The 8-word calibration requires the user to use a device that needs to be calibrated to do 8-word shaking in the air,
In principle, as much as possible to let the device normal direction to point to all 8 quadrants of space.
The electronic compass chip used in the mobile phone has the 897X series of AKM Company, the LSM series of St Company and Yamaha company and so on.
Because of the need to read g-sensor data and compute m-sensor and o-sensor data,
Therefore, manufacturers generally provide a background daemon to complete the work, electronic compass algorithm is generally the company's private property rights.