电赛寻线方案.docx
《电赛寻线方案.docx》由会员分享,可在线阅读,更多相关《电赛寻线方案.docx(28页珍藏版)》请在冰豆网上搜索。
电赛寻线方案
#include"findblack.h"
#definegodelay10
#definestopdelay40
#defineturndelay25
sbitbeep=P3^7;
charcrossnum=0,x=1,y=1,crossflag=0,direction=dx,pingzi12=0;
voiddelay(uintxms)
{
uinti,j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
}
voidfind()
{
if(G1==off&&G2==off&&G3==on&&G4==off&&G5==off){//00100
go(100,100);
}
if(G1==off&&G2==off&&G3==off&&G4==on&&G5==off){//00010
go(100,0);
}
if(G1==off&&G2==on&&G3==off&&G4==off&&G5==off){//01000
go(0,100);
}
if(G1==off&&G2==off&&G3==on&&G4==on&&G5==off){//00110
go(100,0);
}
if(G1==off&&G2==on&&G3==on&&G4==off&&G5==off){//01100
go(0,100);
}
if(G1==off&&G2==off&&G3==off&&G4==off&&G5==on){//00001
go(100,0);
}
if(G1==on&&G2==off&&G3==off&&G4==off&&G5==off){//10000
go(0,100);
}
if(G1==on&&G2==on&&G3==on&&G4==on&&G5==on){//11111
go(100,100);
delay(godelay);
go(0,0);beep=0;
delay(stopdelay);beep=1;
crossflag=1;
}
if(G1==on&&G2==on&&G4==off&&G5==off){//11*00
go(100,100);
delay(godelay);
go(0,0);beep=0;
delay(stopdelay);beep=1;
crossflag=1;
}
if(G1==off&&G2==off&&G4==on&&G5==on){//00*11
go(100,100);
delay(godelay);
go(0,0);beep=0;
delay(stopdelay);beep=1;
crossflag=1;
}
if(G1==off&&G2==off&&G3==off&&G4==off&&G5==off){//00000
go(50,50);
}
}
voidzoufangge()
{
find();
//WriteString("x=",0,0);WriteChar(x+48,2,0);
//WriteString(",y=",3,0);WriteChar(y+48,6,0);
//if(direction==dy)
//WriteString(",dir=y",7,0);
//if(direction==dfy)
//WriteString(",dir=-y",7,0);
//if(direction==dx)
//WriteString(",dir=x",7,0);
//if(direction==dfx)
//WriteString(",dir=-x",7,0);
if(down1==0||down2==0||down3==0){//正立瓶子
left_turn_90_degree();
if(direction==dx){
direction=dy;
}
elseif(direction==dy){
direction=dfx;
}
elseif(direction==dfx){
direction=dfy;
}
elseif(direction==dfy){
direction=dx;
}
}
elseif(up1==0||up2==0||up3==0){//倒立瓶子
right_turn_90_degree();
if(direction==dx){
direction=dfy;
}
elseif(direction==dy){
direction=dx;
}
elseif(direction==dfx){
direction=dy;
}
elseif(direction==dfy){
direction=dfx;
}
}
if(crossflag==1){
crossflag=0;
if(direction==dx)x++;
elseif(direction==dfx)x--;
elseif(direction==dy)y++;
elseif(direction==dfy)y--;
if(x==6&&y==3){
go(0,0);
while
(1);
}
if(x==1&&y==1){
if(direction==dy){
//go
}
if(direction==dx){
//go
}
if(direction==dfy){
left_turn_90_degree();
direction=dx;
}
if(direction==dfx){
right_turn_90_degree();
direction=dy;
}
}
if(x==2&&y==1){
if(direction==dy){
//go
}
if(direction==dx){
//go
}
if(direction==dfy){
left_turn_90_degree();
direction=dx;
}
if(direction==dfx){
right_turn_90_degree();
direction=dy;
}
}
if(x==3&&y==1){
if(direction==dy){
//go
}
if(direction==dx){
//go
}
if(direction==dfy){
left_turn_90_degree();
direction=dx;
}
if(direction==dfx){
right_turn_90_degree();
direction=dy;
}
}
if(x==4&&y==1){
if(direction==dy){
//go
}
if(direction==dx){
//go
}
if(direction==dfy){
left_turn_90_degree();
direction=dx;
}
if(direction==dfx){
right_turn_90_degree();
direction=dy;
}
}
if(x==5&&y==1){
if(direction==dy){
//go
}
if(direction==dx){
//go
}
if(direction==dfy){
left_turn_90_degree();
direction=dx;
}
if(direction==dfx){
right_turn_90_degree();
direction=dy;
}
}
if(x==6&&y==1){
if(direction==dy){
//go
}
if(direction==dx){
left_turn_90_degree();
direction=dy;
}
if(direction==dfy){
left_turn_90_degree();
direction=dx;
}
if(direction==dfx){
right_turn_90_degree();
direction=dy;
}
}
if(x==1&&y==2){
if(direction==dy){
//go
}
if(direction==dx){
//go
}
if(direction==dfy){
left_turn_90_degree();
direction=dx;
}
if(direction==dfx){
right_turn_90_degree();
direction=dy;
}
}
if(x==2&&y==2){
if(direction==dy){
//go
}
if(direction==dx){
//go
}
if(direction==dfy){
left_turn_90_degree();
direction=dx;
}
if(direction==dfx){
right_turn_90_degree();
direction=dy;
}
}
if(x==3&&y==2){
if(direction==dy){
//go
}
if(direction==dx){
//go
}
if(direction==dfy){
left_turn_90_degree();
direction=dx;
}
if(direction==dfx){
right_turn_90_degree();
direction=dy;
}
}
if(x==4&&y==2){
if(direction==dy){
//go
}
if(direction==dx){
//go
}
if(direction==dfy){
left_turn_90_degree();
direction=dx;
}
if(direction==dfx){
right_turn_90_degree();
direction=dy;
}
}
if(x==5&&y==2){
if(direction==dy){
//go
}
if(direction==dx){
//go
}
if(direction==dfy){
left_turn_90_degree();
direction=dx;
}
if(direction==dfx){
right_turn_90_degree();
direction=dy;
}
}
if(x==6&&y==2){
if(direction==dy){
//go
}
if(direction==dx){
left_turn_90_degree();
direction=dy;
}
if(direction==dfy){
//
}
if(direction==dfx){
//
}
}
if(x==1&&y==3){
if(direction==dy){
right_turn_90_degree();
direction=dx;
}
if(direction==dx){
//go
}
if(direction==dfy){
left_turn_90_degree();
direction=dfx;
}
if(direction==dfx){
right_turn_90_degree();
direction=dy;
}
}
if(x==2&&y==3){
if(direction==dy){
right_turn_90_degree();
direction=dx;
}
if(direction==dx){
//go
}
if(direction==dfy){
left_turn_90_degree();
direction=dx;
}
if(direction==dfx){
right_turn_90_degree();
direction=dy;
}
}
if(x==3&&y==3){
if(direction==dy){
right_turn_90_degree();
direction=dx;
}
if(direction==dx){
//go
}
if(direction==dfy){
left_turn_90_degree();
direction=dx;
}
if(direction==dfx){
right_turn_90_degree();
direction=dfx;
}
}
if(x==4&&y==3){
if(direction==dy){
right_turn_90_degree();
direction=dx;
}
if(direction==dx){
//go
}
if(direction==dfy){
left_turn_90_degree();
direction=dx;
}
if(direction==dfx){
right_turn_90_degree();
direction=dy;
}
}
if(x==5&&y==3){
if(direction==dy){
right_turn_90_degree();
direction=dx;
}
if(direction==dx){
//go
}
if(direction==dfy){
left_turn_90_degree();
direction=dx;
}
if(direction==dfx){
right_turn_90_degree();
direction=dy;
}
}
if(x==6&&y==3){
}
if(x==0&&y==1){
if(direction==dy){
//go
}
if(direction==dx){
//go
}
if(direction==dfy){
left_turn_90_degree();
direction=dx;
}
if(direction==dfx){
right_turn_90_degree();
direction=dy;
}
}
if(x==0&&y==2){
if(direction==dy){
//go
}
if(direction==dx){
//go
}
if(direction==dfy){
left_turn_90_degree();
direction=dx;
}
if(direction==dfx){
right_turn_90_degree();
direction=dy;
}
}
if(x==0&&y==3){
if(direction==dy){
//go
}
if(direction==dx){
//go
}
if(direction==dfy){
left_turn_90_degree();
direction=dx;
}
if(direction==dfx){
right_turn_90_degree();
direction=dy;
}
}
if(x==0&&y==4){
if(direction==dy){
right_turn_90_degree();
direction=dx;
}
if(direction==dx){
//go
}
if(direction==dfy){
left_turn_90_degree();
direction=dx;
}
if(direction==dfx){
right_turn_90_degree();
direction=dy;
}
}
if(x==1&&y==4){
if(direction==dy){
right_turn_90_degree();
direction=dx;
}
if(direction==dx){
//go
}
if(direction==dfy){
left_turn_90_degree();
direction=dfx;
}
if(direction==dfx){
right_turn_90_degree();
direction=dy;
}
}
if(x==2&&y==4){
if(direction==dy){
right_turn_90_degree();
direction=dx;
}
if(direction==dx){
//go
}
if(direction==dfy){
left_turn_90_degree();
direction=dfx;
}
if(direction==dfx){
right_turn_90_degree();
direction=dy;
}
}
if(x==3&&y==4){
if(direction==dy){
right_turn_90_degree();
direction=dx;
}
if(direction==dx){
//go
}
if(direction==dfy){
left_turn_90_degree();
direction=dx;
}
if(direction==dfx){
right_turn_90_degree();
direction=dy;
}
}
if(x==4&&y==4){
if(direction==dy){
right_turn_90_degree();
direction=dx;
}
if(direction==dx){
//go
}
if(direction==dfy){
left_turn_90_degree();
direction=dx;
}
if(direction==dfx){
right_turn_90_degree();
direction=dy;
}
}
if(x==5&&y==4){
if(direction==dy){
right_turn_90_degree();
direction=dx;
}
if(direction==dx){
//go
}
if(direction==dfy){
//go
}
if(direction==dfx){
right_turn_90_degree();
direction=dy;
}