How to perform condition monitoring on STM32 using FP-AI-NANOEDG1

Revision as of 14:37, 20 January 2021 by Registered User (→‎Project Definition)
Under construction.png Delivery for this distribution is being prepared

The aim of this article is to provide a step-by-step guide for the readers to set up a vibration-based condition monitoring solution using STM32 sensor board. The anomaly detection AI libraries used in this tutorial will be generated using Cartesiam NanoEdge AI studio and the software used to program the sensor board can be downloaded from the ST website.

In this article you will learn:

  • setting up a motor control project,
  • programming the STWIN with FP-AI-NANOEDG1,
  • setting-up the sensor node and performing the vibration data logging using vibrometer,
  • generating the AI library for condition monitoring,
  • integrating the library to FP-AI-NANOEDG1, and programming the sensor-node for condition monitoring, and
  • condition monitoring of the motor setup using vibration data.

1. Requirements

To follow and reproduce the steps provided in this article the reader requires the following parts.

1.1. Hardware

The hardware required to reproduce this tutorial includes:

  • STEVAL-STWINKT1B
    The STWIN SensorTile wireless industrial node (STEVAL-STWINKT1B) is a development kit and reference design that simplifies prototyping and testing of advanced industrial IoT applications such as condition monitoring and predictive maintenance. For details visit the link.
stwinkt1b.jpg
  • STM32 P-NUCLEO-IHM03 Motor Control Nucleo Pack
    The P-NUCLEO-IHM03 STM32 motor-control pack is a kit composed of the X-NUCLEO-IHM16M1 board, the NUCLEO-G431RB board, a brushless Gimbal motor (GBM2804H-100T), and the DC power supply. For details visit the link.
ihm03Set.jpg
  • Misceleneous
stlink-v3mini.jpg
  • MicroSDTM card formatted as FAT32-FS for the data logging operation,
microSDcard.jpg
  • A USB MicroSDTM card reader to read the data from the MicroSDTM card to the computer.
  • 3 x Micro USB cables to connect the motor control board, STLINK-V3Mini and STWIN
microUSBCable.png
  • Plexiglass: to fix the motor, the X-NUCLEO-IHM16M1, and the NUCLEO-G431RB boards.
  • 20 cm x 15 cm
  • 9 cm x 15 cm
  • Clamps: to fix the whole set up to the table.
  • A 3D printed disc with the wholes to add the load. The 3D file can be downloaded from here
  • Screws: to fix the boards, the motor to the plexiglass base and the disc to the motor,
screws and nuts.png
Warning white.png Warning
fix the link for the 3D file to the disc, and provide an image of the disc.
Warning white.png Warning
for the screws add the image for all the screws.

1.2. Software

  • STM32CubeMX 6.0.1
    STM32CubeMX is a graphical tool that allows a very easy configuration of STM32 microcontrollers and microprocessors, as well as the generation of the corresponding initialization C code for the Arm® Cortex®-M core or a partial Linux® Device Tree for Arm® Cortex®-A core), through a step-by-step process. The software can be downloaded from here.
  • STM32 Motor Control Software Development Kit 5.4.4.
    STM32 MC SDK (motor control software development kit) firmware (X-CUBE-MCSDK and X-CUBE-MCSDK-FUL) includes the Permanent-magnet synchronous motor (PMSM) firmware library (FOC control) and the STM32 Motor Control Workbench (to configure the FOC firmware library parameters), with its graphical user interface (GUI). For details visit link.
  • FP-AI-NANOEDG1 2.0.0
    An Artificial Intelligence (AI) condition monitoring function pack for STM32Cube provides a complete firmware to program an STM32L4+ sensor node for condition monitoring and predictive maintenance applications on the STEVALSTWINKT1B SensorTile wireless industrial node. The function pack can be downloaded from
  • One of the following IDEs
Info white.png Information
In this document all the steps presented are carried out with STM32CubeIDE but the same can also be done with the other two IDEs.
  • Tera Term
    Tera Term is an open-source and freely available software terminal emulator, which is used to host the CLI of the FP-AI-NANOEDG1 through a serial connection. Users can download and install the latest version available from Tera Term.
  • NanoEdge AI Studio 2.0.1
    The function pack is to be powered by Cartesiam. For this, the user needs to generate the libraries from the NanoEdge AI Studio and then embed these libraries in the FP-AI-NANOEDG1. The Studio can be downloaded from this https://cartesiam.ai/st-developpement-board-2/. Cartesiam provides a free evaluation version for the STMicroelectronics boards.

2. Motor set up

2.1. Hardware set up

The setup process includes:

  • A two-level plexiglass base, by fixing two plexiglass pieces with the help of the spacer screws.
  • Fix the motor using double-sided tape from the left side of the smaller board.
  • Fix the G431RB and the IHM16M1 board using the provided screws in the kit with the board. For the electrical connections and jumper configuration please refer to STM32 NUCLEO IHM03 Kit User Manual
MotorWorkBench.png
  • Put the metallic strip in the center of the small board in order to attach the STWIN to the setup.
  • Insert the magnets in the STWIN plastic case.
STWIN Bottom.png
Info white.png Information
For this demonstration, we have arranged the hardware as shown in the figure below. However, the readers can arrange the setup the way it suits them.
Warning white.png Warning
Check if the combination of the cables from Gimbal matters by switching the order and seeing if the motor still runs

2.2. Motor Control Project

For controlling the motor, the motor control project can be created using the STM32 Motor Control Software Development Kit or STM32-MCSDK for short.

2.2.1. Project Definition

In this section, we show the steps to create the project and to program the motor control board with the FW in order to start, stop, or accelerate and decelerate the motor.

Step 1

The first step is to create a new project from the ST Motor Control Workbench. Here we are using version 5.4.4. To start the project click on the New Project icon, this will open a dialog as shown in the figure below.
motor control sdk define motor control project.png

Step 2

In the second step define the parameters for your motor control project. For example, for our project we are defining following parameters which fits our Nucleo-IHM03 Board kit.
  • Application type: Custom
  • System: Single Motor
  • Select Boards
    • Control: NUCELO-G431RB
    • Power: X-NUCLEO_IHM16M1-3Sh
  • Motor: GimBal GBM2804H-100T

Step 3

Once the project is defined the reader will be presented with a screen with the schematic diagram. Here the reader can start the creation of the project and code for the project definition provided in the first step. To start press the download button (1) in the toolbar, and choose a location to save the project definitions as shown in the figure below (2). Once the location is chosen, press the save button (3) to save the definitions. This will open a new dialog for C-code generation.
creatingProjectCodeForGimBalProject.png

2.2.2. C-Code Generation for Motor Control Project

To generate the C-Code for the motor control project the reader is presented with a dialog to define the settings. The figure below shows the settings:

  • STM32CubeMX: 6.0.1
  • Target ToolChain: ST STM32CubeIDE
  • Firmware Package Version: STM32 FW 1.3.0.

and then press the generate button, which will start generating the C-Code in the same directory where the definition of the projects are generated.

motorControlSDKCodeGeneration.png

Once the C-Code generation process is finished the buttons for the UPDATE' and RUN STM32CubeMX are turned Blue from Gray and the text are changed for three buttons to, OPEN FOLDER, RUN STM32CubeMX, and CLOSE respectively. Clicking on the OPEN FOLDER button will open the directory containing the C-Code just generated for the project. The structure and contents for this folder are shown in the figure above.

2.2.3. Programming the G431RB to Control the Motor

After the project is generated the project can be build and the control board can be programmed using STM32CubeIDE a free eclipse-based IDE for STM32 boards. This section explains how to load this project in CubeIDE and then build and flash it to the board.

The project can be imported in the CubeIDE following the steps shown in the figure below.

Step 1: Open the CubeIDE and click on the File menu in the Toolbar. From the list select the option for Open Projects from File System.

Step 2: Click on the directory button and navigate to the folder containing the C-code created in the section above as shown in the image.

Step 3: Go to /GimBal/STM32CubeIDE/ directory.

Step 4: Once in the right directory click the Select Folder button to close the opened dialog.

Step 5: Press the Finish Button to finish the importing process of the project in the STM32CubeIDE.

importing gimbal project in IDE.png

Once the project is imported in STM32CubeIDE the next step is to compile and install the project. The steps to compile and program are showing in the figure below.

building and flashing motor control project.png

Click on the dropdown arrow next to the Hammer icon and select Release mode for building (1). Once the project is successfully built, the Console will show a message indicating the Build Finished. 0 errors, 0 warnings. (took XYZs.XYZms), as shown in the figure above (2).

After the Build process is complete, connect the motor control board to the computer, and flash the binary of the project by simply pressing the Play button as shown in the figure step (3). Once the board is successfully programmed the console will show a message Download verified successfully as shown in step (4).

2.3. Controlling the motor

Once the control board is programmed with the project, the motor is ready to be run. Clicking on the meter icon will open the motor monitor as shown in the figure below.

connecting to the motor.png

Once the right connection parameters are chosen the connection to the motor can be established by pressing the plug button. The steps to connection are:

  • Choice of port: Port 30 (in our case)
  • Baud Rate: 115200
  • Press the connect button.

Once connected the connect icon changes to a connection and tick icon as shown in the figure below. Now the motor can be started by pressing the start button and stopped by pressing the stop button as shown in the right pan of the figure below. By default, the motor is set to be started at 522 RPM, but the speed of the motor can be changed either by rotating the knob or by entering it manually in the text box below the knob. While the motor is running the current/measured speed is also shown in the two places in the monitor as shown in the figure below, i.e. under the speed meter in the main panel and in the left panel under the monitor.

running the motor.png

3. Sensor Node Setup

3.1. Get the function pack

The first step is to get the function pack. The FP-AI-NANOEDG1 can be downloaded from ST website. Once the pack is downloaded, the user can unpack/unzip it and copy the contents to a folder on the PC. The steps of the process along with the contents of the folder are shown in the following image.

installing cli app img1.png

3.2. Flashing the application on the sensor board STEVAL-STWINKT1B

Once the package has been downloaded and unpacked, the next step is to program the sensor node with the binary of the function pack. For the convenience of the users, the function pack is equipped with a pre-built binary file of the project. The sensor board can be very easily programmed with the provided binary by simply performing a drag-and-drop action as shown in the figure below.

installing cli app img2.png

3.3. Setting up the Console

Once the sensor board is programmed with the binary of the project (as shown in section 2), the next step is to set up the serial connection of the board with the PC through the Tera Term. To do so, start Tera Term, and create a new connection by either selecting from the toolbar, select the proper port to establish the serial communication with the board. In the figure below, this is COM10 - USB Serial Device (COM 10).

tera term connection port choice.png

Set the following parameters:

tera term connection new line.png

Once the connection is made the user will see a message like below. If this message does not appear, the user can try to reset the board, to make this message appear.

STWIN FP-AI-NANOEDG1 welcome message stubbed.png
Info white.png Information
NOTE: The message This is a stubbed version, please install Nanoe Edge AI library! shows that the FW is currently using a stub for an actual library and the user needs to generate a valid library using NanoEdgeTM AI Studio and replace the stubbed library with that. Once this is done this warning message will disappear.

Typing help will show the list of all available commands.

4. Condition Monitoring using an AI library generated with NanoEdge AI Studio

The process of condition monitoring using FP-AI-NANOEDG1 is described in the following diagram.

flow diagram.png

Readers have already seen how to program the sensor-board with FP-AI-NANOEDG1, let us see step by step in this section how to perform the rest of the steps.

4.1. Generating a Condition Monitoring Library

In this section, we perform the steps to generate a condition monitoring library with the help of NanoEdge AI Studio to monitor the motor running in a balanced condition. Assumptions:

  • In normal conditions, the motor should run at one of the three speeds [1000, 1250, 1500] RPM.
  • Motor running in unbalanced condition (unbalance introduced with a weight, i.e. a screw in the disc) or motor stopped or impacts or taps on the motor platform base are abnormalities and should be detected when running the condition monitoring phase.

4.1.1. Contextual Datalogging

NanoEdge AI studio requires the user to provide some contextual data in order to provide the best libraries which will fit the setup of the user to be monitored. This data is not used for the learning of the libraries but just the initialization and choosing of the library from a big pool of available solutions. This section describes the process of the sample data acquisition for normal and abnormal conditions.

4.1.1.1. Configure the sensor for data logging

Through the CLI interface, a user can configure the supported sensors on the sensor-board and can log the data with these sensors. In the ISM330DHCX sensor, there are multiple sub-sensors to log acceleration and gyrometer data. These sub-sensors can be individually configured. The configurable options for these sensors and sub sensors include:

  • Activate/deactivate the sensor or a sub-sensor,
  • Set an output data rate (ODR) from the list of available options,
  • Set full-scale range from the list of available options.

The list of all the supported sensors and sub-sensors can be displayed on the CLI console by entering the command:

$ sensor_info

This command will print the ids for the supported sensors with sub-sensors. The detailed information of a given supported sensor or sub-sensor can be shown by typing command:

$ sensor_get <sensor_id.sub-sensor_id> all

Similarly, the values for any of the available configurable parameters can be set through command

$ sensor_set <sensor_id.sub-sensor_id> <param> <val>
sensor configuration.png

In this article we will use the IIS3DWB sensor which is a high bandwidth accelerometer capable of logging the data at ODR (output data rate) of 26.6 kHz, but readers can perform the same procedure with the other sensor ISM330DHCX too, at there desired ODR (one of the supported ODRs).

Info white.png Information
MLC (Machine Learning Core) is not supported.

The first step is to configure the sensor. In order to do so, the user has to reset the sensor-board and set up the sensor IIS3DWB execute the following set of commands.

$ reset
-----------------------------------------------------------------
! This is a stubbed version, please install NanoEdge AI library!
-----------------------------------------------------------------
Console command server.
Type 'help' to view a list of registered commands.

$ sensor_set 0.0 enable 1
sensor 0.0: enable

$ sensor_set 0.0 fullScale 4
sensor fullScale: 4.000000

$ sensor_get 0.0 all
enable = true
ODR = 26667.000000 Hz, measured ODR = 0.000000 Hz
Availabe ODRs:
 26667.000000 Hz
fullScale = 4.000000 g
Available fullScales:
 2.000000 g
 4.000000 g
 8.000000 g
 16.000000 g
$
4.1.1.2. Normal Data Logging

The NanoEdge AI studio requires the use the provide the contextual data for both normal and abnormal conditions. In this section, we will record the normal data for the motor at three different speeds 1000, 1250, and 1500 RPM. NanoEdge AI studio requires only the contextual data, we do not need much data. CLI application for the FP-AI-NANOEDG1 also provides the option of the timed data log. In this example, we will acquire data for just 4 seconds for each condition. In order to do the data log, the reader needs to set the datalog timer the user can set the timer variable and confirm it is set as below:

$ datalog_set timer 4000
data log: timer set to 4000 ms

$ datalog_get timer
data log: timer = 4000 ms
$

The data log can be performed as below:

  1. Run the motor and set the Sensor_board on the motor base as shown in the figure of motor setup in section 2.
  2. Change the speed of the motor to the required speed.
  3. start datalog
  4. Wait for the datalog to stop and then repeat from steps 2 to 4 until all the three speeds are recorded.
4.1.1.3. Abnormal Data Logging

To record the abnormal data we will present the data for the motor running at three different speeds in the unbalance condition. To introduce the unbalance we have added a screw on the disc as shown in the figure below.

unbalanced wheel.png

Log the data for the three speeds for unbalanced conditions following the same steps described in the section above.

4.1.2. Data Preparation for NanoEdge AI Studio

The data logging in section 4.1.1. will generate six data logging folders named as STM_DL_00X where X keeps on incrementing for every new datalog. In order to use these datalogs for the generation of the NanoEdge AI library, the data needs to be prepared and processed in a defined way to generate the normal and abnormal data files for NanoEdge AI Studio.

To facilitate the readers, FP-AI-NANOEDG1 provides sample code examples and datasets for the GimBal motor at the aforementioned three speeds. The Python code examples along with the data can be found at the path /FP-AI-NANOEDG1_V2.0.0/Utilities/AI_resources/Datalog/. The codes are provided in this as a Jupyter Notebook named as FP-AI-NANOEDG1-HSD-Utilities.ipynb and the sample datasets are in the subdirectory ./Sample-DataLogs/. These scripts expect the reader to arrange the data as below. As the first three logs correspond to data for three speeds in normal condition, these are grouped into balanced folder and the other three are grouped under unbalanced. Both the normal and abnormal data are placed in a single folder named GimBalData. The details are shown in the figure below.

normalAndAbnormalDataOrganization.png

Each of the data logging folders contains three files, AcquisitionInfo.json, DeviceConfig.json, and IIS3DWB_ACC.dat. These files contain the details of the acquisition info, the sensor configurations, and binary formatted data for the sensor IIS3DWB. The data as shown in the figure below is in the form of binary and is not useable as it is. In order to process and shape the data in NanoEdge AI compliant format, Python utility code is provided in the form of a Jupyter Notebook in FP-AI-NANOEDG1. Following section details, the process of generating human-readable CSV files for each of the acquisitions as well as creating segments of the data and reshaping them to provide to NanoEdge AI studio.

4.1.2.1. Parsing the .dat files into CSV files

The Jupyter Notebook FP-AI-NANOEDG1_V2.0.0UtilitiesAI_resourcesDataLog/FP-AI-NANOEDG1-HSD-Utilities.ipynb contains all the required code for the data manipulation for this article. The reader just has to run section 3, named Playing with actual data for PdM to generate NEAI libraries.

In order to use this python script to prepare the data for the GimBal monitoring the user needs to copy the data folder GimBalData created using the instructions provided in the above section, at the path FP-AI-NANOEDG1_V2.0.0UtilitiesAI_resourcesDataLog/Sample-DataLogs/GimBalData/.

Once the data is copied, the user can modify the variable called dataFolder and put the relative path to the data folder as, dataFolder = ./Samples-DataLogs/GimBalData/. Running this section will generate the CSV files for all the six data logs. Each folder will now contain a .csv file named as IIS3DWB_ACC.csv.

This snippet is provided AS IS, and by taking it, you agree to be bound to the license terms that can be found here for the component: Application.
# 3.1 Parsing the data for all speeds and conditions
import Utilities_FP_AI_NanoEdgeAi as UNEAI
dataFolder = './Sample-DataLogs/IIS3DWB/' # to be replaced with the new data folder
conditions = [ 'balanced', 'unbalanced' ]
speeds = [ 1000, 1250, 1500 ]
sensorName = 'IIS3DWB'
for cdn in conditions:
    for spd in speeds:
        UNEAI.DataParser('{}{}/{}RPM/'.format( dataFolder, cdn, spd ), sensorName = sensorName )
4.1.2.2. Creating the Segments for normal and abnormal data for NanoEdge AI Studio

Once the CSV files are generated for all the data acquisitions the next step is to form the data segments to present as normal and abnormal data to NanoEdge AI studio. In order to model the normal and abnormal behavior of the system, we can not just use one sample as it is too short and impulsive, but we want to model the behavior over a window or frame of the samples. Similarly, using too long a sequence length result in long delays and non-real-time behavior. To find a compromise in this demo we are using a sequence length of 1024 samples.

NanoEdge AI Studio expects the data of a sequence or frame to be vectorized in the following order.

dataFormatingNEAIStudio.png

In order to do so, the reader can simply use the code provided in section 3.2 of the Jupyter notebook. All that is required is to change the name of the normal and abnormal data directories, in the line as shown in the snippet below.

This snippet is provided AS IS, and by taking it, you agree to be bound to the license terms that can be found here for the component: Application.
seqLength = 1024 # length of the segments
seqStep = 1024 # controls the overlap
dataDir = './Sample-DataLogs/IIS3DWB/'    # replace it with dataDir = './Sample-DataLogs/GimBalData/' 
normalDataFileName = 'normalSegments.csv'
abnormalDataFileName = 'abnormalSegments.csv'
sensorName = 'IIS3DWB' # change it to the sensor name you are using ISM330DHCX
normalDataDir = dataDir + 'balanced/'
abnormalDataDir =  dataDir + 'unbalanced/'
subSensorName = sensorName + '_ACC' # change _ACC with _GYR if using Gyro sensor instead of Acc

normalDataSeqs, abnormalDataSeqs = UNEAI.PrepareCSVs( normalDataDir = normalDataDir, abnormalDataDir = abnormalDataDir, 
                                                     sensorName = sensorName, frameLength = seqLength, seqStep = seqStep,
                                                     normalDataFileName = normalDataFileName, abnormalDataFileName = abnormalDataFileName)
print('Files have been prepared with following details.')
print('Number of normal samples : ', normalDataSeqs.shape[0])
print('Number of abnormal samples : ', abnormalDataSeqs.shape[0])

Running this section will generate two csv files named as normalSegments.csv and abnormalSegments.csv containing frames for normal and abnormal data, at the path /FP-AI-NANOEDG1_V2.0.0/Utilities/AI_resources/Datalog/. In the next section, we explain how to use these files to generate the AI libraries from NanoEdge AI Studio. As an indication, if these files are creating following exactly the same steps, the number of normal and abnormal frames will be around 310 to 312.

4.1.3. Library generation with NanoEdge AI Studio

NanoEdge AI studio provides an automatic way to generate and select the best libraries for the condition monitoring of your setup based on the provided contextual data (normal and abnormal conditions). The main view of NanoEdge AI Studio looks like below.

4.1.3.1. Open the NanoEdge AI Studio

There are four panes in the main View of NanoEdge AI Studio.

1) Existing Projects in the Workspace: A new project can be created from here or an existing project can be loaded.
2) Project Definition of the new project.
3) Tips for defining the project.
4) Tutorials. This section contains the links and videos of the existing tutorials.
NanoEdgeAiStudioView.png
4.1.3.2. Create a new project

For creating a new project the reader needs to provide the following information.

Project type:: Two project types are available in NanoEdge AI studio.
  • Anomaly Detection: This project expects the data for normal and abnormal behavior and builds a library that lets us perform Anomaly Detection.
  • Anomaly Classification: This project builds a library to perform the classification of the provided classes. This expects to input a file of data for every class.
Name: Provide a name for the project to save for future references.
Description: Provide a name for the project to save for future references.
Target: Selects one of the target platforms to deploy the generated library.
Max RAM: : Define a max RAM budget in KBS for the library. The generated library will fit within this RAM budget.
NEAI projectCreation.png
Info white.png Information
NanoEdge AI Studio is freely available for STMicroelectronics boards including, NUCELO-F401RE Cortex-M4, NUCLEO-L432KC Cortex-M4, STM32L562QE-DK Corte- M33, and STEVAL-STWINKT1B Cortex-M4.
4.1.3.3. Import the normal data in NanoEdge AI Studio
NEAI importNormalSegments.png

Once the project is created, it expects contextualization data for normal and abnormal conditions for generating an anomaly detection library. This section explains the process of importing a normal data file.

Step 1: Click on the Choose Signals button, this will open a dialog titled Import your Signal.

Step 2: Select the type of delimiter in your data file. In our case, we have a comma-separated version of the data file so we are selecting the option for Comma.

Step 3: Click on the button Select file and choose the file to be imported. This will load the first 20 lines of the data in the file in the Preview window as shown in the figure above.

Step 4: Validate the choice of the data file by click on the Validate import button.

This will bring back you to the second step of the library generation process for anomaly detection and show a preview of the data statistics for each of the three-axes, namely mean (average) and std (Standard deviation of the data segments).

4.1.3.4. Import the abnormal data in NanoEdge AI Studio

Go to section 3 and import the data for the abnormal condition following the steps used for normal data. These steps can also be seen in the figure below.

NEAI importAbnormalSegments.png
4.1.3.5. Create the Benchmark for Creating the AI Library

Once the data for the normal and abnormal conditions have been loaded, the process for selecting and optimizing the best library for the condition monitoring can be performed in section 4 of the NanoEdge Ai Studio project creation. To start the Optimize and Benchmark process go to step 4 and press the start button. This will show a dialog by plotting the axis of the data for normal and abnormal conditions side by side. Press the Validate button and start the process of the Optimization and Benchmarking .

NEAI BenchmarkingScreen.png

While the optimization is running the view of the NanoEdge AI studio looks like below. The optimization takes place based on three Key Performance Indicators (KPIs).

  • Balanced Accuracy
  • Confidence
  • RAM

During the process of optimization, these figures are shown in real-time, as numbers in (1), (2), and (3) as well as a graph in (5). The graph in (4) provides the separation of the normal and abnormal data based on the current library under optimization, showing normal data in blue and abnormal in red. (6) shows a warning that the library has more confidence once the metrics in (1), (2) are above 90%.

The process of benchmarking can be stopped either by clicking on the Stop button next to the progress bar (if the performances have reached the required standards) or it will automatically stop once the convergence is achieved by the Studio. Upon stopping the benchmark view will show the performance of the selected library, along with an indication to tell how many minimum calls are to be made to learn a normal phenomenon.

NEAIStudioBenchmarkFinished.png
Info white.png Information
Experiments shows that in order to achieve good performances the readers require to provide the learning frames equal to 4 to 5 times the minimum iteration

.

4.1.3.6. Compiling and downloading the library

The generated libraries can then be downloaded in Step 6 by selecting the right values for the compilation as shown in the figure below.

Step 1: Choose the benchmark to be used as the library. In case there are multiple benchmarks generated, users will have a choice to choose any of the benchmarks for which they want to generate the library.

Step 2: Select if the generated library is to be used in a multi-library environment. This option lets users deploy multiple libraries on a single MCU. If the users require this function they can specify a tag for each of the libraries in order to have a dedicated namespace for the APIs. This is out of the scope of this article so users can leave it unchecked.

Step 3: Check the flag named as -mfloat-abi. Leaving it unchecked goes for "soft" option and causes GCC to generate output containing library calls for floating-point operations. "hard" allows the generation of floating-point instructions and uses FPU-specific calling convention.

Leave the other flags unchecked and press the Compile button. Select, Development version or Production version based on your requirements, i.e. if you want to use the library for testing/prototyping purposes or for production respectively and press download the library.

NEAILibraryGeneration.png

The detailed documentation on the NanoEdge AI studio can be found at https://cartesiam-neai-docs.readthedocs-hosted.com/studio/studio.html.

4.1.4. Linking the library with FP-AI-NANOEDG1

Once the libraries are generated and downloaded from Cartesiam NanoEdge AI Studio, the next step is to incorporate these libraries to FP-AI-NANOEDG1. The FP-AI-NANOEDG1, comes with the library stubs in the place of the actual libraries generated by NanoEdge AI Studio. This is done to make it easy for users to link the generated libraries and have a place holder for the libraries, which are generated by following the steps provided in the previous section. In order to link the actual libraries, the user needs to copy the generated libraries and replace the existing stub/dummy libraries and header files NanoEdgeAI.h, and libneai.a files present in the folders Inc, and lib, respectively. The relative paths of these folders are /FP_AI_NANOEDG1_V2.0.0/Middlewares/Third_Party/Cartesiam_NanoEdge_AI_Library/ as shown in the figure below.

linking libraries.png

Once these files are copied, the project must be reconstructed and programmed on the sensor board to link the libraries. For this, the user needs to open the .project file from the FP-AI-NANOEDG1 folder, located at the path /FP_AI_NANOEDG1_V2.0.0/Projects/STM32L4R9ZI-STWIN/Applications/NanoEdgeConcole/STM32CubeIDE/ as shown in the step 2 in figure below.

programming FW after linking libraries.png

To install the new firmware after linking the library, connect the sensor board, and rebuild the project using the play button. See the console for the outputs and wait for the Build and Download success message as shown in step 4 in the figure below.

programming FW after linking libraries 2.png

Once the sensor-board is programmed successfully, the following welcome message will appear in the CLI (Tera Term terminal). If the message does not appear you can try to reset the board by pressing the RESET button.

STWIN FP-AI-NANOEDG1 welcome message library.png
Info white.png Information
NOTE: As one can see the welcome message is now included with a message saying Powered by NanoEdge AI library! . This denotes that now the library stub has been replaced with an actual library generated using NanoEdgeTM AI Studio.

4.2. Condition monitoring

Once the STWIN is programmed with the FW with the suitable AI library generated and downloaded from NanoEdge AI Studio, the condition monitoring libraries are ready to be tested on the sensor board.

4.2.1. Learning the normal behavior

The first step is to learn the normal conditions. In order to do so, we have to provide the normal data for all three speeds. The first step is to set the sensor configurations. The sensor is to be configured with the same parameters as it was at the time of the data logging for contextual data. So we need to enable the sensor 0.0 and set its fullScale value to 4. As below:

NEAILearning.png

The learning phase can be started by simply issuing a command start neai_learn in the CLI console. However, CLI of FP-AI-NANOEDG1 also provides a capability of controlled learning. These options include specifying a time period or number of signal frames for learning and detection. The process goes like described in the figure in Learning Phase. The number of signals for NanoEdge AI context can be provided by simply issuing a command $ neai_set signals 40. This will stop the learning process automatically once the learning has been performed on 40 signals as shown in the figure. The reason for choosing 40 signals is that the minimum iterations for the library were 10 and we have to perform learning on 4 or 5 times the data. The same process has to be repeated while the motor is running at three speeds.

The process goes like this Step 1: Run the motor at one of the three speeds. Step 2: Start learning the behavior using $ start neai_learn command. Step 3: Change the speed and repeat step 2 until all the speeds are learned.

4.2.2. Condition Monitoring

Once the normal conditions are learned, the user can start the condition monitoring process by starting the neai_detect mode. This mode can be started by issuing the command

$ neai_set signals 0
NanoEdge AI: signals set to 0
$ start neai_detect
NanoEdgeAI: starting

or by short pressing the user button on the sensor board. Issuing the command $ neai_set signals 0 will remove the limit on the number of signals to be used for inference and will keep the detection mode running until stopped manually.

During the process of condition monitoring whenever the similarity of the signal drops lesser than 90% there will a line shown in the console showing the id of the signal, a condition (anomaly) and the similarity of the signal in the format {"signal": id, "similarity": XX, "status": anomaly}. Nothing will be printed in the CLI console if the similarity is higher than 90% to the normal signals. Other than this the orange LED will blink fast (alternating 200 msec on-off sequence) to show the anomaly is detected.

4.2.3. Fine Tuning of Library

For the convenience of the users, the CLI application also provides some handy options to fine-tune the inference and learning process of the condition monitoring easily. Users can see all the variables they can play with by issuing the following command:

$ neai_get all
NanoEdgeAI: signals = 0
NanoEdgeAI: sensitivity = 1.000000
NanoEdgeAI: threshold = 95
NanoEdgeAI: timer = 0

Each of the these parameters can be configured using neai_set <param> <val> command. The details are provided in the command table above. This section provides small details on neai_set signals <nr of signals> . Using this command, a user can start the learning or condition monitoring mode for a given number of samples. For example, to learn on 100 signals, the user can issue this command, before issuing the learn command. In the following snippet, an example is presented where the learning is performed for 10 signals.

$ neai_set signals 10
NanoEdge AI: signals set to 10

$ start neai_learn
NanoEdgeAI: starting

$ {"signal": 1, "status": success}
{"signal": 2, "status": success}
{"signal": 3, "status": success}
{"signal": 4, "status": success}
{"signal": 5, "status": success}
{"signal": 6, "status": success}
{"signal": 7, "status": success}
{"signal": 8, "status": success}
{"signal": 9, "status": success}
{"signal": 10, "status": success}
NanoEdge AI: stopped

The threshold parameter is used to report the anomalies. For any signal which has similarities below the threshold value is reported as anomaly. The default value used in the CLI application is 90. Users can change this value by using neai_set threshold <val> command.

The sensitivity parameter is used as an emphasis parameter. The default value is set to 1. Increasing this sensitivity will mean that the matching of the signals is to be performed more strictly, reducing it will also reduce the matching calculation process, i.e. resulting in higher matching values.

Info white.png Information
Note: For good performance, the user is required to expose all the normal conditions to the sensor-board during the learning, and library generation process, i.e. in case of motor monitoring the required speeds and ramps that are required to be monitored should be exposed.

For details, users are invited to read the detailed documentation of NanoEdge AI studio.

5. Resources