Source to Rocket’s tank robot

November 27th, 2011 § 0 comments § permalink

我使用的是RP5 Tracked Mobile Tank Bas及arduinoDFRduino Duemilanove 328 (Arduino Compatible)Motor Shield For Arduino
使用的传感器是Adjustable Infrared Sensor Switch总共使用了三个。

我的传感器布置在坦克中部前方、右前方及右中部。主要策略是贴边走。
程序中的命名因为事前编程以为比赛方向为顺时针,而比赛时则为逆时针,因此没有来得及改名字而已。
以下为程序。

int E1 = 5;
int M1 = 4;
int E2 = 6;
int M2 = 7;//着部分是motor shield的定义
int front=8;
int leftfront=9;
int leftback=10;//传感器定义

void setup()
{
pinMode(M1, OUTPUT);
pinMode(M2, OUTPUT);
pinMode(front,INPUT);
pinMode(leftfront,INPUT);
pinMode(leftback,INPUT);
}
void foward()//前进函数定义
{
digitalWrite(M1,HIGH);
digitalWrite(M2, HIGH);
analogWrite(E1, 255); //PWM调速
analogWrite(E2, 255); //PWM调速
}
void back()//后退函数定义
{
digitalWrite(M1,LOW);
digitalWrite(M2, LOW);
analogWrite(E1, 255); //PWM调速
analogWrite(E2, 255); //PWM调速
}
void rightgo()//右转函数定义
{
digitalWrite(M1,HIGH);
digitalWrite(M2, LOW);
analogWrite(E1, 255); //PWM调速
analogWrite(E2, 255); //PWM调速
}
void leftgo()//左转函数定义
{
digitalWrite(M1,LOW);
digitalWrite(M2, HIGH);
analogWrite(E1, 255); //PWM调速
analogWrite(E2, 255); //PWM调速
}

void loop()
{
if (digitalRead(9)==1)//策略为如果右中部如果一直保持触发即贴住墙就好了,如果没有就向右转,直到接触到墙壁。
{
rightgo();
delay(600);
}
if (digitalRead(8)==1&&digitalRead(10)==1)
{ foward();
delay(500);
}
else if(digitalRead(8)==0&&digitalRead(10)==1)
{leftgo();
delay(500);}

else if (digitalRead(10)==0&&digitalRead(10)==1)
{
rightgo();
delay(100);
}

else leftgo();

}

程序以上
请各位指正批评。
另外附上我使用设备的购买地址

http://www.dfrobot.com/index.php?route=product/product&path=36&product_id=114

http://www.dfrobot.com/index.php?route=product/product&product_id=69

http://www.dfrobot.com/index.php?route=product/product&filter_tag=Arduino&product_id=49

http://www.dfrobot.com/index.php?route=product/product&path=35&product_id=96

http://www.dfrobot.com/index.php?route=product/product&path=35_39&product_id=264

Where Am I?

You are currently browsing entries tagged with arduino 机器人比赛 策略 at 新车间 [Xinchejian].