如何解决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++ 的
如果有人能帮助我,我会很棒。
不工作的部分代码:
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 举报,一经查实,本站将立刻删除。