Getting started with FP-AI-NANOEDG1

Revision as of 09:37, 29 June 2020 by Registered User (→‎Preparing the Data)
Under construction.png The preparation of this wiki page is under progress...

This article is a quick start guide for FP-AI-NanoEdg1, which is a condition monitoring function pack using vibration sensor data using STM32Cube and STM32 microcontroller family. This article will provide a brief overview on the hardware and software used, setting the software and hardware, using the function pack to do the data collection, installing the NanoEdgeAI machine learning library and testing it, and finally the links to useful online resources which can help a user to get started.

1. Hardware and Software Review

1.1. Discovery kit with STM32L562QE MCU Hardware Description

The STM32L562E-DK Discovery kit is a complete demonstration and development platform for Arm® Cortex®-M33 with Arm® TrustZone® and ARMv8-M mainline security extension core-based STM32L562QEI6QU microcontroller, with 512 Kbytes of Flash memory and 256 Kbytes of SRAM. The key specifications of the board are

File:STM32L562E-DK.png
STM32L562E-DK Board
  • STM32L562QEI6QU microcontroller featuring 512 Kbytes of Flash memory and 256 Kbytes of SRAM
  • 1.54" 240 × 240 pixel-262K color TFT LCD module with parallel interface and touch-control pane
  • MEMS digital microphones
  • 512-Mbit Octal-SPI Flash memory
  • Bluetooth® V4.1 Low Energy module
  • iNEMO 3D accelerometer and 3D gyroscope
  • 2 user LEDs
  • User and reset push-buttons
  • Board connectors:
  • USB Type-C™
    • microSD™ card
    • Stereo headset jack including analog microphone input
    • JTAG debugger

1.2. FP-AI-NanoEdg1 Software Description

The FP-AI-NANOEDG1 function pack helps to easily jump-start the development and implementation of condition monitoring applications designed with the NanoEdge™ AI Studio solution from Cartesiam.

File:SoftwareDescription.png
Overall Software Architecture

The key features of the software are

  • Complete firmware to develop a sensor node for condition monitoring and predictive maintenance applications based on vibration data:
  • Simple LCD user interface
  • Autonomous mode controlled by user button.
  • Wired interactive command-line interface (CLI) for
    • Node configuration
    • AI utility for data logging on a microSD™ card
    • Management of the learning and detection phases of Cartesiam Machine Learning solution
  • Free, user-friendly license terms

2. Setup and Application Examples

2.1. HW prerequisites for STM32L562E-DK

To use the FP-AI-NanoEdg1 function pack on STM32L562E-DK, the user need to have following hardware items in hand:

  • 1x STM32L562E-DK development board
  • Laptop/PC with Windows 7 or later.
  • 1x USB cable to connect the PC to the Micro-B USB connector on the board CN17-STLNK
  • 1x micro SDcard for data logging operations
Hardware Required

2.2. Software and other prerequisites

2.2.1. FP-AI-NanoEdg1

  • Download the FP-AI-NANOEDG1 package from www.st.com, copy the .zip file contents into a folder on your PC. The package contains binaries and source code with project files (STM32CubeIDE only) based on STM32L562E-DK.

2.2.2. STM32CubeIDE

  • Integrated Development Environment for STM32
  • Download and install STM32CubeIDE.

2.2.3. STM32 ST-Link Utility

  • full-featured software interface for programming STM32 microcontrollers.
  • Download and install STSW-LINK004.

2.2.4. TeraTerm

  • Open source free software terminal emulator
  • Download and install TeraTerm

2.3. FP-AI-NANOEDG1 Console Application

FP-AI-NANOEDG1 provides an interactive Command Line Interface (CLI) application which lets a user to configure and control the sensor node to log the data to generate the Cartesiam NanoEdge AI libraries and then test these libraries by performing training and condition monitoring on the edge. Following sections provide small details along with image illustrations on how to use this CLI application.

2.3.1. Get the Function Pack

The first step is to get the Function Pack. The FP-AI-NANOEDG1 can be downloaded from [www.st.com| www.st.com]. Once the pack is downloaded as a zip the user has to unpack it. The following image shows the process to download and unpack the function pack as well as its contents.

Downloading and Unpacking the FP-AI-NANOEDG1

2.3.2. Flash the Application

Once the user has downloaded and unpacked the function pack the next step is to flash the sensor node with the binary of the function pack. For the convenience of the users, ST provide a pre-build binary for the project. Following image shows the steps required to flash the board.

File:flash the application.png
Steps to flash the board with FP-AI-NANOEDG1 binary

2.3.3. Use the Command Line Interface (CLI)

File:using command line interface.png
Using the Command Line Interface Application for FP-AI-NANOEDG1

3. Data Collection

Once the user has flashed the sensor node and has already connected the sensor node through the CLI, user can start doing the data log. In this section the guide for doing the data log is provided step by step.

3.1. Configure the Sensor for Data Logging

The FP-AI_NANOEDG1 provides the capability of logging the inertial data through onboard accelerometer LSM6DSO installed in STM32L562E-DK, through the console application. The CLI interface provides the user with a capability to not just log the data with the preset configurations of the sensor but also make them able to configure the sensor with the required settings. The configurable options include:

  • activate/deactivate a sensor or subsenor
  • set one of the available output data rates (ODR)
  • set one of the available full scale range

The list of available sensors can be displayed on the CLI console by entering the command $ sensor_infor . This command will show the supported sensors. The information of a supported sensor or sub-sensor can be shown by typing command $ sensor_get <sensor_id.subsensor_Id> all . Similarly, the values for any of the available configurable parameters can be set through command $ sensor_set <sensor_id.subsensor_Id> <param> <val> .

File:data logging.png
Sensor Configuration and Data logging using FP-AI-NANOEDG1

3.2. Logging the Data

Once the sensor configurations are set to the wanted values, the data logging can be started by simply entering the command $ start datalog in the console. Note that this step requires an SDcard present int he SDcard slot. The screen shows the active size of the data log in kilobytes as shown in the figure above. Once the data is logged for the required time the data logging process can be stopped by either pressing the Esc button or by typing the command $ stop in to the console.

With every datalog generated a new data folder will be created in the SDcard with the name STM32_DL_XXX, with DeviceConfig.json and LSM6DSO.dat files containing the sensor configuration and sensor data respectively.

4. Installing and Testing NanoEdgeAI Machine Learning Library

4.1. Preparing the Data

The data logged through the datalogger is in the binary format and is not user readable in its current condition. In order to convert this data to useful form, FP-AI-NANOEDG1 provides python utility scrips. These scripts along with example usage can be found in a Parser_for_HS_Logged_Data.ipynb , a Python Jupyter Notebok, located on the path FP-AI-NANOEDG1/Utilities/AI-resources/DataLog/ as shown in the figure below.

File:preparingData.png
Python Utility code for parsing and preparing the inertial data for NanoEdge AI Studio

4.2. Generating a Library with NanoEdgeAI Studio

The process of generating the libraries with Cartesiam NanoEdge AI studio consists of five steps.

  1. Hardware description
    1. Choosing a microcontroller type : ARM® Cortex® M33
    2. Maximum amount of RAM to be allocated for the library: Usually few KBs will suffice (depends on the dataframe length used in the process of data preparation.
    3. Sensor type : 3-axes accelerometer
  2. Providing the sample contextual data to adjust and gauge the performance of the chosen model. This step will require data for:
    1. Nominal or Normal case
    2. Abnormal case
  3. Benchmarking of available models and choosing the one which complies with the requirements.
  4. Validating the model for learning and testing through the provided emulator which emulates the behavior of the library on the edge.
  5. The final step is to compile and download the libraries. In this process the flag mfloatabi has to be unchecked for using libraries with hardware FPU.

4.3. Installing the Generated Library

Once the libraries are generated and downloaded from Cartesiam NanoEdge AI Studio the next step is to incroporate these libraries to FP-AI-NANOEDG1. To do so the user needs to copy and replace the existing NanoEdgeAI.h file and the libneai.afile in to the folders lib, and lib, respectively located in /FP_AI_NANOEDG1/Middlewares/Third_Party/Cartesiam_NanoEdge_AI_Library/ as shown in the figure below.

Once copied these files, to link the libraries the project needs to be rebuild and flashed to the sensor board. For this open the .project file from the FP-AI-NANOEDG1 folder, located at the path FP_AI_NANOEDG1/Projects/STM32L562E-DK/Applications/NanoEdgeConcole/STM32CubeIDE/ as shown in the step 2 in figure below. To install the new firmware after linking the library, connect the sensorboard and rebuild the project using the play button. See the console to for the outputs showing the build and programming progress. Cvheck for the build and Download successful message as shown in step 4 in the figure below. Once this message appears, the generated AI libraries are linked to the firmware on the sensor board and are ready to be tested.

File:installing and testing generated libraries.png
Installing and Testing Cartesiam generated AI libraries

4.4. Testing the Generated Library

To test the libraries on the sensor board follow the instructions available on the screen, i.e. long press to start the Learning Process and press the button again to stop. Short press the button to start the detection process. The step 5 in the figure above shows the testing process on the screen. Furthermore, these steps can also be controlled from the console application by typing $ start neai_learn and stopping it by pressing either Esc button or by typing command $ stop . Similarly the detection process can be started by started by typing in the command $ start neai_detect.

5. Documents and Related Resources