主控板主要提供智能数据分析,根据分析的结果通过串口发送控制命令给小车驱动板,小车驱动板根据控制命令控制小车的动作,主控板采用Java平台,集成相关领域的开源解决方案,软件系统主要包括如下:   微信图片_20210117163003  
  1. 底盘驱动:根据控制命令控制4个电机的控制
  2. 听觉系统:采用Sphinx4开源语音识别框架,识别语音数据
  3. 视觉系统:采用JavaCV图像识别来分析小车所看到的内容,做到目标跟踪
  4. 语音合成系统:采用FreeTTS语音合成技术,合成语音数据,
  5. 舵机控制系统:通过采集的视觉和语音数据,控制舵机,一开始只是控制摄像头的左右上下活动
  6. 传感器系统:系统安装温度、湿度、光感、人体感知等传感器,主控器根据传感器数据做出相应的动作
  1.底盘驱动 底盘采用Arduino+电机驱动板,代码比较简单,从串口接收命令,控制四个马达驱动,Arduino代码如下:  
#include <AFMotor.h>

#include <Servo.h>

AF_DCMotor Rback_motor(1);   
AF_DCMotor Rfront_motor(2);
AF_DCMotor Lback_motor(4);
AF_DCMotor Lfront_motor(3);

int maxSpeed = 255;/最大速度
int delay180=2350;//选择180度所需要的时间(ms)
char getstr;串口数据

Servo myservo1;/舵机
int trig = 13;
int echo = 9;
long IntervalTime = 0;
int pos = 0;
int control=0;/0:人工控制;1:自动控制

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);    
  Rback_motor.setSpeed(0);
 
  Rback_motor.run(RELEASE);

  Rfront_motor.setSpeed(0);
 
  Rfront_motor.run(RELEASE); 

  Lback_motor.setSpeed(0);
 
  Lback_motor.run(RELEASE);

  Lfront_motor.setSpeed(0);
 
  Lfront_motor.run(RELEASE); 

     舵机控制初始化
  myservo1.attach(10);
  myservo1.write(90);
  delay(2000);

  超声波测距
  pinMode(echo, INPUT);
  pinMode(trig, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  getstr = Serial.read();
  driver();
  if(control==1){
      ultrasonicCar();
  }
  //Serial.println("we are link");
  
  //delay(3000);
}

void forward() {

  Rback_motor.run(BACKWARD);
  Rfront_motor.run(BACKWARD);
  Lback_motor.run(BACKWARD);
  Lfront_motor.run(BACKWARD);

  Rback_motor.setSpeed(maxSpeed);
  Rfront_motor.setSpeed(maxSpeed);
  Lback_motor.setSpeed(maxSpeed);
  Lfront_motor.setSpeed(maxSpeed);
}

void backward() {

  Rback_motor.run(FORWARD);
  Rfront_motor.run(FORWARD);
  Lback_motor.run(FORWARD);
  Lfront_motor.run(FORWARD);

  Rback_motor.setSpeed(maxSpeed);
  Rfront_motor.setSpeed(maxSpeed);
  Lback_motor.setSpeed(maxSpeed);
  Lfront_motor.setSpeed(maxSpeed);

}

void stopcar() {
  Rback_motor.setSpeed(0);
  Rfront_motor.setSpeed(0);
  Lback_motor.setSpeed(0);
  Lfront_motor.setSpeed(0);
  Rback_motor.run(RELEASE);
  Rfront_motor.run(RELEASE);
  Lback_motor.run(RELEASE);
  Lfront_motor.run(RELEASE);
}

void left(){
  Rback_motor.run(FORWARD);
  Rfront_motor.run(FORWARD);
  Lback_motor.run(BACKWARD);
  Lfront_motor.run(BACKWARD);

  Rback_motor.setSpeed(maxSpeed);
  Rfront_motor.setSpeed(maxSpeed);
  Lback_motor.setSpeed(maxSpeed);
  Lfront_motor.setSpeed(maxSpeed);  
}


void right(){
  Rback_motor.run(BACKWARD);
  Rfront_motor.run(BACKWARD);
  Lback_motor.run(FORWARD);
  Lfront_motor.run(FORWARD);

  Rback_motor.setSpeed(maxSpeed);
  Rfront_motor.setSpeed(maxSpeed);
  Lback_motor.setSpeed(maxSpeed);
  Lfront_motor.setSpeed(maxSpeed);    
}

void rightAngle(int angle){
  right();
  delay(delay180*angle/180);
  stopcar();
}

void leftAngle(int angle){
  left();
  delay(delay180*angle/180);
  stopcar();
}

void driver() {
  if (getstr == '5') {
    Serial.println("stopcar");
    stopcar();
    control=0;
  }
  if (getstr == '1') {
    Serial.println("forward");
    forward();
    control=0;
  }
  if (getstr == '2') {
    Serial.println("backward");
    backward();
    control=0;
  }
  if (getstr == '3') {
    Serial.println("right");
    right();
    control=0;
  }
  if (getstr == '4') {
    Serial.println("left");
    left();
    control=0;
  }
  if (getstr=='6'){
    control=1;
  }
  if(getstr=='7'){
    control=0;
  }
}  

void servocontrol1(int mypos) {
  myservo1.write(mypos);
}

float getdistance() {
  digitalWrite(trig, 1);
  delayMicroseconds(15);
  digitalWrite(trig, 0);
  IntervalTime = pulseIn(echo, HIGH);
  //Serial.print(IntervalTime / 58.00);
  return IntervalTime / 58.00;
}

void ultrasonicCar() {

  float s135 = 0;
  float s45 = 0;
  float s90 = 0;
  for (pos = 45; pos < 136; pos++) {
    myservo1.write(pos);
    if (pos == 45) {
      s45 = getdistance();
    } else if (pos == 90) {
      s90 = getdistance();
    } else if (pos == 135) {
      s135 = getdistance();
    } else {
      delay(5);
    }
  }
  ultrasonicCar(s135, s90, s45);


  for (pos = 135; pos >= 45; pos--) {
    myservo1.write(pos);
    if (pos == 45) {
      s45 = getdistance();
    } else if (pos == 90) {
      s90 = getdistance();
    } else if (pos == 135) {
      s135 = getdistance();
    } else {
      delay(5);
    }
  }
  ultrasonicCar(s135, s90, s45);
}

void ultrasonicCar(float s135, float s90, float s45) {
  //Serial.println("--------------------------");
  
  if ((s90 < 40)&&(s45<40)&&(s135<40)){
    stopcar();
  }else if ((s90 < 40)&&(s45>40)&&(s135<40)){
    left();
  }else if ((s90 < 40)&&(s45<40)&&(s135>40)){
    right();
  }else{
    forward();
  }
}
  持续更新中