BLE 是无限循环卡在运行模型上

问题描述

我正在关注 Arduino BLE 33 Sense 的 tutorial 以将其用作 RaspBerry Pi 上街头霸王的控制器,我尝试使用 BLE 库使其与电池无线连接,但运行时遇到问题就像两个星期,基本上它在运行模型时卡住了我不确定是不是因为蓝牙。或其他东西,但它没有向我显示手势的输出。它连接但之后它只是在串行监视器上向我显示这个:

Connecting ...

Connected

在接收所有信息的 Python 代码中,我尝试使用此代码txChar.writeValue(String(gestureid)); 并且它有效,但是当我尝试使用该模型时,不会从手势 ID 中给我任何结果。这些是没有给我模型输出的主线:

gestureid=i+1; //THIS IS THE LINE THAT IS NOT WORKING
txChar.writeValue(String(gestureid));
Serial.print(txChar.writeValue(String(gestureid)));

即使我尝试通过 BLE 连接,它也挂断了。但原因是 简单...... BLE 库是一个不会退出的 while 循环......这意味着 执行永远不会到达模型代码代码也是 无限循环。

所以我将不得不使用 C++ 的 库创建单独的线程 然后在线程之间传递数据。 但我在这方面没有太多经验,所以一些文档会很棒或任何建议。

如果有人能帮助我,我会很棒。

My full code

不工作的部分代码

void updategyroscopeLevel() {
  
  float aX,aY,aZ,gX,gY,gZ;

  // check if new acceleration AND gyroscope data is available
  if (IMU.accelerationAvailable() && IMU.gyroscopeAvailable()) {
    // read the acceleration and gyroscope data
    IMU.readacceleration(aX,aZ);
    IMU.readgyroscope(gX,gZ);

    // normalize the IMU data between 0 to 1 and store in the model's
    // input tensor
    tflInputTensor->data.f[samplesRead * 6 + 0] = (aX + 4.0) / 8.0;
    tflInputTensor->data.f[samplesRead * 6 + 1] = (aY + 4.0) / 8.0;
    tflInputTensor->data.f[samplesRead * 6 + 2] = (aZ + 4.0) / 8.0;
    tflInputTensor->data.f[samplesRead * 6 + 3] = (gX + 2000.0) / 4000.0;
    tflInputTensor->data.f[samplesRead * 6 + 4] = (gY + 2000.0) / 4000.0;
    tflInputTensor->data.f[samplesRead * 6 + 5] = (gZ + 2000.0) / 4000.0;

    samplesRead++;

    if (samplesRead == numSamples) {
      // Run inferencing
      TfLiteStatus invokeStatus = tflInterpreter->Invoke();
      if (invokeStatus != kTfLiteOk) {
        Serial.println("Invoke Failed!");
        while (1);
        return;
      }

      // Loop through the output tensor values from the model
      for (int i = 0; i < NUM_GESTURES; i++) {
        if(tflOutputTensor->data.f[i]>0.7)
        {
          gestureid=i+1; //THIS IS THE LINE THAT IS NOT WORKING
          txChar.writeValue(String(gestureid));
          Serial.print(txChar.writeValue(String(gestureid)));
        }
      }

      Serial.print(gestureid);
      gestureid=0;
      //Serial.println();
    }
  }
}

解决方法

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

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

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