使用Genuino 101神经元进行长动作的识别

1352
#include <CurieIMU.h>
#include <CuriePME.h>
#include <CurieBLE.h>
#include <SerialFlash.h>
#include <SPI.h>

#include "buzzer.h"
#include "loadIMU.h"
//#include "saveLoad.h"
//#include "loadIMUa.h"
//#include "SaveAndLoad.h"


Buzzer buzzer(6);
int buttonPin = 8;

void setup()
{
  pinMode(buttonPin, INPUT_PULLUP);
  Serial.begin(115200);
  while (!Serial);
  CurieIMU.begin();
  CuriePME.begin();
  //    pinMode(buttonPin, INPUT_PULLUP);
  //    if (digitalRead(buttonPin)==HIGH)
  //    {
  //        //加载数据,并进入识别模式
  //        // restoreNetworkKnowledge();
  //    }else
  //    {
  //        //学习数据,并存入Flash
  //        // saveNetworkKnowledge();
  //    }

  Serial.println("test test");
  CurieIMU.begin();
  CuriePME.begin();
  CurieIMU.setAccelerometerRate(1600);
  CurieIMU.setAccelerometerRange(2);


  //    while (digitalRead(buttonPin) == HIGH);
  Serial.println("Training begin===============================");
  Serial.println("3");
  delay(1000);
  Serial.println("2");
  delay(1000);
  Serial.println("1");
  delay(1000);
  Serial.println("Training begin");
  training1(5);
  Serial.println("Training begin===============================");
  Serial.println("3");
  delay(1000);
  Serial.println("2");
  delay(1000);
  Serial.println("1");
  delay(1000);
  Serial.println("Training begin");
  training2(5);
  Serial.println("Training begin===============================");
  Serial.println("3");
  delay(1000);
  Serial.println("2");
  delay(1000);
  Serial.println("1");
  delay(1000);
  Serial.println("Training begin");
  training3(5);
}
byte vector[128];
void loop()
{
  // while(digitalRead(buttonPin)==HIGH);
  // delay(10);

  readVectorFromIMU(vector);
  unsigned int category = CuriePME.classify(vector, 128);
  if (category == CuriePME.noMatch)
  {
    Serial.println("noMatch");
  }
  else
  {
    Serial.println(category);
  }
}


//连续动作识别
void training1(int trainingReps)
{
  unsigned int currentTraining = 0;
  unsigned int actionsLen = 3;
  while (currentTraining < trainingReps)
  {
    buzzer.bbb();
    currentTraining++;
    Serial.println(currentTraining);
    unsigned int currentAction = 0;
    byte vector1[128];
    byte vector2[128];
    byte vector3[128];
    //        byte vector4[128];
    readVectorFromIMU(vector1);
    readVectorFromIMU(vector2);
    readVectorFromIMU(vector3);
    //        readVectorFromIMU(vector4);
    CuriePME.learn(vector1, 128, 1);
    CuriePME.learn(vector2, 128, 2);
    CuriePME.learn(vector3, 128, 3);
    //        CuriePME.learn(vector4, 128, 4);
    Serial.println("Got it!");
    buzzer.end();
  }
}

void training2(int trainingReps)
{
  unsigned int currentTraining = 0;
  unsigned int actionsLen = 3;
  while (currentTraining < trainingReps)
  {
    buzzer.bbb();
    currentTraining++;
    Serial.println(currentTraining);
    unsigned int currentAction = 0;
    byte vector1[128];
    byte vector2[128];
    byte vector3[128];
    //        byte vector4[128];
    readVectorFromIMU(vector1);
    readVectorFromIMU(vector2);
    readVectorFromIMU(vector3);
    //        readVectorFromIMU(vector4);
    CuriePME.learn(vector1, 128, 5);
    CuriePME.learn(vector2, 128, 6);
    CuriePME.learn(vector3, 128, 7);
    //        CuriePME.learn(vector4, 128, 8);
    Serial.println("Got it!");
    buzzer.end();
  }
}

void training3(int trainingReps)
{
  unsigned int currentTraining = 0;
  unsigned int actionsLen = 3;
  while (currentTraining < trainingReps)
  {
    buzzer.bbb();
    currentTraining++;
    Serial.println(currentTraining);
    unsigned int currentAction = 0;
    byte vector1[128];
    byte vector2[128];
    byte vector3[128];
    //        byte vector4[128];
    readVectorFromIMU(vector1);
    readVectorFromIMU(vector2);
    readVectorFromIMU(vector3);
    //        readVectorFromIMU(vector4);
    CuriePME.learn(vector1, 128, 9);
    CuriePME.learn(vector2, 128, 10);
    CuriePME.learn(vector3, 128, 11);
    //        CuriePME.learn(vector4, 128, 12);
    Serial.println("Got it!");
    buzzer.end();
  }
}

 

留下一个答复

Please enter your comment!
Please enter your name here