Skip to main content
Visitor II
February 5, 2025
Question

User Activity Tracking (Walking, Running, and Steady) Using LSM6DSOX

  • February 5, 2025
  • 1 reply
  • 1662 views

Hello Community,

I am currently developing a medical device and am utilizing the LSM6DSOX IMU sensor for user activity tracking. My goal is to implement functionality that can accurately track activities such as running, walking, and being steady.

To achieve this, I’ve started by working with the MLC (Machine Learning Core) example provided in the ST GitHub repository. However, despite my efforts, we are not getting any output from the implementation.

Could anyone provide guidance or suggestions on the following:

  1. Steps for implementing user activity tracking with the LSM6DSOX IMU sensor, specifically for activities like running, walking, and being steady.
  2. Common pitfalls or challenges that might cause issues like not getting output.
  3. Any best practices or recommendations for improving activity classification accuracy.

I’d appreciate any advice or tips to help move forward with this project. Looking forward to your suggestions!

 

 

    This topic has been closed for replies.

    1 reply

    Technical Moderator
    February 6, 2025

    Hi @Ggurjar98 ,

    • Collect raw accelerometer and gyroscope data for different activities (running, walking, being steady).
    • Label the data appropriately to create a dataset for training the machine learning model.
    • Use tools like Weka or Python libraries (e.g., scikit-learn) to train a decision tree model on the collected data.
    • Export the trained model in a format compatible with the MEMS Studio
    • Load the trained model into the MEMS Studio
    • Configure the MLC settings, such as input features, sensor ODR (Output Data Rate), and decision tree parameters
    • Generate the MLC configuration file and download it to the LSM6DSOX sensor
    •  

      Use the STM32CubeMX tool to generate initialization code for the LSM6DSOX sensor.
    • Write code to load the MLC configuration into the sensor and start the MLC.

    As best practices you can experiment with different features (e.g., mean, variance, FFT coefficients) derived from the raw sensor data to improve model performance. Use data augmentation techniques to artificially increase the size of your training dataset, this can help improve model robustness. Continuously collect new data and retrain the model to adapt to changes in user behavior and improve accuracy over time.

    Here is an example code snippet to initialize the LSM6DSOX sensor and read the MLC output:

    // Include necessary headers
    #include "lsm6dsox_reg.h"
    
    // Define sensor context
    stmdev_ctx_t dev_ctx;
    
    // Initialize platform-specific functions (e.g., I2C/SPI read/write)
    void platform_init(void);
    
    // Load MLC configuration
    void load_mlc_configuration(stmdev_ctx_t *ctx);
    
    // Main function
    int main(void) {
     // Initialize platform-specific functions
     platform_init();
    
     // Initialize LSM6DSOX sensor
     lsm6dsox_device_id_get(&dev_ctx, &whoamI);
     if (whoamI != LSM6DSOX_ID) {
     // Handle sensor initialization error
     }
    
     // Load MLC configuration
     load_mlc_configuration(&dev_ctx);
    
     // Main loop
     while (1) {
     uint8_t mlc_output;
     lsm6dsox_mlc_out_get(&dev_ctx, &mlc_output);
    
     // Interpret MLC output
     switch (mlc_output) {
     case 1:
     // Running
     break;
     case 2:
     // Walking
     break;
     case 3:
     // Steady
     break;
     default:
     // Unknown activity
     break;
     }
     }
    }
    
    // Function to load MLC configuration
    void load_mlc_configuration(stmdev_ctx_t *ctx) {
     // Load the MLC configuration generated by Unico GUI
     uint8_t mlc_config[] = { /* MLC configuration bytes */ };
     lsm6dsox_mlc_config_set(ctx, mlc_config, sizeof(mlc_config));
    }
    1.  
    Ggurjar98Author
    Visitor II
    February 19, 2025

    Hello,

    Thanks for your reply.

    Instead of generating the MLC configuration file using the device tree parameters, we can use the following MLC configuration file directly:

    File: LSM6DSOX Activity Recognition for Wrist

    What are the steps to use this MLC configuration file for user activity detection?

    Ggurjar98Author
    Visitor II
    February 28, 2025

    @Federica Bossi Please give me update on above replay.