1 / 13

樂高機器人

樂高機器人. 進度. 遙控車製作. 遙控器. #define BT_CONN 1 #define OUTBOX 5 #define OUTBOXX 4 sub BTCheck(int conn) // 檢查藍芽是否連線 { if(!BluetoothStatus(conn)==NO_ERR) { TextOut(5,LCD_LINE2,"Error"); Wait(1000); Stop(true); } }. task main() {

jalila
Download Presentation

樂高機器人

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 樂高機器人

  2. 進度 • 遙控車製作

  3. 遙控器 • #define BT_CONN 1 • #define OUTBOX 5 • #define OUTBOXX 4 • sub BTCheck(int conn) //檢查藍芽是否連線 • { • if(!BluetoothStatus(conn)==NO_ERR) • { • TextOut(5,LCD_LINE2,"Error"); • Wait(1000); • Stop(true); • } • }

  4. task main() • { • BTCheck(BT_CONN); //檢查藍芽連線 • int x,y; • while(true) • { • ClearScreen(); • x=MotorTachoCount(OUT_B); • y=MotorTachoCount(OUT_C)/4;

  5. if(x>100) //馬達電力值在100~-100,當角度超過100或-100就限制住 • x=100; • else if(x<-100) • x=-100; • if(y>100) • y=100; • else if(y<-100) • y=-100;

  6. NumOut(10,LCD_LINE2,x); • NumOut(10,LCD_LINE4,y); • SendRemoteNumber(BT_CONN,OUTBOX,x); • //傳送X值 • SendRemoteNumber(BT_CONN,OUTBOXX,y); • //傳送Y值 • } • }

  7. 遙控車 • #define INBOX 5 • #define INBOXX 4 • sub BTCheck(int conn) • { • if(!BluetoothStatus(conn)==NO_ERR) • { • TextOut(5,LCD_LINE2,"Error"); • Wait(1000); • Stop(true); • } • }

  8. task main() • { • BTCheck(0); 以接收端來看,傳送端都是在line 0 • int x,y,i,j,k,l; • int smp=1; • while(true) • { • ReceiveRemoteNumber(INBOX,false,x); //接收X值 • ReceiveRemoteNumber(INBOXX,false,y);//接收Y值

  9. if(y>0 && x>=0) //前進左轉 • { • if(x==0) • i=-y; • else • { • i=x-y; • if(i<0) • i=0; • } • OnFwdReg(OUT_B,x,OUT_REGMODE_SPEED); • OnFwdReg(OUT_C,i,OUT_REGMODE_SPEED); • }

  10. else if(y<0 && x>=0) //前進右轉 • { • if(x==0) • j=y; • else • { • j=x+y; • if(j<0) • j=0; • } • OnFwdReg(OUT_B,j,OUT_REGMODE_SPEED); • OnFwdReg(OUT_C,x,OUT_REGMODE_SPEED); • }

  11. else if(y>0 && x<0) //後退左轉 • { • k=x+y; • if(k>0) • k=0; • OnFwdReg(OUT_B,x,OUT_REGMODE_SPEED); • OnFwdReg(OUT_C,k,OUT_REGMODE_SPEED); • }

  12. else if(y<0 && x<0) //後退右轉 • { • l=x-y; • if(l>0) • l=0; • OnFwdReg(OUT_B,l,OUT_REGMODE_SPEED); • OnFwdReg(OUT_C,x,OUT_REGMODE_SPEED); • } • else //直線前進後退 • OnFwdReg(OUT_BC,x,OUT_REGMODE_SPEED); • } • }

  13. End

More Related