|
实现原理: 把所有动作都拆分成几个小动作,识别的时候,只要在一定时间范围内,同事出现了这几个小动作,就把判定为一个大动作;
程序如下:
如果看不懂的话,请先看CuriePME例程,看懂例程再看这个就明白了
[kenrobot_code]
#include <CurieIMU.h>
#include <CuriePME.h>
#include <CurieBLE.h>
#include "buzzer.h"
#include "loadIMU.h"
// #include "loadIMUa.h"
// #include "SaveAndLoad.h"
Buzzer buzzer(6);
int buttonPin = 8;
void setup()
{
Serial.begin(115200);
// while(!Serial);
pinMode(buttonPin, INPUT_PULLUP);
Serial.println("test test");
CurieIMU.begin();
CuriePME.begin();
CurieIMU.setAccelerometerRate(1600);
CurieIMU.setAccelerometerRange(2);
// while(digitalRead(buttonPin)==HIGH);
// Serial.println("Training 1 begin");
// training(1,5);
// while(digitalRead(buttonPin)==HIGH);
// Serial.println("Training 2 begin");
// training(2,5);
// while(digitalRead(buttonPin)==HIGH);
// Serial.println("Training 3 begin");
// training(3,5);
// while (digitalRead(buttonPin) == HIGH);
// buzzer.bbb();
// Serial.println("Training 1 begin");
// training(1, 1);
// training(2, 1);
// training(3, 1);
// buzzer.end();
while (digitalRead(buttonPin) == HIGH);
Serial.println("Training begin");
training2(6);
// while (digitalRead(buttonPin) == HIGH);
// Serial.println("Training begin");
// training3(6);
}
void loop()
{
// while(digitalRead(buttonPin)==HIGH);
// delay(10);
byte vector[128];
readVectorFromIMU(vector);
unsigned int category = CuriePME.classify(vector, 128);
if (category == CuriePME.noMatch)
{
// Serial.println("Don't recognise that one-- try again.");
}
else
{
Serial.println(category);
}
}
// //单一动作
// void training(unsigned int currentClassification, int trainingReps)
// {
// unsigned int currentTraining = 0;
// while (currentTraining < trainingReps)
// {
// buzzer.bbb();
// byte vector[128];
// currentTraining++;
// readVectorFromIMU(vector);
// CuriePME.learn(vector, 128, currentClassification);
// buzzer.end();
// Serial.println("Got it!");
// }
// }
//连续动作
// void training2(unsigned int currentActions, int trainingReps)
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, 1);
CuriePME.learn(vector2, 128, 2);
CuriePME.learn(vector3, 128, 3);
CuriePME.learn(vector4, 128, 4);
Serial.println("Got it!");
// while(currentAction < actionsLen)
// {
// byte vector[128];
// currentAction++;
// readVectorFromIMU(vector);
// CuriePME.learn(vector, 128, currentAction);
// 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 vector[128];
// currentAction++;
readVectorFromIMU(vector);
CuriePME.learn(vector, 128, 1);
Serial.println("Got it!");
readVectorFromIMU(vector);
CuriePME.learn(vector, 128, 4);
Serial.println("Got it!");
readVectorFromIMU(vector);
CuriePME.learn(vector, 128, 5);
Serial.println("Got it!");
}
}[/kenrobot_code]
|
|