0

我正在使用 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 数据获取到输入张量的方法。

4

0 回答 0