关于使用CuriePME实现更自然动作识别的研究-Arduino中文社区 - Powered by Discuz!

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 3440|回复: 3

关于使用CuriePME实现更自然动作识别的研究

[复制链接]
发表于 2017-3-4 01:23 | 显示全部楼层 |阅读模式
实现原理: 把所有动作都拆分成几个小动作,识别的时候,只要在一定时间范围内,同事出现了这几个小动作,就把判定为一个大动作;

QQ图片20170315223457.png


程序如下:
如果看不懂的话,请先看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]

发表于 2017-6-1 13:49 | 显示全部楼层
fatal error: buzzer.h: No such file or directory
发表于 2017-6-1 15:35 | 显示全部楼层
readVectorFromIMU was not declared in this scope

点评

上面已经说了,先看库例程  详情 回复 发表于 2017-6-1 19:16
 楼主| 发表于 2017-6-1 19:16 | 显示全部楼层
迷茫的人 发表于 2017-6-1 15:35
readVectorFromIMU was not declared in this scope

上面已经说了,先看库例程
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|Archiver|手机版|Arduino中文社区

GMT+8, 2024-11-28 08:41 , Processed in 0.128037 second(s), 26 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表