《避障機(jī)器人設(shè)計(jì)與調(diào)試講解》由會(huì)員分享,可在線閱讀,更多相關(guān)《避障機(jī)器人設(shè)計(jì)與調(diào)試講解(5頁(yè)珍藏版)》請(qǐng)?jiān)谘b配圖網(wǎng)上搜索。
1、
避障機(jī)器人設(shè)計(jì)與調(diào)試
、實(shí)訓(xùn)目的
1 了解機(jī)器人大賽中避障的規(guī)則,進(jìn)一步理解電機(jī)和紅外測(cè)距傳感器的原理;
2 掌握避障機(jī)器人的設(shè)計(jì)方法。
二、實(shí)訓(xùn)設(shè)備
1 硬件: HOST 機(jī)一臺(tái)、基于機(jī)器人項(xiàng)目驅(qū)動(dòng)的嵌入式教學(xué)實(shí)訓(xùn)平臺(tái)一套;
2 軟件: WIN2000 或 xp 操作系統(tǒng)、 Siliconlab IDE 開(kāi)發(fā)環(huán)境、調(diào)試器。
三、實(shí)訓(xùn)原理
實(shí)現(xiàn)避障的功能從原理上是通過(guò)分析紅外測(cè)距傳感器的測(cè)量值判斷障礙物的位置,
120
然后驅(qū)動(dòng)電機(jī)避開(kāi)障礙物。通過(guò)連接三個(gè)紅外測(cè)距傳感器,機(jī)器人可以探測(cè)到
度的視角范圍的障礙物。
磯耦人IT動(dòng)
四、實(shí)訓(xùn)步驟
1、正確
2、連接PC機(jī)、調(diào)試器和基于機(jī)器人項(xiàng)目驅(qū)動(dòng)的嵌入式教學(xué)實(shí)訓(xùn)平臺(tái);
2、打開(kāi)電源,打開(kāi)Siliconlab IDE ;
3、打開(kāi)避障的例程,正確調(diào)試并運(yùn)行該程序。
4、燒錄完成后斷電拔掉調(diào)試器,把組裝好的機(jī)器人放入模擬的參賽場(chǎng)地,再次打開(kāi)電 源,觀察機(jī)器人避障的情況。
void main()
{
unsigned int ad_test;
unsigned int i = 0;
SystemInit();
while(1)
{
DodgeObstruction();
void DodgeObstruction()
{
unsigned char ad_distance_l
3、eft = 0;
unsigned char ad_distance_midl = 0;
unsigned char ad_distance_rigt = 0;
while(1)
{
ad_distance_left = GetIR_Distance(2);
ad_distance_midl = GetIR_Distance(3);
ad_distance_rigt = GetIR_Distance(4);
if(ad_distance_left>40 && ad_distance_midl>40 && ad_distance_rig
4、t>40) {
DC_Motor(1,0,60);
DC_Motor(3,0,60);
DC_Motor(2,0,60);
DC_Motor(4,0,60);
}
if(ad_distance_rigt<40)
{
DC_Motor(1,0,60);
DC_Motor(3,0,60);
DC_Motor(2,2,10);
DC_Motor(4,2,10);
}
if(ad_distance_midl<40)
{
DC_Motor(1,2,70);
DC_Motor(3,2,70);
DC_Motor(2,2,70);
DC_Motor(4,
5、2,70);
}
if(ad_distance_left<40)
{
DC_Motor(1,2,10);
DC_Motor(3,2,10);
DC_Motor(2,0,60);
DC_Motor(4,0,60);
}
}
}
void
DC_Motor(unsigned char motor_num,unsigned char direction, unsigned char motor_speed) {
unsigned char SFRPAGE_save = SFRPAGE;
SFRPAGE = CONFIG_PAGE; if(!motor_speed)
6、
{
switch(motor_num)
{
case 1:
PCA0CPH0 = 255; break;
case 2:
PCA0CPH1 = 255;
break;
case 3:
PCA0CPH2 = 255; break;
case 4:
PCA0CPH3 = 255; break;
case 5:
PCA0CPH4 = 255;
break;
case 6:
PCA0CPH5 = 255;
break; default: break;
}
}
else
switch(motor_num) {
case 1:
PCA0CPH0 = 255
7、- (motor_speed+116); break;
case 2:
PCA0CPH1 = 255 - (motor_speed+116); break;
case 3:
PCA0CPH2 = 255 - (motor_speed+116); break;
case 4:
PCA0CPH3 = 255 - (motor_speed+116);
Break;
case 5:
PCA0CPH4 = 255 - (motor_speed+116); break;
case 6:
PCA0CPH5 = 255 - (motor_speed+116);
break;
defa
8、ult: break;
}
switch(direction)
{
case 0:
if(motor_num==1) P3 &= ~0x20; //P1.3 = 0, 即 DIR0 置 0
if(motor_num==2) P1 &= ~0x10; //P1.4 = 0, 即 DIR1 置 0
if(motor_num==3) P1 &= ~0x20; //P1.5 = 0, 即 DIR2 置 0
if(motor_num==4) P1 &= ~0x40; //P1.6 = 0, 即 DIR3 置 0
if(motor_num==5) P3 &
9、amp;= ~0x40; //P3.6 = 0, 即 DIR4 置 0
break;
case 1:
if(motor_num==1) PCA0CPH0 = 255;
if(motor_num==2) PCA0CPH1 = 255;
if(motor_num==3) PCA0CPH2 = 255;
if(motor_num==4) PCA0CPH3 = 255;
if(motor_num==5) PCA0CPH4 = 255;
if(motor_num==6) PCA0CPH5 = 255;
break;
case 2:
if(motor_num==1) P3 |=
i
10、f(motor_num==2) P1 |=
0x20;
0x10;
//P3.5 =
//P1.4 =
1,即
1,即
DIR0 置 1;
DIR1
置 1;
if(motor_num==3) P1 |=
0x20;
//P1.5 =
1,即
DIR2
置 1;
if(motor_num==4) P1 |=
0x40;
//P1.6 =
1,即
DIR3
置 1;
if(motor_num==5) P3 |=
0x40;
//P3.6 =
1,即
DIR4
置 1;
break;
default: break;
}
SFRPAGE = SFRPAGE_save;