9134浏览
查看: 9134|回复: 5

[2018参赛作品] 【脑洞大赛】第6组老少爷们队

[复制链接]
本帖最后由 longxchen 于 2016-7-24 16:41 编辑

神经元探索车
用Genuino 101 (神经元)模块通过wifi带视屏和抓手的小车远程控制取物排障,基本原理见原理图。
拓展:可以用四驱飞机投放到更加复杂地形进行排障,救援工作。

神经元部分代码:

#include "BLESerial.h"
#include "CurieIMU.h"
int ax, ay, az;         // accelerometer values
int gx, gy, gz;         // gyrometer values
int calibrateOffsets = 1; // int to determine whether calibration takes place or not
#include <CurieNeurons.h>
CurieNeurons hNN;
int catL=0; // category to learn
int prevcat=0; // previously recognized category
int dist, cat, nid, nsr, ncount; // response from the neurons
//
// Variables used for the calculation of the feature vector
//
#define sampleNbr 10  // number of samples to assemble a vector
#define signalNbr  6  // ax,ay,az,gx,gy,gz
int raw_vector[sampleNbr*signalNbr]; // vector accumulating the raw sensor data
byte vector[sampleNbr*signalNbr]; // vector holding the pattern to learn or recognize
int mina=0xFFFF, maxa=0, ming=0xFFFF, maxg=0, da, dg;
void setup()
{
  pinMode(13,OUTPUT);
  Serial.begin(9600); // initialize Serial communication
  BLESerial.setName("Bluno101");
  BLESerial.begin();
  //Serial.println("Bluetooth device active, waiting for connections...");
  while(!BLESerial);
  
  //while(!Serial);   //Not need Serial while Demo zkp // wait for the serial port to open
  // initialize device
  Serial.println("Initializing IMU device...");
  CurieIMU.begin();
  // use the code below to calibrate accel/gyro offset values
  if (calibrateOffsets == 1)
  {   
    Serial.println("About to calibrate. Make sure your board is stable and upright");
    delay(5000);
    Serial.print("Starting Gyroscope calibration and enabling offset compensation...");
    CurieIMU.autoCalibrateGyroOffset();
    Serial.println(" Done");
    Serial.print("Starting Acceleration calibration and enabling offset compensation...");
    CurieIMU.autoCalibrateAccelerometerOffset(X_AXIS, 0);
    CurieIMU.autoCalibrateAccelerometerOffset(Y_AXIS, 0);
    CurieIMU.autoCalibrateAccelerometerOffset(Z_AXIS, 1);
    Serial.println(" Done");
  }
  
  // Initialize the neurons and set a conservative Max Influence Field
  hNN.Init();
  hNN.Forget(1000); //set a conservative  Max Influence Field prior to learning
  //int value=hNN.MAXIF(); // read the MAXIF back to verify proper SPI communication
  //Serial.print("\nMaxif register=");Serial.print(value);
  
  Serial.print("\n\nEntering loop...");
  Serial.print("\nMove the module vertically or horizontally...");
  Serial.print("\ntype 1 + Enter if vertical motion");
  Serial.print("\ntype 2 + Enter if horizontal motion");
  Serial.print("\ntype 0 + Enter for any other motion");
}
void loop()
{   
    // Learn if push button depressed and report if a new neuron is committed
    if (Serial.available() == 2)
    {
      catL = Serial.read();
      char inChar = (char)Serial.read();
      if (inChar == '\n')
      {
        catL = catL - 48;
        Serial.print("\nLearning motion category "); Serial.print(catL);
        // learn 5 consecutive sample vectors
        for (int i=0; i<5; i++)
        {
          getVector(); // the vector array is a global
          //Serial.print("\nVector = ");
          //for (int i=0; i<signalNbr*sampleNbr; i++) {Serial.print(vector);Serial.print("\t");}
          ncount=hNN.Learn(vector, sampleNbr*signalNbr, catL);
        }
        Serial.print("\tNeurons="); Serial.print(ncount);      
      }
    }
    else
    {
      // Recognize
      getVector(); // the vector array is a global
      hNN.Classify(vector, sampleNbr*signalNbr,&dist, &cat, &nid);
      if (cat!=prevcat && BLESerial.operator bool())
      {
        digitalWrite(13,HIGH);
        if (cat!=0x7FFF)
        {
          Serial.print("\nMotion category #"); Serial.print(cat);
          //BLESerial.write("\nMotion category # ");BLESerial.println(cat);
          switch(cat) {
            case 1: BLESerial.println("F"); break;
            case 2: BLESerial.println("B"); break;
            case 3: BLESerial.println("L"); break;
            case 4: BLESerial.println("R"); break;
            case 5: BLESerial.println("S"); break;
            default: BLESerial.println(cat); break;
          }
          delay(100);
        }
        else
        {
          Serial.print("\nMotion unknown");
          //BLESerial.write("\nMotion unknown ");     
        }
        prevcat=cat;
      }
    }
}  
void getVector()
{
  // the reset of the min and max values is optional depending if you want to
  // use a running min and max from the launch of the script or not
  mina=0xFFFF, maxa=0, ming=0xFFFF, maxg=0, da, dg;
  
  for (int sampleId=0; sampleId<sampleNbr; sampleId++)
  {
    //Build the vector over sampleNbr and broadcast to the neurons
    CurieIMU.readMotionSensor(ax, ay, az, gx, gy, gz);
   
    // update the running min/max for the a signals
    if (ax>maxa) maxa=ax; else if (ax<mina) mina=ax;
    if (ay>maxa) maxa=ay; else if (ay<mina) mina=ay;
    if (az>maxa) maxa=az; else if (az<mina) mina=az;   
    da= maxa-mina;
   
    // update the running min/max for the g signals
    if (gx>maxg) maxg=gx; else if (gx<ming) ming=gx;
    if (gy>maxg) maxg=gy; else if (gy<ming) ming=gy;
    if (gz>maxg) maxg=gz; else if (gz<ming) ming=gz;   
    dg= maxg-ming;
    // accumulate the sensor data
    raw_vector[sampleId*signalNbr]= ax;
    raw_vector[(sampleId*signalNbr)+1]= ay;
    raw_vector[(sampleId*signalNbr)+2]= az;
    raw_vector[(sampleId*signalNbr)+3]= gx;
    raw_vector[(sampleId*signalNbr)+4]= gy;
    raw_vector[(sampleId*signalNbr)+5]= gz;
  }
  
  // normalize vector
  for(int sampleId=0; sampleId < sampleNbr; sampleId++)
  {
    for(int i=0; i<3; i++)
    {
      vector[sampleId*signalNbr+i]  = (((raw_vector[sampleId*signalNbr+i] - mina) * 255)/da) & 0x00FF;
      vector[sampleId*signalNbr+3+i]  = (((raw_vector[sampleId*signalNbr+3+i] - ming) * 255)/dg) & 0x00FF;
    }
  }
}

原理图

原理图

四驱投放

四驱投放

团队

团队

hnyzcj  版主

发表于 2016-7-24 18:47:54

就是视频WIFI小车对吧
回复

使用道具 举报

longxchen  见习技师
 楼主|

发表于 2016-7-24 20:22:20

可以理解成探索神经元模块的视频WIFI小车:)
回复

使用道具 举报

Rockets  NPC

发表于 2016-7-25 19:10:22

大人小孩在一起工作什么的就是那么的有意思。
欢迎你们继续在蘑菇云里玩耍。
回复

使用道具 举报

井底添蛙  学徒

发表于 2016-7-25 20:50:31

神经元究竟是啥意思?
回复

使用道具 举报

yoyojacky  初级技匠

发表于 2016-7-27 14:12:15

好像是通过捕获神经上的生物电来驱动小车,然后进行前进后退什么的,挺有趣的。
这个我觉得很有意思,哈哈,如果机械臂能够和四轴结合起来更好玩儿吧。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
关于楼主
上海智位机器人股份有限公司 沪ICP备09038501号-4

© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail