Ei_run_classifier returns EI_IMPULSE_DSP_ERROR

Hi @Ranchpal ,

I’ll be helping Louis with this issue. I will give you an update in two days (on Wed).

Thanks,
Alex

Hi @Ranchpal

The gist doesn’t have all of the source code. Can you upload the header files that this file includes? (More is fine too)

In the meantime, what I was looking at was IMU_BUFFER_SIZE;

What is that set to? I downloaded your model and was able to run it locally. The first step to debugging your gist is to understand how you are setting this value:

    features_signal.total_length = IMU_BUFFER_SIZE;

You should be setting features_signal.total_length to 300. (Or set IMU_BUFFER_SIZE to 300, if that makes sense).

Hi @AlexE ,

Apologies for the late reply.

The Gist contains only the file where functions relating to edge Impulse are implemented. Is there any specific thing you are looking for ?

Yes the IMU_BUFFER_SIZE is set to 300.

This is user_imu_buffer.h file

#ifndef  __USER_IMU_BUFFER_H__
#define  __USER_IMU_BUFFER_H__

#include <stdint.h>
#include <stdbool.h>
#include <string.h>

#include "lsm6dsmtr.h"

#define NUMBER_OF_SAMPLES_TO_HOP        ((uint8_t)10)
#define MAX_IMU_SAMPLES_STORED          ((uint8_t)50)
#define NUMBER_OF_ELEMENTS_IN_A_SAMPLE  ((uint8_t)6)
#define IMU_BUFFER_SIZE                 ((uint16_t)MAX_IMU_SAMPLES_STORED * NUMBER_OF_ELEMENTS_IN_A_SAMPLE) /* 50 samples. Each sample containing 6 axis data */

/** @brief A function to add sample to the buffer */
void user_imu_buffer_add_sample(lsm6dsmtr_data_t imu_sample);

/** @brief A function to remove the first 'X' number of sample from the buffer */
void user_imu_buffer_del_sample(uint16_t X);

/** @brief A function get the if the imu buffer ready to be processed */
bool is_user_imu_buffer_ready(void);

/** @brief A function to clear buffer ready to process flag */
void clr_user_imu_buffer_ready_flag(void);

/** @brief A function to get imu buffer */
void get_imu_buffer(float *p_res_buffer);

/** @brief A function to print the values in the buffer */
void print_imu_buffer(void);

This is user_ai_model.h file

#ifndef  __USER_AI_MODEL_H__
#define  __USER_AI_MODEL_H__

#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include <stdlib.h>

/* #define MAX_ELEMETS_IN_COW_STATE_BUFFER ((uint16_t)300) */
#define MAX_ELEMETS_IN_COW_STATE_BUFFER ((uint16_t)75)

/* @brief A function to get the feature data buffer */
int get_feature_data(size_t offset, size_t length, float *out_ptr) ;

/* @brief A function to run the edgeimpulse model */
/* This function takes in the 50 samples of data and return a label */
void user_ai_model_run(float *p_data, uint8_t *p_label);

/* @brief A function to add cow state to a buffer
 * This buffer would be used to get mode of the states every 60secs and update the adv data */
void user_ai_model_store_cow_state(uint8_t state);

/* @brief A function to check if the state buffer is ready to calc the mode
*/
bool is_cow_state_buffer_ready_to_calc_mode(void);

/* @brief A function clear cow state buffer ready flag
*/
void user_ai_model_clr_cow_state_buffer_ready_flag(void);

/* @brief A function to calculate the mode of the cow state
*/
uint8_t user_ai_model_calc_mode(void);


#endif //__USER_AI_MODEL_H__

Hope this helps.

Thanks,
Rakesh

Hi @Ranchpal

Since I’m running your model w/o problem on my machine, there are two possibilities:
1- I’m not invoking your model exactly the same way you are
2- There’s something going on within your device specifically that’s causing the issue

To rule out (1), I’ve pushed my test code to a fork here. I believe I’m invoking your model exactly the same way you are in your Gist, but if you can push some code to this repo and cause the -5 issue, we’ll get it fixed right away. Note, I’ve uploaded the test case as “features.txt”

For (2), here are some suggestions:

  • Your function “user_ai_model_run” looks like it should run deterministically. The input size is fixed, the get_data function is simple. This tells me that maybe you’re having a stack overflow or other memory corruption?
  • What I would do to debug this is just turn off as many interrupts, other threads, etc. Just run the classifier on gibberish and see if you get the -5 code. (input data changing shouldn’t change the error code). You’ll obviously get gibberish output too, but you shouldn’t see the error code.
  • If you can get that to run w/o issue, start turning things back on one at a time and see when you start seeing the -5 again