on 2020-06-29 07:10 AM
Recalling the steps of the procedure to setup the Vibration detection with LSM6DSOX demo, described in the Part 1:
STEP1 . Installation of Unico and Unicleo GUI on PC
STEP2 . Download DataLogger FW project on SensorTile.box
STEP3 . Configure the LSMDSOX with Unico GUI
STEP4 . Log Motion MEMS sensor RAW data (ACC+GYR)
STEP5 . Extract the Features from log files with Unico GUI
STEP6 . Decision Tree model training on WEKA
STEP7 . Configure the LSM6DSOX MLC with Unico GUI
STEP8 . Update the STM32 FW project with new Decision Tree configuration
The model of this project has been trained using Weka tool.
Ø Launch Weka tool and push the “Explorer” button
Ø Load the ARFF file created before by pushing the “Open file…” button in the “Preprocess” panel. Once the file is open you may be able to see all the Attributes (Features and Classes) that we selected with the Unico GUI.
Ø We can now choose in Weka the desired ML algorithm, in our case the Decision Tree, by selecting “Choose >> trees >> J48”. Then Push the “Start” button.
Ø Copy and paste the information relative to the Decision Tree model trained by the Weka tool:
J48 pruned tree ------------------ F11_PeakToPeak_on_ACC_X <= 0.112 | F8_ENERGY_on_ACC_Z <= 27.4375 | | F6_ENERGY_on_ACC_X <= 0.039063: Balanced_MID (174.0) | | F6_ENERGY_on_ACC_X > 0.039063 | | | F16_PeaKDet_on_ACC_X <= 17: Balanced_MID (63.0) | | | F16_PeaKDet_on_ACC_X > 17: Balanced_HI (131.0) | F8_ENERGY_on_ACC_Z > 27.4375 | | F1_VAR_on_ACC_X <= 0.000294 | | | F16_PeaKDet_on_ACC_X <= 26: Stop (132.0) | | | F16_PeaKDet_on_ACC_X > 26: Balanced_MID (3.0/1.0) | | F1_VAR_on_ACC_X > 0.000294: Balanced_HI (29.0) F11_PeakToPeak_on_ACC_X > 0.112 | F16_PeaKDet_on_ACC_X <= 16: Unbalanced_MID (984.0) | F16_PeaKDet_on_ACC_X > 16: Unbalanced_HI (247.0) Number of Leaves : 8 Size of the tree : 15
Ø In the case it’s needed to analyze more in details the dataset used, it’s possible also to visualize in Weka some plots for the values of each Feature relative to the different classes in the “Visualize” panel.
It’s important to pay attention to the possible issue of overfitting, typical of Decision Tree algorithm: the accuracy on the training dataset may be quite high (also close to 100%) but the model may fit “too much” the data collected for the training, and may not work “so well” in the real application. To minimize this possible issue it’s important to collect a large dataset in different application/environment conditions in order to make the solution as much as possible robust to different conditions. In the case of this vibration detection demo, position of the vibration absorber has been changed for ach data log.
We need to come back now to the Unico GUI we left open and load the .txt file with the Decision Tree configuration.
Ø Click on "Next" and leave default options for the Meta-classifier
Ø You will be able to save the configuration .ucf file for the LSM6DSOX
We need now to convert the .ucf configuration file in a c source file to be updated in the STM32 project. We can use Unico GUI to do it:
Ø In the “Options” Tab push on the “C code generation...” button, load the .ucf file created before and push “Generate C code” button.
Ø A file with the same name of the .ucf file but with .h extension will be generated
Ø From the .ucf file copy and paste the table of the LSM6DSOX registers updating the one already present in the file lsm6dsox_activity_recognition_for_mobile.h:
Ac 10 00 Ac 11 00 Ac 01 80 Ac 05 00 Ac 17 40 Ac 02 11 …
The first column represents the Sensor Register Address and the second column the Value.
Ø Recompile and download the updated FW on the STM32.
Please refer to BLE Master project at THIS Github repository:
BLE master FW project for STM32F401 Nucleo board (NUCLEO-F401RE) + X-Nucleo BLE module board (X-NUCLEO-IDB05A1).
The FW projects is based on the FP-NET-BLESTAR1 Function Pack FW project for STM32, to which few modifications have been applied:
ble_master_service.c file >> GAP_Start_General_Discovery_CB function >> line 1603 manuf_data[3]==SENSOR_VIB1
sensor_service.c file >> setConnectable function >> manuf_data[26]
It's possible to check all modifications applied to original FP-NET-BLESTAR1 project by searching "Matteo" keyword in the comments to the source code.
The demo project is intended to show the capabilities of Machine Learning Core (Decision Tree)
A) Download Motor Control SDK for STM32 and install the tool:
B) Load the P-NUCLEO-IHM03 pre-loaded project “Speed ramp with Potentiometer on P-NUCLEO-IHM03 kit” and generate FW project source code for STM32G431:
C) Apply following modifications to the main.c:
#define CMD_CNTROL 1 //define 1 #define SLOW_SPEED 400 #define FAST_SPEED 1000
In the case you would like to set the speed of the motor manually with the Potentiometer present on the X-Nucleo motor driver board, you may need to set:
#define CMD_CNTROL 0 //define 1
D) Recompile and download project to the STM32 using your preferred IDE.
E) In case you have chosen to set the speed of the motor by STM32 GPIO Inputs, need to use the following ones:
Command | PC0 CN7.37 | PC3 CN7.38 |
STOP | 0 | 0 |
SLOW | 0 | 1 |
FAST | 1 | 1 |
STOP | 1 | 0 |
F) Make sure to connect also GND between Motor Nucleo Pack board and LCD panel board.
G) Apply 5V to the Nucleo board by connecting MicroUSB connector, and 12VDC power supply to the X-Nucleo board.
The EDT Smart Embedded display is visualizing information of the demo on the LCD thanks to the use of TouchGFX library. The STM32F7 is receiving information on the motor status from the UART connected to the Nucleo+X-Nucleo BLE Master board, and sending commands (relative to the press of buttons on the Touch display) to the Motor control board by GPIOs.
END OF THE ARTICLE