on 2022-03-11 06:29 AM
Table of the contents
This MLC example implements the detection of the tilt angle, i.e. the current inclination of the device, in the range of -20 to +20 degrees.
Two decision trees with 255 nodes configured to detect different classes are generated- to detect the angle between the x-axis (1st decision tree) and the y-axis (2nd decision tree) and the horizontal plan.
The output can be read from the MLC0_SRC and MLC1_SRC registers and is expressed as a 8-bit value in two’s complement. The tilt angle in degrees is obtained by multiplying the output by a sensitivity of 0.15748 degrees/LSB.
For a detailed description of the configuration of the sensor involved and of the two decision trees, please refer to the Github documentation: LINK
Using Unico GUI, the accelerometer is configured with ±0.5 g full scale and 26 Hz output data rate. The reference position, when both detected tilt angles are 0 degrees, is when the x-y plane of the sensor is orthogonal to the gravity vector.
Note: the angle is measured between a sensing axis and a line formed by the intersection of the horizontal plane and the vertical plane where the sensing axis lies. Generally, the two vertical planes where the sensing axes lie are not orthogonal to each other, which is not in accordance to aeronautical nomenclature. Therefore, in applications that should meet the aeronautical definition of the roll angle, the tilt must always be applied to only one axis, while the other axis is maintained perpendicular to the gravity vector. Any tilt on the other axis reduces the magnitude of the acceleration (due to gravity) on the sensing axis, resulting in an error in the angle computation.
After the sensor has been configured, data can be acquired directly using Unico GUI, labelling the datalog in the proper way.
As important note, typical sensor errors (such as zero-g offset, sensitivity error, etc.) are not taken into account here. If a more accurate measurement is required, a calibration must be performed and then projected into the calculated threshold levels (then a program adjustment is required).
Referring to the AN5536 application note:
A 2nd order low-pass IIR filter with cutoff frequency of 5 Hz and gain = 1 (for ODR = 26 Hz) is configured to filter the accelerometer data. Two features have been used for building the decision tree: the mean of the x-axis and the mean of the y-axis of the filtered accelerometer data. The MLC runs at 26 Hz, computing features on windows of 1 sample (corresponding to 38.5 milliseconds), in order to ensure maximum responsiveness. As anticipated before, two decision trees with 255 nodes were configured to detect different classes. Each class represents a tilt angle in the given range. Meta-classifiers are not used. In order to build the decision trees, Weka tool can be used (LINK), or with a dedicated built-in program (LINK).
The output value is expressed as an 8-bit value in two’s complement corresponding to the tilt angle in the range of -20 to +20 degrees. The output is saturated (on the maximum value), when the actual tilt angle is outside the given tilt range. The tilt angle in degrees can be obtained by multiplying the output by a sensitivity of 0.15748 degrees/LSB. The configuration generates an interrupt (pulsed and active-high) on the INT1 pin every time the register MLC0_SRC (70h) is updated with a new value. The duration of the interrupt pulse is 38.5 ms in this configuration.
More details about can be found here --> LINK
The easiest way to evaluate the results is using the ProfiMEMSTool with the STEVAL-MKI209V1K and Unico GUI. Run Unico GUI and connect the ProfiMEMSTool with inserted STEVAL-MKI209V1K board to the PC by using a micro USB cable. Select IIS2ICLX from the list of Device Names, keep the "Communication with the motherboard [Enabled]" option box checked and click the Select Device button. Go to the Load/Save tab, click the Load button, browse for the generated UCF file and then click the Open button. Wait until the file is Loaded, click the Start button and open the Data window by clicking the Data button from the option panel on the left side.
The MLC output value is expressed as an 8-bit value in two’s complement and must be multiplied by the angular sensitivity mentioned in the output of the iis2iclx_tilt_angle_DT_generator.exe program (default is 0.15748 deg/LSB).
For example, in the figure above, text box 1 shows a value of 36 and text box 2 shows a value of 107. These values correspond to an inclination in the x and y axes. The values are represented as a two’s complement number, from which it can be determined that both are positive numbers. Therefore, they can be directly converted to the inclination angle value in degrees by multiplying them by the angular sensitivity:
36 * 0.15748 = 5.67 degrees 107 * 0.15748 = 16.85 degrees