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

Revision as of 09:59, 11 January 2021 by Registered User (→‎Project creation)
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 data logging,
  • generating the AI libraries for condition monitoring, and
  • condition monitoring of the motor setup using vibration data.

1. Requirements

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 for the data logging operation,
microSDcard.jpg
  • 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.
  • Screws: to fix the boards and the motor to the plexiglass base,
screws and nuts.png
  • Magnets and Metallic tape: to attach the STWIN on the motor setup.

1.2. Software

  • STM32 Motor Control Software Development Kit
    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
    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.
  • STM32 ST-LINK Utility
    A software interface for programming STM32 microcontrollers. This software is only required to install the prepared binaries provided in the function pack folder at the start. Note that this software will be used by not just users to install the already provided binaries but by STM32CubeIDE also to program the boards with the generated binaries.
    NOTE: This software can be downloaded from STSW-LINK004.
  • 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
    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.
  • Put the metallic strip in the center of the small board in order to attach the STWIN to the setup.
MotorWorkBench.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.

2.2. Project creation

For creating the motor, the project has to be created using the STM32 Motor Control Software Development Kit or STM32-MCSDK for short. 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.
motor control sdk define motor control project.png
creatingProjectCodeForGimBalProject.png
motorControlSDKCodeGeneration.png
importing gimbal project in IDE.png
building and flashing motor control project.png

2.3. Controlling the motor

connecting to the motor.png
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

4.1. Generating a Condition Monitoring Library

4.1.1. Contextual Datalogging
4.1.2. Data Preparation for NanoEdge AI Studio

The data logged through the datalogger is in the binary format and is not user readable in its current condition. To convert this data to a useful form, FP-AI-NANOEDG1 provides Python™ utility scripts on the path /FP-AI-NANOEDG1_V2.0.0/Utilities/AI-resources/DataLog/ as shown in the figure below.

contents of python utilities.png

The following calls to the python functions will convert the datalogs in STM32_DL_001, and STM32_DL_002 data directories to human-readable .csv files.

>> python STM_DataParser.py ./Sample-DataLogs/STM32_DL_001
>> python STM_DataParser.py ./Sample-DataLogs/STM32_DL_002 

Once the .csv files are generated for every data log, then the user needs to prepare the NanoEdge TM AI Studio compliant files. This can be achieved by issuing following python call.

>> python PrepareNEAIData.py ./Sample-DataLogs/STM32_DL_001/ ./Sample-DataLogs/STM32_DL_002/ -seqLength 1024 -sensorName IIS3DWB_ACC
Info white.png Information
NOTE: STM32_DL_001 will be used as normal data and STM32_DL_002 will be used as abnormal data.

The detailed examples for different settings of these calls and documentation are provided in the form of a Python™ Jupyter™ Notebook Parser_for_HS_Logged_Data.ipynb , in the same folder, as shown in the figure above.

4.1.3. Library generation with NanoEdge AI Studio
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

4.2.1. Learning the normal behavior

Once the STWIN is programmed with the FW with a valid library, the condition monitoring libraries are ready to be tested on the sensor board. The learning phase can be started by simply issuing a command start neai_learn in the CLI console. Starting this command will show the process of learning and will show a message on the console every time learning is performed on a new signal, as shown in the below snippet.

 
$ 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}

The process can be stopped either by issuing the

$ stop

command or by simply pressing the ESC key on the keyboard.

The learning can also be started by performing a long-press of the user button. Once the learning is happening, pressing the user button again will stop the learning process.

Info white.png Information
NOTE: For achieving the expected performances, the user should perform the learning using the same sensor configurations which were used during the data acquisition for the contextual data.
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

$ start neai_detect
NanoEdgeAI: starting

or by short pressing the user button on the sensor board. If the similarity of the current signal will be less than the threshold, the similarity will be printed on the CLI console showing the signal is an anomaly as shown in the snippet below. 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