无法使用Arduino将IMU传感器数据输入到tflite魔术棒的修改

问题描述

我正在使用 Arduino 编写代码,用于使用 tflite 模型从来自 Adafruit_LSM6DSOX 传感器的 IMU 数据中识别手势。我正在使用函数读取数据:

bool got_data = ReadAccelerometer(error_reporter,model_input->data.f,input_length);

函数读取 50 x 6 传感器值并将它们复制到模型的输入层:

float save_data[300] = {0.0};

bool ReadAccelerometer(tflite::ErrorReporter* error_reporter,float* input,int length) {
  for (int i = 0; i < 50; ++i) { 
                                                                                    
    sensors_event_t accel;
    sensors_event_t gyro;
    sensors_event_t temp;
    
    sox.getEvent(&accel,&gyro,&temp);


    const float xa = accel.acceleration.x;
    const float ya = accel.acceleration.y;
    const float za = accel.acceleration.z;

    const float xg = gyro.gyro.x;
    const float yg = gyro.gyro.y;
    const float zg = gyro.gyro.z;



    save_data[begin_index++] = xa;
    save_data[begin_index++] = ya;
    save_data[begin_index++] = za;

    save_data[begin_index++] = xg;
    save_data[begin_index++] = yg;
    save_data[begin_index++] = zg;
    
    
    // If we reached the end of the circle buffer,reset
    if (begin_index >= 300) {
      begin_index = 0;
    }
  }

  // copy the requested number of bytes to the provided input tensor
  for (int i = 0; i < length; ++i) {
    input[i] = save_data[i];

    Serial.print(input[i]);
    Serial.print("---");
    Serial.print(input[i]);
    Serial.print("---");
  }
  return true;
}

然而, input[i] 中的值立即消失(在设置其值后的第二行)。上面的代码输出

5.83---0.00---
-1.96---0.00---
7.97---0.00---
-0.63---0.00---
0.77---0.00---
0.12---0.00---
5.88---0.00---
-2.05---0.00---
7.98---0.00---
-0.51---0.00---
0.75---0.00---
-0.21---0.00---
5.83---0.00---
-2.07---0.00---
7.99---0.00---
0.55---0.00---
-1.19---0.00---
-0.04---0.00---
5.88---0.00---
-2.01---0.00---
7.91---0.00---
0.59---0.00---
0.02---0.00---
-0.19---0.00---
5.96---0.00---
-2.05---0.00---
7.87---0.00---
-0.40---0.00---
0.75---0.00---
-0.30---0.00---
6.07---0.00---
-1.98---0.00---
7.87---0.00---
-0.52---0.00---
-0.54---0.00---
-0.09---0.00---
5.95---0.00---
-2.02---0.00---
7.91---0.00---
0.21---0.00---
-0.19---0.00---
0.01---0.00---
5.85---0.00---
-2.08---0.00---
8.07---0.00---
0.43---0.00---
0.67---0.00---
0.16---0.00---
5.90---0.00---
-2.07---0.00---
7.94---0.00---
-0.00---0.00---
-0.17---0.00---
0.10---0.00---
5.88---0.00---
-2.11---0.00---
8.05---0.00---
-0.25---0.00---
-0.67---0.00---
0.17---0.00---
5.85---0.00---
-2.08---0.00---
7.98---0.00---
-0.07---0.00---
0.38----0.00---
0.02----1.49---
6.02---ovf---
-2.09---ovf---
8.02---0.00---
0.19---ovf---
0.05---ovf---
0.00---ovf---
5.93---ovf---
-2.03---ovf---
7.93---0.00---
0.12---0.00---
-0.50---ovf---
-0.13---ovf---
5.97---ovf---
-2.08----0.00---
7.90---48.07---
-0.04---0.00---
0.07---ovf---
-0.11---ovf---
5.88---ovf---
-2.03---0.00---
7.81---48.17---
-0.12---0.00---
0.34---ovf---
-0.18---61443.26---
5.77---ovf---
-2.01---ovf---
7.94---ovf---
-0.02---ovf---
-0.24----0.00---
-0.03---ovf---
5.94---61441.25---
-2.09---ovf---
7.89---ovf---
0.02---ovf---
-0.24---ovf---

第二个值与将任何值分配给 input[i] 之前打印的值相同。 请帮助将 IMU 数据获取到输入张量的方法

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...