FP-AI-NANOEDG1 V2.0 getting started

Warning white.png Warning
FP-AI-NANOEDG1 is now deprecated and not recommended for new design. It is now replaced by FP-AI-MONITOR1 to support NanoEdge™ AI Studio V3 and STM32Cube.AI libraries. Get it Now

Condition monitoring is a major component of the predictive maintenance systems, allowing production performance improvement, maintenance cost reduction, and a drastic decrease of the downtime due to routine maintenance. The FP-AI-NANOEDG1 function pack helps to jump-start the implementation and development of condition monitoring applications designed with the NanoEdge™ AI Studio solution from Cartesiam (a member of the ST Partner program).

NanoEdge™ AI Studio simplifies the creation of autonomous Machine Learning libraries with the possibility of running not just inference but also training on the edge. It facilitates the integration of predictive maintenance capabilities as well as the security and detection with sensor patterns self-learning and self-understanding, exempting users from special skills in mathematics, Machine Learning, data science, or creation and training of Neural Network.

FP-AI-NANOEDG1 implements a wired interactive CLI to configure the node, record the data, and manage the learn and detect phases. For simple operation in the field, a standalone battery-operated mode allows basic controls through the user button, without using the console.

This article provides an overview of the following topics:

  • Overview of the required hardware and software,
  • Setting up the hardware and software components,
  • Performing the vibration sensor data collection using the provided function pack,
  • Generating, Installing, and testing the NanoEdge™ AI machine learning libraries on the sensor node STEVAL-STWINKT1B using the provided function pack, and
  • Some links to useful online resources, which can help a user to better understand the project and then customize the project for his own needs.

For full user instructions of the FP-AI-NANOEDG1 please refer to this article.

Info white.png Information
NOTE: The NanoEdge™ library generation itself is out of the scope of this function pack and must be generated using NanoEdge™ AI Studio.

1 Hardware and software overview

1.1 SensorTile Wireless Industrial Node Evaluation Kit STEVAL-STWINKT1B

The STWIN SensorTile wireless industrial node (STEVAL-STWINKT1B) is a development kit and reference design that simplifies the prototyping and testing of advanced industrial IoT applications such as condition monitoring and predictive maintenance. It is powered with Ultra-low-power Arm® Cortex®-M4 MCU at 120 MHz with FPU, 2048 kbytes Flash memory (STM32L4R9). STWIN SensorTile is equipped with a microSD™ card slot for standalone data logging applications. STWIN SensorTile is equipped with a wide range of industrial IoT sensors including:

  • an ultra-wide bandwidth (up to 6 kHz), low-noise, 3-axis digital vibration sensor (IIS3DWB)
  • a 6-axis digital accelerometer and gyroscope iNEMO inertial measurement unit (IMU) with machine learning (ISM330DHCX)

and much more. Please refer to this link for all the sensors and features supported by STWIN. Other attractive features include:

  • a Li-Po battery 480 mAh to enable standalone working mode
  • STLINK-V3MINI debugger with programming cable to flash the board
  • a Plastic box for ease of placing and planting the SensorTile on the machines for condition monitoring. For further details, the users are advised to visit this link

1.2 FP-AI-NANOEDG1 Software Description

The top-level architecture of the FP-AI-NANOEDG1 function pack is shown in the following figure.

software architecture.png

2 Prerequisites and setup

2.1 HW prerequisites and setup

To use the FP-AI-NANOEDG1 function pack on STEVAL-STWINKT1B, the following hardware items are required:

  • STEVAL-STWINKT1B development kit board,
  • Windows® powered laptop/PC (Windows® 7, 8, or 10),
  • Two MicroUSB cables, one to connect the sensor-board to the PC, and another one for the STLINK-V3MINI, and
  • A microSD™ card for data logging.
required hardware.png

2.2 Software requirements

2.2.1 FP-AI-NANOEDG1

  • Download the FP-AI-NANOEDG1, package from ST website, extract and copy the .zip file contents into a folder on your PC. The package contains binaries and source code, for the sensor-board STEVAL-STWINKT1B.

2.2.2 IDE

Info white.png Information
In this document all the steps presented are carried out with STM32CubeIDE but the same can also be done with any of the other two IDEs.

2.2.3 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.
  • This software can be downloaded from STSW-LINK004.

2.2.4 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.

2.2.5 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.3 Installling the Function Pack to STWIN

2.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

2.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 Autonomous modes

The FP-AI-NANOEDG1 is equipped with extended autonomous and button-operated modes. The purpose of the extended modes is to enable the users to operate the FP-AI-NANOEDG1 on STWIN even in the absence of the CLI console. All the (default) values required for running different execution phases (datalog, learn, and detect) are provided in the FW.

3.1 Button-operated mode

In the button-operated mode, the user can start-stop different execution phases using just the user button. The following table shows the user instruction for the button-operated mode.

Button Press Description Action
SHORT_PRESS The button is pressed for less than (200 ms) and released Detect
LONG_PRESS The button is pressed for more than (200 ms) and released Learn
DOUBLE_PRESS A succession of two SHORT_PRESS in less than (500 ms) Datalog
ANY_PRESS The button is pressed and released (overlaps with the three other modes) Stop running execution phase.

The status of the current execution phase is indicated to the user through the onboard LEDs. The LEDs are allocated as the table below:

Pattern Green Orange
OFF Power OFF
ON idle System error
BLINK Data logging MicroSD™ card missing
BLINK_SHORT Detecting, no anomaly Anomaly detected
BLINK_LONG Learning, status OK Learning, status FAILED

3.2 Extended auto-mode

Other than this button-operated mode, the autonomous mode is also equipped with a special mode, called “auto-mode”. The auto-mode can be initiated automatically, at the device power-up stage or whenever a reset is performed. In this mode, the user can choose to have one or even a chain of modes/commands (up to ten commands) to run in a sequence as a list of execution steps. For example, these commands could be learning the nominal mode for a given duration and then start the detection mode for anomaly detection. Other than this, this mode can also be used to start the datalog operations or even to pause all the executions for a specific period by putting the sensor node in the "idle" phase. The auto-mode is controlled through an execution_config.json file by placing it in the root of the MicroSDTM card. The following section provides a simple example of the execution_config.json file.

3.2.1 execution_config.json

In the extended auto-mode, the execution_config.json is used to configure the chain of the execution phases and their context parameters. An example execution_config.json is presented in the snippet below.

{
	"info": {
		"version": "1.0",
		"auto_mode": false,
		"phases_iteration": 0,
		"start_delay_ms": 0,
		"execution_plan": [
			"idle"
		],
		"learn": {
			"signals": 0,
			"timer_ms": 0
		},
		"detect": {
			"signals": 0,
			"timer_ms": 0,
			"threshold": 90,
			"sensitivity": 1.0
		},
		"datalog": {
			"timer_ms": 0
		},
		"idle": {
			"timer_ms": 1000
		}
	}
}

Other than the execution_config.json, user can also place the Device_Config.json file in the root of the MicroSDTM card, in order to override the default configuration settings. Please refer to the full user manual for full details and examples.

4 FP-AI-NANOEDG1 console application

FP-AI-NANOEDG1 provides an interactive command-line interface (CLI) application. This CLI application equips a user with the ability to configure and control the sensor node, to log the vibration data using industrial-grade sensors onboard, which will be used to generate the Cartesiam NanoEdgeTM AI libraries, as well as to perform learning and (anomaly) detection operations of these AI libraries on the edge. The following sections provide a small guide on how a user can install this CLI application on a sensor board and control it through the CLI from a PC.

4.1 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.2 Data collection

Once the user has verified that the binary has been programmed successfully and the serial connection is already setup to the sensor-node, the user can start the data logging. The following section provides a basic guide for performing the data log.

4.2.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
Info white.png Information
MLC (Machine Learning Core) is not supported.

4.2.2 Logging the data

Once the sensor is configured to the wished configuration values, the data logging can be started by simply entering the command

$ start datalog

in the CLI console. While the data logging is in progress, the green light on the STWIN will be blinking to show that the data log is in progress. Once the data is logged for the required time, the process can be stopped by either pressing the Esc button on the keyboard or by typing the command

$ stop

in the CLI console. With every successful data logging command, a new data acquisition folder will be created in the SD card with the name format STM32_DL_XXX. This folder will contain for every data log a DeviceConfig.json, an AcquisitionInfo.json file, and .dat files for all the active sensors.

Note that for every sub sensor a separate .dat file is created, with naming convention SENSORNAME_SUBSENSORTYPE.dat. For example for IIS3DWB, a file is created named as IIS3DWB_ACC.dat. The JSON files contain the information for sensor configurations and acquisition specific information such as device UUID.

Info white.png Information
Note: The data logging requires a FAT32 formatted microSD card present. In the absence of the microSD card, an error will be reported on the CLI console.

5 Condition monitoring using NanoEdge AI Machine Learning library

This section provides a complete method to set up an application for condition monitoring using FP-AI-NANOEDG1. The steps are provided with brief details in the diagram below.

Flow diagram of an application using FP-AI-NANOEDG1

The details on how to set up the sensor board with a function pack as well as data collection have been already provided in the sections above. The following sections provide the details on library generation, installation, training, and testing.

5.1 Generating a condition monitoring library

The AI libraries for the condition monitoring for this function pack are generated and provided by NanoEdge AI Studio, a solution provided by Cartesiam. This section provides a step-by-step guide on how to generate these condition monitoring libraries, installing them on the sensor node by linking them to the provided project in FP-AI-NANOEDG1 and then using them to perform the condition monitoring on the edge, by running first in training and then detection mode.

5.1.1 Data logging for normal and abnormal conditions

The library generation requires some sample data to be provided to the NanoEdge AI Studio. This data will provide the context of the set up to be monitored. The first step is to log the data for the normal and abnormal conditions using the data logging application provided in this function pack.

Info white.png Information
Note: The user is required to expose the solution to all the normal and as many of the abnormal cases as they can. For detailed information, the users are invited to read the detailed documentation of the NanoEdge AI studio here.

5.1.2 Data preparation for library generation with 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

This function call will generated normalSegments.csv and abnormalSegments.csv containing the segments of the data for normal and abnormal conditions respectively. These files will be used as contextual data to optimize the selection and generation process of the NanoEdgeTM AI library in the next section.

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.

5.1.3 Library generation using NanoEdge AI Studio

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

  1. Hardware description
    1. Choosing the target platform or a microcontroller type: STEVAL-STWINKT1B Cortex-M4
    2. Maximum amount of RAM to be allocated for the library: Usually a few Kbytes will suffice (but it depends on the data frame length used in the process of data preparation, you can start with 32 Kbytes).
    3. Sensor type : 3-axis 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 (normalSegments.csv)
    2. Abnormal case (abnormalSegments.csv)
  3. Benchmarking of available models and choose the one that 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 "-mfloat-abi" has to be checked for using libraries with hardware FPU. All the other flags can be left to the default state.

Detailed documentation on the NanoEdge AI Studio.

Info white.png Information
NanoEdgeTM AI libraries can be freely generated for the evaluation purposes for STEVAL-STWINKT1B Cortex-M4, NUCLEO-F401RE Cortex-M4,NUCLEO-L432KC Cortex-M4, and STM32L562QE-DK Cortex-M33)

.

5.2 Installing the NanoEdgeAI Machine Learning library

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.

5.3 Testing the NanoEdgeAI Machine Learning library

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.

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.

5.3.1 Some hyper-parameters in condition monitoring

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.

6 Documents and related resources

  • DB4196: Artificial Intelligence (AI) condition monitoring function pack for STM32Cube
  • User Manual : User Manual for FP-AI-NANOEDG1 V2.0
  • Wiki: How to perform condition monitoring on STM32 using FP-AI-NANOEDG1
  • Getting Started with FP-AI-NANOEDG1: Getting Started with FP-AI-NANOEDG1 V1.0, at STM32L562E-DK
  • STEVAL-STWINKT1B
  • DB4345: Data brief for STEVAL-STWINKT1B.
  • UM2777: How to use the STEVALSTWINKT1B SensorTile Wireless Industrial Node for condition monitoring and predictive maintenance applications.