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