Hi need some help.
Now I have trained a model on the edge impulse using Arduino Nano ble 33 sense my project is to use accelerometer( LSM9DSI) that can recognize hand gesture when moving hand to up the car move foreword when moving hand down the car goes backsword and when i move my hand to the right the car turn right . Now I want to call this model on Arduino IDE and write a program to control the the car using of Arduino nano 33 ble sense development board. After I follow the steps in the document to convert the pulse into C + + source code, I donât know how to take the next step. I hope you can give me some advice. What can I do next?
#include <joker44project-1_inference.h>
#include <Arduino_LSM9DS1.h>
/* Constant defines -------------------------------------------------------- /
#define CONVERT_G_TO_MS2 9.80665f
#define IN1 7 //K1ăK2 motor direction
#define IN2 8 //K1ăK2 motor direction
#define IN3 9 //K3ăK4 motor direction
#define IN4 10 //K3ăK4 motor direction
#define ENA 5 // Needs to be a PWM pin to be able to control motor speed ENA
#define ENB 6 // Needs to be a PWM pin to be able to control motor speed ENA
/ Private variables ------------------------------------------------------- */
static bool debug_nn = false; // Set this to true to see e.g. features generated from the raw signal
/**
-
@brief Arduino setup function
*/
//motor control/
void go_ahead() //motor rotate clockwise -->robot go ahead
{
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
delay(2000);
}
void go_back() //motor rotate counterclockwise -->robot go back
{
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
delay(2000);
}
void turn_right(int t) //left motor rotate clockwise and right motor rotate counterclockwise -->robot turn right
{
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4,LOW);
}
/*set motor speed */
void set_motorspeed(int lspeed,int rspeed) //change motor speed
{
analogWrite(ENA,lspeed);//lspeed:0-255
analogWrite(ENB,rspeed);//rspeed:0-255
}
void setup()
{
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Edge Impulse Inferencing Demo");
if (!IMU.begin()) {
ei_printf("Failed to initialize IMU!\r\n");
}
else {
ei_printf("IMU initialized\r\n");
}
if (EI_CLASSIFIER_RAW_SAMPLES_PER_FRAME != 3) {
ei_printf("ERR: EI_CLASSIFIER_RAW_SAMPLES_PER_FRAME should be equal to 3 (the 3 sensor axes)\n");
return;
}
}
/**
-
@brief Printf function uses vsnprintf and output using Arduino Serial
-
@param[in] format Variable argument list
*/
void ei_printf(const char *format, âŚ) {
static char print_buf[1024] = { 0 };va_list args;
va_start(args, format);
int r = vsnprintf(print_buf, sizeof(print_buf), format, args);
va_end(args);if (r > 0) {
Serial.write(print_buf);
}
/L298N/
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
pinMode(ENA, OUTPUT);
pinMode(ENB, OUTPUT);set_motorspeed(255,255);
//go ahead 5s
go_ahead();
delay(2000);
//go back 5s
go_back();
delay(2000);//turn right 5s
turn_right(2000);
}
/**
- @brief Get data and run inferencing
-
@param[in] debug Get debug info if true
*/
void loop()
{
ei_printf("\nStarting inferencing in 2 secondsâŚ\n");
delay(2000);
ei_printf("Sampling...\n");
// Allocate a buffer here for the values we'll read from the IMU
float buffer[EI_CLASSIFIER_DSP_INPUT_FRAME_SIZE] = { 0 };
for (size_t ix = 0; ix < EI_CLASSIFIER_DSP_INPUT_FRAME_SIZE; ix += 3) {
// Determine the next tick (and then sleep later)
uint64_t next_tick = micros() + (EI_CLASSIFIER_INTERVAL_MS * 1000);
IMU.readAcceleration(buffer[ix], buffer[ix + 1], buffer[ix + 2]);
buffer[ix + 0] *= CONVERT_G_TO_MS2;
buffer[ix + 1] *= CONVERT_G_TO_MS2;
buffer[ix + 2] *= CONVERT_G_TO_MS2;
delayMicroseconds(next_tick - micros());
}
// Turn the raw buffer in a signal which we can the classify
signal_t signal;
int err = numpy::signal_from_buffer(buffer, EI_CLASSIFIER_DSP_INPUT_FRAME_SIZE, &signal);
if (err != 0) {
ei_printf("Failed to create signal from buffer (%d)\n", err);
return;
}
// Run the classifier
ei_impulse_result_t result = { 0 };
err = run_classifier(&signal, &result, debug_nn);
if (err != EI_IMPULSE_OK) {
ei_printf("ERR: Failed to run classifier (%d)\n", err);
return;
}
// print the predictions
ei_printf("Predictions ");
ei_printf("(DSP: %d ms., Classification: %d ms., Anomaly: %d ms.)",
result.timing.dsp, result.timing.classification, result.timing.anomaly);
ei_printf(": \n");
for (size_t ix = 0; ix < EI_CLASSIFIER_LABEL_COUNT; ix++) {
ei_printf(" %s: %.5f\n", result.classification[ix].label, result.classification[ix].value);
}
#if EI_CLASSIFIER_HAS_ANOMALY == 1
ei_printf(" anomaly score: %.3f\n", result.anomaly);
#endif
}
#if !defined(EI_CLASSIFIER_SENSOR) || EI_CLASSIFIER_SENSOR != EI_CLASSIFIER_SENSOR_ACCELEROMETER
#error âInvalid model for current sensorâ
#endif