SL4A Direction Sensor

A.Coordinate System of SL4A Direction Sensor In order to describe the direction of Android phone, the coordinate system of the direction is given in Fig.1. In the figure, ABCD is a parallelogram and it is an Android phone, and near the AD edge of the phone is the phone’s HOME key. Place the phone horizontally and its screen toward the sky, AD is the tail of the phone, BC is the head of the phone, AB is the left side of the phone, DC is the right side of the phone. To facilitate the description, let’s set the AB direction for the Y axis, AD d irection for the X a xis, the screen upward direction for the Z axis. When the phone moves or rotates, these axes move or rotate along with the phone. Azimuth is defined as the angle between the AB side of the phone ,which is a vector, and the north of the earth. It can be used to indicate the direction of the head of the phone. When the phone rotates around the z axis, the angle value of the azimu th w ill ch an g e, the ang le ran g e is -180~ 18 0 d eg rees . When the phone rotates from the clockwise direction, the azimuth of the phone is positive. When the phone rotates counterclockwise, the azimuth is negative. Pitch is defined as the angle between the vector BA and the horizontal plane of the earth. Pitch is degrees of rotation around the x a xis. It can be used to indicate the tilt of the head and tail of the phone. When the phone rotates around the x axis, the pitch will change, the angle range is -180~180 degrees. When the head of the phone does not move, the tail continues to move up to the plane X0Y, the pitch is a positive value that will gradually increase from 0 to 180. When the tail of the phone does not move, the phone continues to move up to the plane X0Y, the pitch is a negative value that will gradually d ecreas e fro m 0 to -180.

Roll is defined as the angle between the CB side of the phone, which is a vector, and the horizontal plane of the earth.Roll is degrees of rotation around the y axis. It can be used to indicate the left and right tilt of the phone. When the phone rotates around the y axis, the roll will change, the angle range is -180~180 degrees. When the DC side of the phone does not move, the AB side continues to move up to the plane X0 Y, t h e ro ll is a p o s it iv e v alu e t h at wi ll g rad u ally in creas e fro m 0 to 180. When the AB side of the phone does not move, the DC side continues to move up to the plane X0Y, the roll is a n eg at iv e v alu e t h at will g rad u ally d ecreas e fro m 0 to -180.

https://codeshoppy.com/php-projects-titles-topics.html

B.The Working Process of SL4A Direction Sensor The working process of SL4A direction sensor is first to open sensor and set sensor parameters, then read data from sensor in polling mode, and finally close sensor. SL4A sensor has two important parameters A and B. Parameter A indicates which sensor data needs to be recorded . The value of the parameter A can be an integer from 1 to 4. The value of 1 indicates data for all the sensors . The value of 2 indicates only data of acceleration sensor. The value of 3 indicates data from magnetic sensor. The value of 4 indicates data of optical sensor. Since a direction sensor is simulated by a magnetic sensor and an acceleration sensor, the parameter A is set to the value of 1. Parameter B points out the minimu m interval time between two consecutive data from the same sensor. To avoid duplicate data, the min imu m interval time should be 20 millisecond. After setting the parameters of A and B, data fro m sensor specified by parameter A will be recorded every other time specified by parameter B. The data from sensor is processed as a sensor event, and the sensor event is sent to event queue to be used by application.

The unit of azimuth and pitch and roll is radians. The radians value range is from –π to π. If a mobile phone manufacturer limits magnetic sensor and acceleration sensor, then the three values of azimuth and pitch and roll will be empty. In order to allow users to experience the three values, the following formula can be used to convert radians to degrees. d eg ree=rad ian * 180 /π (1) When an application no longer needs a sensor, the application must notify SL4A to stop collecting sensor data. If the application does not do that, SL4A will continue to collect s en s o r d at a, wh ich will lead t o b at t ery en erg y lo s s p ro b lem.

Open chat