I have tried to Implement the gesture classification model in Arduino Nano 33 BLE sense rev 2 board using. For reference I have followed the due procedure mentioned in the official website. But after acquiring the accelerometer data from the sensor and train it the due procedure I have faced a problem while compiling it in the last step. I have paste the code below and the error I am getting.
The tensor flow lite library is also giving me the problem as I was not getting the library from the official site but I found it in an github repository and intalled it from there.
Please help with the error:
#include <TensorFlowLite_ESP32.h>
#include <Arduino_BMI270_BMM150.h>
//#include <TensorFlowLite.h>
#include <tensorflow/lite/micro/all_ops_resolver.h>
#include <tensorflow/lite/micro/micro_error_reporter.h>
#include <tensorflow/lite/micro/micro_interpreter.h>
#include <tensorflow/lite/schema/schema_generated.h>
#include <tensorflow/lite/micro/system_setup.h>
//#include <tensorflow/lite/version.h>
#include "model.h"
const float accelerationThreshold = 2.5; // threshold of significant in G's
const int numSamples = 119;
int samplesRead = numSamples;
// global variables used for TensorFlow Lite (Micro)
tflite::MicroErrorReporter tflErrorReporter;
// pull in all the TFLM ops, you can remove this line and
// only pull in the TFLM ops you need, if would like to reduce
// the compiled size of the sketch.
tflite::AllOpsResolver tflOpsResolver;
const tflite::Model* tflModel = nullptr;
tflite::MicroInterpreter* tflInterpreter = nullptr;
TfLiteTensor* tflInputTensor = nullptr;
TfLiteTensor* tflOutputTensor = nullptr;
// Create a static memory buffer for TFLM, the size may need to
// be adjusted based on the model you are using
constexpr int tensorArenaSize = 8 * 1024;
byte tensorArena[tensorArenaSize] __attribute__((aligned(16)));
// array to map gesture index to a name
const char* GESTURES[] = {
"punch",
"flex"
};
#define NUM_GESTURES (sizeof(GESTURES) / sizeof(GESTURES[0]))
void setup() {
Serial.begin(9600);
while (!Serial);
// initialize the IMU
if (!IMU.begin()) {
Serial.println("Failed to initialize IMU!");
while (1);
}
// print out the samples rates of the IMUs
Serial.print("Accelerometer sample rate = ");
Serial.print(IMU.accelerationSampleRate());
Serial.println(" Hz");
Serial.print("Gyroscope sample rate = ");
Serial.print(IMU.gyroscopeSampleRate());
Serial.println(" Hz");
Serial.println();
// get the TFL representation of the model byte array
tflModel = tflite::GetModel(model);
if (tflModel->version() != TFLITE_SCHEMA_VERSION) {
Serial.println("Model schema mismatch!");
while (1);
}
// Create an interpreter to run the model
tflInterpreter = new tflite::MicroInterpreter(tflModel, tflOpsResolver, tensorArena, tensorArenaSize, &tflErrorReporter);
// Allocate memory for the model's input and output tensors
tflInterpreter->AllocateTensors();
// Get pointers for the model's input and output tensors
tflInputTensor = tflInterpreter->input(0);
tflOutputTensor = tflInterpreter->output(0);
}
void loop() {
float xAcc, yAcc, zAcc, xGyro, yGyro, zGyro;
// wait for significant motion
while (samplesRead == numSamples) {
if (IMU.accelerationAvailable()) {
// read the acceleration data
IMU.readAcceleration(xAcc, yAcc, zAcc);
// sum up the absolutes
float aSum = fabs(xAcc) + fabs(yAcc) + fabs(zAcc);
// check if it's above the threshold
if (aSum >= accelerationThreshold) {
// reset the sample read count
samplesRead = 0;
break;
}
}
}
// check if the all the required samples have been read since
// the last time the significant motion was detected
while (samplesRead < numSamples) {
// check if new acceleration AND gyroscope data is available
if (IMU.accelerationAvailable() && IMU.gyroscopeAvailable()) {
// read the acceleration and gyroscope data
IMU.readAcceleration(xAcc, yAcc, zAcc);
IMU.readGyroscope(xGyro, yGyro, zGyro);
// normalize the IMU data between 0 to 1 and store in the model's
// input tensor
tflInputTensor->data.f[samplesRead * 6 + 0] = (xAcc + 4.0) / 8.0;
tflInputTensor->data.f[samplesRead * 6 + 1] = (yAcc + 4.0) / 8.0;
tflInputTensor->data.f[samplesRead * 6 + 2] = (zAcc + 4.0) / 8.0;
tflInputTensor->data.f[samplesRead * 6 + 3] = (xGyro + 2000.0) / 4000.0;
tflInputTensor->data.f[samplesRead * 6 + 4] = (yGyro + 2000.0) / 4000.0;
tflInputTensor->data.f[samplesRead * 6 + 5] = (zGyro + 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++) {
Serial.print(GESTURES[i]);
Serial.print(": ");
Serial.println(tflOutputTensor->data.f[i], 6);
}
Serial.println();
}
}
}
}/*
IMU Capture
This example uses the on-board IMU to start reading acceleration and gyroscope
data from on-board IMU and prints it to the Serial Monitor for one second
when the significant motion is detected.
You can also use the Serial Plotter to graph the data.
The circuit:
- Arduino Nano 33 BLE or Arduino Nano 33 BLE Sense board.
Created by Don Coleman, Sandeep Mistry
Modified by Dominic Pajak, Sandeep Mistry
This example code is in the public domain.
*/
#include <Arduino_BMI270_BMM150.h>
const float accelerationThreshold = 2.5; // threshold of significant in G's
const int numSamples = 119;
int samplesRead = numSamples;
void setup() {
Serial.begin(9600);
while (!Serial);
if (!IMU.begin()) {
Serial.println("Failed to initialize IMU!");
while (1);
}
// print the header
Serial.println("xAcc,yAcc,zAcc,gX,gY,gZ");
}
void loop() {
float xAcc, yAcc, zAcc, xGyro, yGyro, zGyro;
// wait for significant motion
while (samplesRead == numSamples) {
if (IMU.accelerationAvailable()) {
// read the acceleration data
IMU.readAcceleration(xAcc, yAcc, zAcc);
// sum up the absolutes
float aSum = fabs(xAcc) + fabs(yAcc) + fabs(zAcc);
// check if it's above the threshold
if (aSum >= accelerationThreshold) {
// reset the sample read count
samplesRead = 0;
break;
}
}
}
// check if the all the required samples have been read since
// the last time the significant motion was detected
while (samplesRead < numSamples) {
// check if both new acceleration and gyroscope data is
// available
if (IMU.accelerationAvailable() && IMU.gyroscopeAvailable()) {
// read the acceleration and gyroscope data
IMU.readAcceleration(xAcc, yAcc, zAcc);
IMU.readGyroscope(xGyro, yGyro, zGyro);
samplesRead++;
// print the data in CSV format
Serial.print(xAcc, 3);
Serial.print(',');
Serial.print(yAcc, 3);
Serial.print(',');
Serial.print(zAcc, 3);
Serial.print(',');
Serial.print(xGyro, 3);
Serial.print(',');
Serial.print(yGyro, 3);
Serial.print(',');
Serial.print(zGyro, 3);
Serial.println();
if (samplesRead == numSamples) {
// add an empty line if it's the last sample
Serial.println();
}
}
}
}
The error I am getting is
C:\Users\AP\Documents\Arduino\IMU_Capture\IMU_Capture.ino:15:10: fatal error: model.h: No such file or directory
#include "model.h"
^~~~~~~~~
compilation terminated.
exit status 1Compilation error: model.h: No such file or directory