六足機器人控制程序_第1頁
六足機器人控制程序_第2頁
六足機器人控制程序_第3頁
六足機器人控制程序_第4頁
六足機器人控制程序_第5頁
已閱讀5頁,還剩3頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領

文檔簡介

1、精選優(yōu)質文檔-傾情為你奉上#include "main.h"/電機反向運行的延時計數(shù)器uword tiDelay1,tiDelay2,tiDelay3;/電機運行的脈沖計數(shù)器ulong ctPulse1,ctPulse2,ctPulse3; /串口控制的電機方向、脈沖寬度和脈沖數(shù)量ubyte MOT_direct1,MOT_direct2,MOT_direct3,RS_Status,a; /電機方向ubyte MOT_PulseTime1,MOT_PulseTime2,MOT_PulseTime3;/電機脈沖寬度uword MOT_PulseNum1,MOT_PulseNu

2、m2,MOT_PulseNum3;/電機脈沖數(shù)/串口接收變量ubyte RS_DataRS_LENGTH; /串口接收數(shù)組ubyte RS_Indx;/串口接收數(shù)組指針ubyte RS_Status; /串口接收狀態(tài)標志 /定時器變量ubyte B_TimerStart;/0.5ms定時器標志位 unsigned inti,j,t,d1,d2,d3,c=0; unsigned int maxt,maxb;/上盤抬起或下盤下降子程序 void shangpantaiqizichengxu() 編程思想:,在LabVIEW里面設置合適的轉速,合適的轉角,發(fā)出脈沖,子程序的計數(shù)脈沖,脈沖寬度都是由所

3、發(fā)脈沖決定,根據(jù)計數(shù)脈沖,脈沖寬度的要求,編寫程序,發(fā)出合適的脈沖,控制電機達到要求的轉速與轉角,通過控制P9_P0口、P9_P1口、P9_P2口來控制電機轉向,實現(xiàn)我們想要的運動。 int NUM1=0,NUM2=0,NUM3=0;int flag=0; P9_P3=0; P9_P4=0; P9_P5=0; P9_P0=1; / P9_P0口控制電機轉向,將其置1,電機順時針轉動 P9_P1=1; / P9_P1口控制電機轉向,將其置1,電機順時針轉動 P9_P2=1; / P9_P2口控制電機轉向,將其置1,電機順時針轉動while(NUM1!=MOT_PulseNum1|NUM2!=MO

4、T_PulseNum2|NUM3!=MOT_PulseNum3)/當電機一、二、三的計數(shù)次數(shù)都達到設定值時跳出while循環(huán),否者繼續(xù)執(zhí)行 flag+; /用來記錄走過多少個0.5ms if(0=(flag-1)%(2*MOT_PulseTime1) 0020 /第1個電機所需要的脈沖/2*MOT_PulseTime1即MOT_PulseTime1/0.5,說明每個脈沖寬度有幾個0.5ms。flag若能被2*MOT_PulseTime1則發(fā)出一個脈沖,高低電平互換 if(NUM1<MOT_PulseNum1*2) /在滿足上面的條件下,若計數(shù)次數(shù)未達到設定計數(shù)次數(shù)是,發(fā)出脈沖,高低互換,

5、否這不執(zhí)行 P9_P3=!P9_P3; /當滿足上面兩個條件時高低電平互換 NUM1+; if(0=(flag-1)%(2*MOT_PulseTime2) /第2個電機所需要的脈沖解釋同上 if(NUM2<MOT_PulseNum2*2) P9_P4=!P9_P4; NUM2+; if(0=(flag-1)%(2*MOT_PulseTime3) /第3個電機所需要的脈沖解釋同上 if(NUM3<MOT_PulseNum3*2) P9_P5=!P9_P5; NUM3+; while(B_TimerStart) ;/延時程序P9_P3=0; P9_P4=0; P9_P5=0;/下盤抬起

6、或上盤下降子程序 void xiapantaiqizichengxu()編程思想:三個電機同時逆時針轉動可實現(xiàn)下盤抬起或上盤下降子程序,除了P9_P0口、P9_P1口、P9_P2口的狀態(tài)不一樣,其余都相同。 int NUM1=0,NUM2=0,NUM3=0;int flag=0; P9_P3=0; P9_P4=0; P9_P5=0; P9_P0=0; P9_P1=0; P9_P2=0; while(NUM1!=MOT_PulseNum1|NUM2!=MOT_PulseNum2|NUM3!=MOT_PulseNum3) flag+; if(0=(flag-1)%(2*MOT_PulseTime1

7、) /第1個電機 if(NUM1<MOT_PulseNum1*2) P9_P3=!P9_P3; NUM1+; if(0=(flag-1)%(2*MOT_PulseTime2) /第2個電機 if(NUM2<MOT_PulseNum2*2) P9_P4=!P9_P4; NUM2+; if(0=(flag-1)%(2*MOT_PulseTime3) /第3個電機 if(NUM3<MOT_PulseNum3*2) P9_P5=!P9_P5; NUM3+; while(B_TimerStart) ; P9_P3=0; P9_P4=0; P9_P5=0;/3號電機0軸正轉 void y

8、ihaodianjizhouzhengzhuan() 編程思想:只要求3號電機轉,則只給3號電機發(fā)送脈沖,一號二號電機不發(fā)送脈沖,則一號二號電機不動 int NUM1=0,NUM2=0,NUM3=0;int flag=0; P9_P3=0; P9_P4=0; P9_P5=0; P9_P0=0; P9_P1=0; P9_P2=1; /使三號電機正轉while(NUM3!=MOT_PulseNum3) /給三號電機發(fā)送脈沖 flag+; if(0=(flag-1)%(2*MOT_PulseTime3) /第3個電機 if(NUM3<MOT_PulseNum3*2) P9_P5=!P9_P5;

9、 NUM3+; while(B_TimerStart) ;P9_P3=0; P9_P4=0; P9_P5=0; /3號電機軸反轉 void yihaodianjizhoufanzhuan() 編程思想:只要求3號電機轉,則只給3號電機發(fā)送脈沖,一號二號電機不發(fā)送脈沖,則一號二號電機不動,除了三號電機轉速不一樣以外其余與三號電機正轉程序相同 int NUM1=0,NUM2=0,NUM3=0;int flag=0; P9_P3=0; P9_P4=0; P9_P5=0; P9_P0=0; P9_P1=0; P9_P2=0; /三號電機逆時針轉動while(NUM3!=MOT_PulseNum3) f

10、lag+; if(0=(flag-1)%(2*MOT_PulseTime3) /第3個電機 if(NUM3<MOT_PulseNum3*2) P9_P5=!P9_P5; NUM3+; while(B_TimerStart) ; P9_P3=0; P9_P4=0; P9_P5=0;/機器人走一步程序void zouyibu()/走一步編程思想:通過研究機器人結構,發(fā)現(xiàn)讓機器人走一步可分解為以下幾個動作:1、電機1、2、3同時順時針轉,實現(xiàn)下底盤抬起。2、當三號電機順時針轉動,而一號二號電機不轉動時下底盤前進3、一號二號三號電機同時逆時針轉動時,下底盤下降,當接觸到地面繼續(xù)下降時,上盤被抬起

11、。4、三號電機逆時針轉動,一號二號電機不轉動時實現(xiàn)上盤的前進。5、一號二號三號電機同時順時針轉動,上盤下降,接觸帶地面時完成一步行走通過調(diào)試在電機轉速80,電機位置100的情況下:上盤抬起或下盤下降子程序執(zhí)行兩次,3號電機軸正轉子程序執(zhí)行三次,下盤抬起或上盤下降子程序執(zhí)行七次,3號電機軸反轉子程序執(zhí)行三次,上盤抬起或下盤下降子程序執(zhí)行五次可實現(xiàn)一步行走。下面程序為為實現(xiàn)這一步行走所調(diào)用的子程序及其步驟。 for(j=0;j<2000;j+)/第一步延時1s while(B_TimerStart) / 此程序是延時程序B_TimerStart=1時一直執(zhí)行while,0.5ms發(fā)出一個中斷

12、使B_TimerStart變?yōu)?,跳出while,再將B_TimerStart置1,一直循環(huán)2000次,實現(xiàn)延時一秒。 B_TimerStart =1; shangpantaiqizichengxu() ;/上盤抬起或下盤下降子程序 for(j=0;j<2000;j+)/第二步延時1s while(B_TimerStart) B_TimerStart =1; shangpantaiqizichengxu() ;/上盤抬起或下盤下降子程序 for(j=0;j<2000;j+)/第三步延時1s while(B_TimerStart) B_TimerStart =1; yihaodian

13、jizhouzhengzhuan() ;/3號電機軸正轉 for(j=0;j<2000;j+)/第四步延時1s while(B_TimerStart) B_TimerStart =1; yihaodianjizhouzhengzhuan() ;/3號電機軸正轉 for(j=0;j<2000;j+)/第五步延時1s while(B_TimerStart) B_TimerStart =1; yihaodianjizhouzhengzhuan() ;/3號電機軸正轉 for(j=0;j<2000;j+)/第六步延時1s while(B_TimerStart) B_TimerStar

14、t =1; xiapantaiqizichengxu() ; /下盤抬起或上盤下降子程序 for(j=0;j<2000;j+)/第七步延時1s while(B_TimerStart) B_TimerStart =1; xiapantaiqizichengxu() ; /下盤抬起或上盤下降子程序 for(j=0;j<2000;j+)/第八步延時1s while(B_TimerStart) B_TimerStart =1; xiapantaiqizichengxu() ; /下盤抬起或上盤下降子程序 for(j=0;j<2000;j+)/第九步延時1s while(B_Timer

15、Start) B_TimerStart =1; xiapantaiqizichengxu() ; /下盤抬起或上盤下降子程序 for(j=0;j<2000;j+)/第十步延時1s while(B_TimerStart) B_TimerStart =1; xiapantaiqizichengxu() ; /下盤抬起或上盤下降子程序 for(j=0;j<2000;j+)/第十一步延時1s while(B_TimerStart) B_TimerStart =1; xiapantaiqizichengxu() ; /下盤抬起或上盤下降子程序 for(j=0;j<2000;j+)/第十

16、二步延時1s while(B_TimerStart) B_TimerStart =1; xiapantaiqizichengxu() ; /下盤抬起或上盤下降子程序 for(j=0;j<2000;j+)/第十三步延時1s while(B_TimerStart) B_TimerStart =1; yihaodianjizhoufanzhuan();/三號電機軸反轉 for(j=0;j<2000;j+)/第十四步延時1s while(B_TimerStart) B_TimerStart =1; yihaodianjizhoufanzhuan();/三號電機軸反轉 for(j=0;j&l

17、t;2000;j+)/第十五步延時1s while(B_TimerStart) B_TimerStart =1; yihaodianjizhoufanzhuan();/三號電機軸反轉 for(j=0;j<2000;j+)/第十六步延時1s while(B_TimerStart) B_TimerStart =1; shangpantaiqizichengxu() ;/上盤抬起或下盤下降子程序 for(j=0;j<2000;j+)/第十七步延時1s while(B_TimerStart) B_TimerStart =1; shangpantaiqizichengxu() ;/上盤抬起或

18、下盤下降子程序 for(j=0;j<2000;j+)/第十八步延時1s while(B_TimerStart) B_TimerStart =1; shangpantaiqizichengxu() ;/上盤抬起或下盤下降子程序 for(j=0;j<2000;j+)/第十九步延時1s while(B_TimerStart) B_TimerStart =1; shangpantaiqizichengxu() ;/上盤抬起或下盤下降子程序 for(j=0;j<2000;j+)/第二十步延時1s while(B_TimerStart) B_TimerStart =1; shangpantaiqizichengxu() ;/上盤抬起或下盤下降子程序 for(j=0;j<2000;j+)/第二十一步延時1s while(B_TimerStart) B_TimerStart =1; 主程序void MotorControl_0x5ms(void) if(MOT_direct1=1&&MOT_dire

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論