在高速环境下实现小车导航 在

在高速环境下实现小车导航

 

在高速环境下要用两个同时测才行~~

 

 


int pinI1=8;//定义I1接口

int pinI2=9;//定义I2接口

int speedpin=11;//定义EA(PWM调速)接口,left

int pinI3=6;//定义I3接口

int pinI4=7;//定义I4接口

int speedpin1=10;//定义EB(PWM调速)接口right

int input=15;//超声波输出端口(发射)连接开发板模拟0

int output=14;//超声波输入端口(接收)连接开发板模拟1


int speed1;//定义左转速

int speed2;//定义右转速


int a=0;

int b=0;


unsigned long time1,time2,oldtime1,oldtime2;


void setup()

{

 Serial.begin(9600);

 pinMode(pinI1,OUTPUT);

 pinMode(pinI2,OUTPUT);

 pinMode(speedpin,OUTPUT);

 pinMode(pinI3,OUTPUT);

 pinMode(pinI4,OUTPUT);

 pinMode(speedpin1,OUTPUT);

 pinMode(input,INPUT);

 pinMode(output,OUTPUT);

 

   pinMode(3,INPUT);

   pinMode(4,INPUT);

   pinMode(5,INPUT);


   pinMode(2,INPUT);

   

   pinMode(45,INPUT);

   


 pinMode(55,INPUT);

 pinMode(54,OUTPUT);

 pinMode(57,INPUT);

 pinMode(56,OUTPUT);

 pinMode(59,INPUT);

 pinMode(58,OUTPUT);



 speed1=760;

 speed2=709;

 analogWrite(speedpin,speed1);

 analogWrite(speedpin1,speed2);


}

void loop()

{

 





   digitalWrite(pinI4,HIGH);//使直流电机(右)顺时针转

   digitalWrite(pinI3,LOW);

   digitalWrite(pinI1,HIGH);//使直流电机(左)逆时针转

   digitalWrite(pinI2,LOW);




if (digitalRead(3)==LOW)

{

   digitalWrite(pinI4,LOW);

   digitalWrite(pinI3,HIGH);

   digitalWrite(pinI1,HIGH);

   digitalWrite(pinI2,LOW);

}

   digitalWrite(pinI4,HIGH);//使直流电机(右)顺时针转

   digitalWrite(pinI3,LOW);

   digitalWrite(pinI1,HIGH);//使直流电机(左)逆时针转

   digitalWrite(pinI2,LOW);

if (digitalRead(45)==LOW)

{

   digitalWrite(pinI4,LOW);

   digitalWrite(pinI3,HIGH);

   digitalWrite(pinI1,HIGH);

   digitalWrite(pinI2,LOW);

}

   digitalWrite(pinI4,HIGH);//使直流电机(右)顺时针转

   digitalWrite(pinI3,LOW);

   digitalWrite(pinI1,HIGH);//使直流电机(左)逆时针转

   digitalWrite(pinI2,LOW);





 

 if (digitalRead(5)==LOW)

{

   digitalWrite(pinI4,HIGH);

   digitalWrite(pinI3,LOW);

   digitalWrite(pinI1,LOW);

   digitalWrite(pinI2,HIGH);

}

   digitalWrite(pinI4,HIGH);//使直流电机(右)顺时针转

   digitalWrite(pinI3,LOW);

   digitalWrite(pinI1,HIGH);//使直流电机(左)逆时针转

   digitalWrite(pinI2,LOW);

if (digitalRead(4)==LOW)

{

   digitalWrite(pinI4,HIGH);

   digitalWrite(pinI3,LOW);

   digitalWrite(pinI1,LOW);

   digitalWrite(pinI2,HIGH);

}

   digitalWrite(pinI4,HIGH);//使直流电机(右)顺时针转

   digitalWrite(pinI3,LOW);

   digitalWrite(pinI1,HIGH);//使直流电机(左)逆时针转

   digitalWrite(pinI2,LOW);




/**

if ((digitalRead(2)==LOW)&&(a==1))

{

 while (digitalRead(4)==HIGH)

{

   digitalWrite(pinI4,HIGH);

   digitalWrite(pinI3,LOW);

   digitalWrite(pinI1,LOW);

   digitalWrite(pinI2,HIGH);

}

a=0;

}


if ((digitalRead(1)==LOW)&&(b==1))

{

 while (digitalRead(4)==HIGH)

{

   digitalWrite(pinI4,LOW);

   digitalWrite(pinI3,HIGH);

   digitalWrite(pinI1,HIGH);

   digitalWrite(pinI2,LOW);

}

b=0;

}



 digitalWrite(56,LOW);//使发出发出超声波信号接口低电平2us

 delayMicroseconds(2);

 digitalWrite(56,HIGH);//使发出发出超声波信号接口高电平10us

 delayMicroseconds(10);

 digitalWrite(56,LOW);//保持低电平

 unsigned long distance=pulseIn(57,HIGH);//读出脉冲时间

 distance=int((float)distance/29.034/2);//将时间转化为距离,声音传播速度34000cm/s,所以1cm需要29.41us

 delayMicroseconds(10);

   

 digitalWrite(58,LOW);//使发出发出超声波信号接口低电平2us

 delayMicroseconds(2);

 digitalWrite(58,HIGH);//使发出发出超声波信号接口高电平10us

 delayMicroseconds(10);

 digitalWrite(58,LOW);//保持低电平

 unsigned long distance1=pulseIn(59,HIGH);//读出脉冲时间

 distance1=int((float)distance1/29.034/2);//将时间转化为距离,声音传播速度34000cm/s,所以1cm需要29.41us

 delayMicroseconds(10);

 

if  (distance<40)

{

 a=1;

}


if  (distance1<40)

{

 b=1;

}


if ((distance<40)&&(distance1<40))

 {

 digitalWrite(54,LOW);//使发出发出超声波信号接口低电平2us

 delayMicroseconds(2);

 digitalWrite(54,HIGH);//使发出发出超声波信号接口高电平10us

 delayMicroseconds(10);

 digitalWrite(54,LOW);//保持低电平

 unsigned long distance2=pulseIn(55,HIGH);//读出脉冲时间

 distance2=int((float)distance2/29.034/2);//将时间转化为距离,声音传播速度34000cm/s,所以1cm需要29.41us

 delayMicroseconds(10);

 if (distance2<25)

 {

   digitalWrite(pinI4,LOW);

   digitalWrite(pinI3,LOW);

   digitalWrite(pinI1,LOW);

   digitalWrite(pinI2,LOW);

   delay(99999999);

 }

}

 

**/  





}






在高速环境下实现小车导航 在》上有1条评论

  1. Pingback引用通告: BZ编程小组 作品 | BZ编程小组

发表评论

电子邮件地址不会被公开。 必填项已用*标注

This site uses Akismet to reduce spam. Learn how your comment data is processed.