First, we need to understand a basic concept: the geomagnetic sensor must work with the gravity sensor, and the compass will work properly.
I. Key points for commissioning:
1. The gravity sensor has a directivity of 3 axes, and the data output of the geomagnetic sensor is also directional. We must configure the correct position according to the position of the relative LCD view of the hardware Layout board sensor to indicate the correct orientation.
2. Mag3110 driver in the Linux bottom register, is actually registered two input devices, one is the geomagnetic equipment freescalemagnetometer, the other is the electronic compass ecompass. The latter outputs two types of data (magnetic geomagnetic and orientation directions) needed for app applications such as the compass.
3. Freescale added a service called MAGD when the system was started. When the system starts, the service checks the system for the presence of geomagnetic sensor freescalemagnetometer and gravity sensors, as well as the ecompass of the three devices (the first two actually exist, there is a specific hardware IC), if not present, then exit the services.
4. Using geomagnetic sensors, we also need to register two types of sensors in the HAL layer's Sensors.cpp: magnetic geomagnetic and orientation direction. It is also said that the upper app can see the presence of geomagnetic sensors and directional sensors.
5. Mag3110 HAL Layer Code MAGSENSOR.CPP, responsible for reading data for the input data of the Ecompass device (including magnetic geomagnetic and orientation direction), So after the freescalemagnetometer is allowed, we can see the underlying report data with the GetEvent command, but if the service does not run correctly, the data will not be read and displayed in the HAL layer if it is MAGD.
6. The correct operation of the MAGD, read the two data from the Freescalemagnetometer and Gsensor, after a series of operations (Freescale's own algorithm, the library package) to generate ecompass type of input data, The data will be correctly read and recognized by the MAG3110 HAL layer and eventually displayed in the upper app (see the accompanying drawings).
7. However, but ... Freescalemagnetometer and Gsensor These two data will generate magnetic (geomagnetic) data after being processed by Magd this serivice, but if the data is entered incorrectly (for example, Gsensor or magnetometer direction is set incorrectly, the data is inaccurate, etc.), the orientation (direction) is not generated, and the compass still does not work.
8. Because of the different magnetic field strength in each place, so we use the compass application in each place for the first time, in order to guarantee the accuracy, please use the Compass application in the "calibration" operation, otherwise there will be the problem of direction deviation. Specifically in Freescale's code, it saves/data/misc/fsl_mag.txt such a file to retain calibration parameters. While debugging, when we need to change the data size or direction configuration, it is also important to remember to first delete this file and perform a recalibration operation.
Two. Important issues in commissioning:
1. In the HAL Layer code sensorbase (NULL, "freescaleaccelerometer") instruction, the latter parameter is the input device name, must be registered with the Linux driver layer device name consistent, otherwise it will cause the HAL layer can not read the underlying data.
2. We can also launch some executable files (service services) here, in addition to the ability to read and write access to various device files in the Init.rc file. For example, we have added MAGD services.
Service MAGDSERVICE/SYSTEM/BIN/MAGD
Class Main
User root
Group Root
Onshot
Additional clarification is required:
(1) The file in the system System/bin is an executable file;
(2) How to compile a module into an executable file and place it in the system System/bin directory?
Local_module_path: = $ (target_out)/bin #设置编译后生成的模块需要存放的位置;
Local_module_class: = Executables #指定编译类型为可执行文件
Include $ (build_executable) #引入编译成可执行文件的规则
3. In the commissioning process, the compass direction is not accurate, the original FAE let check the input geomagnetic data and gravity data is correct. In the log, found that the gravity data obtained by MAGD and the actual output of the gravity sensor data is very different, further analysis found that the gravity sensor output data type int type, and the MAGD program to obtain gravity data using the short int type, This results in data being obtained only from the low 16 bits of the input data of the gravity sensor.
4. Also during the commissioning process, due to no removal of/data/misc/fsl_ Mag.txt this file, causing the system to still use the old calibration parameters each time it starts, resulting in inaccurate data, and even no orientation (direction) data output (the phenomenon seen in the Compass app interface is that the pointer remains stationary).
Drawings: Geomagnetic sensor data generation flowchart
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Freescale Geomagnetic sensor MAG3110 Debug notes