?? function_2009.c~
字號:
//*************************************************************
//*************************************************************
//ThIs FuNcTiOn Is uSe FoR mOvInG tHrOuGhT tHe ReD fIeLd Of MoUnTaIn
void moving_forward(int max_speed,char line,char stop_position,char status_running
,char current_position)
{
//DECLARE PARAMETERS FOR INITIALIZE
//!!!!Remember to clear the line_numb value before exitting!!!!
//the initial value of line_numb is decided by the last function OR the last statements.
//IMPORTANT.DON"t FORGET IT.
//*********************************
int V=0; //Setting verlocity at beginning
char x=1; //1 default //Setting the place where robo will decrease verlocity before line-end
char dem=0,k1=1,k2=1,k3=1; //counting-time variable for adjust time duration
char strectch_time=30; // stretch of time
char so_led=5;
//line_numb=0; //reset number of line .line_numb is a global variable
//*********************************
LED =0; //reset LED Value
if(status_running==0) V=0;
else V=200;
while(line_numb<line)
{
if(V>=max_speed) V=max_speed;
else
{
++dem ;
if(dem >= strectch_time)
{
V+=1;
dem=0;
}
}
scan_line(V);
//LED=line_numb;
//*********************************************************************************
// PROCESSING WHEN ROBO CATCH THE LINE...
//*********************************************************************************/
if(S_sensor >= so_led)
{
line_numb++;
LED=line_numb;
//CHECKING WHERE YOU WANT TO STOP
if(line_numb==line)
{
if(stop_position == at_line)
{
Vleft=0;
Vright=0;
delay_ms(20);
break;
}
else if(stop_position == behind_line1)
{
count=0;
while(count<30) //20
{
scan_line(V);
};
break;
}
else if(stop_position == behind_line2)
{
count=0;
while(count<100) //60
{
scan_line(V);
};
}
else if(stop_position == behind_line3)
{
count=0;
while(count<140) //60
{
scan_line(V);
};
}
}
//******************************************************************
if(current_position ==qua_doc_X)
switch(line_numb)
{
case 3:
//V=max_speed;
//max_speed=350;
break;
case 4:
//max_speed=350;
max_speed=300;
V=max_speed;
break;
case 6:
break;
case 7:
elevator(-1);
max_speed=200;
V=max_speed;
break;
case 8:
max_speed=180;
V =max_speed;
break;
case 9:
if(k1==1)
{
begin_get_encoder();
while(left_data<5000)
{max_speed=180;}
k1=0;
}
max_speed=400;
V=250;
break;
}
///////////////////
///*
if((line_numb<=6)&&(line_numb>=3))
{
begin_get_encoder();
while(left_data<8500)
{scan_line(V);}
while(S_sensor>2)
scan_line(V);
}
else
{
// begin_get_encoder();
// while(left_data<1000)
// {scan_line(V);}
while(S_sensor>3)
{
scan_line(V);
}
count=0;
while(count<30) //20//60
{
scan_line(V);
} //*/
}
}
//***********************************************
};
stop();
//clear line_numb for the next use
line_numb=0;
}
//***************************************************************************
//
//****************************************************************************
void moving_forward_qua_rung(int max_speed,char line,char stop_position,char status_running
,char current_position)
{
//DECLARE PARAMETERS FOR INITIALIZE
//!!!!Remember to clear the line_numb value before exitting!!!!
//the initial value of line_numb is decided by the last function OR the last statements.
//IMPORTANT.DON"t FORGET IT.
//*********************************
int V=0; //Setting verlocity at beginning
char x=1; //1 default //Setting the place where robo will decrease verlocity before line-end
char dem=0,k1=1,k2=1,k3=1; //counting-time variable for adjust time duration
char strectch_time=30; // stretch of time
char so_led=4;
//line_numb=0; //reset number of line .line_numb is a global variable
//*********************************
LED =0; //reset LED Value
if(status_running==0) V=0;
else V=200;
if(current_position ==qua_rung_X)
so_led=4;
while(line_numb<line)
{
if(V>=max_speed) V=max_speed;
else
{
++dem ;
if(dem >= strectch_time)
{
V+=1;
dem=0;
}
}
scan_line1(V);
//*********************************************************************************
// PROCESSING WHEN ROBO CATCH THE LINE...
//*********************************************************************************/
if(S_sensor >= so_led)
{
line_numb++;
LED=line_numb;
if(line_numb==line)
{
stop();//motor shutdown.
break;
}
//while until meet another line
while(S_sensor>2)
{
if(line_numb>2) if(S_sensor>7) break;
scan_line1(V);
};
if(line_numb>2) if(S_sensor>7) break;
count=0;
while(count<60) //20//60
{
if(line_numb>2) if(S_sensor>7) break;
scan_line1(V);
} ;
}
//***********************************************
if(line_numb>2) if(S_sensor>7) break;
};
stop();
//clear line_numb for the next use
line_numb=0;
}
void moving_forward_doline(int max_speed,char line,char stop_position,char status_running)
{
//DECLARE PARAMETERS FOR INITIALIZE
//*********************************
int V=0; //Setting verlocity at beginning
char x=1; //1 default //Setting the place where robo will decrease verlocity before line-end
char dem=0; //counting-time variable for adjust time duration
char strectch_time=1; // stretch of time
line_numb=0; //reset number of line .line_numb is a global variable
//flag_90=0; //set this flag to 1 to enable capacity turn at the corner 90deg
//*********************************
if(status_running==0) V=0;
else V=Vright;
while(line_numb<line)
{
if(V>=max_speed) V=max_speed;
else
{
++dem ;
if(dem >= strectch_time)
{
V+=2;
dem=0;
}
}
doline(V);
//LED=V;
if((S_sensor >=4))
{
line_numb++;
LED=line_numb;
switch(stop_position)
{
case at_line:
if(line_numb==line)
{
Vleft=0;
Vright=0;
break;
}
else
{
while(S_sensor>2)
{
doline(V);
} //while until meet another line
count=0;
while(count<20) //60
{
doline(V);
}
}
break;
case behind_line1: //truong hopnay dung de re 90
while(S_sensor>2) {;} //while until meet another line
count=0;
while(count<30) //20
{
// scan_line(V); //truong hop nay dung de re 90
}
break;
case behind_line2:
while(S_sensor>2) {;} //while until meet another line
count=0;
while(count<100) //60
{
doline(V);
}
break;
case behind_line3:
while(S_sensor>2) {;} //while until meet another line
count=0;
while(count<140) //60
{
doline(V);
}
break;
}
}
//*************************************************/
if(line_numb==line)
{
Vleft=0;
Vright=0;
// delay_ms(100); //motor shutdown.
}
//***********************************************?
};
delay_ms(5);
}
/*****************************************
ENCODER RUNNING :
*****************************************/
void fuzzy_run_straight_enc(int VL,int VR,int fuzzy_enc,int enc_numb,char stop_sens)
{
int enc=0;
char temp,i;
char delta;
LED =1122;
if ((VL >=200)&&(VL <250)) delta=25;
else if((VL >=250)&&(VL <300)) delta=30;
else if((VL >=300)&&(VL <350)) delta=35;
else if((VL >=350)&&(VL <400)) delta=40;
else if((VL >=400)&&(VL <500)) delta=45;
if(fuzzy_enc)
{
temp=fuzzy_enc/100;
for(i=0;i<=temp-1;i++)
{
begin_get_encoder();
while(enc <100)
{
Vleft=VL + delta;
Vright=VR;
enc =(abs(left_data) + abs(right_data))>>1;
};
LED=(enc*i)/10+enc;
enc =0;
}
}
if(enc_numb)
{
temp=enc_numb/10;
for(i=1;i<=temp;i++)
{
begin_get_encoder();
while(enc <10)
{
Vleft=VL + delta;
Vright=VR;
enc =(abs(left_data) + abs(right_data))>>1;
};
LED=(enc*i)/10;
if(stop_sens==sflag) break;
enc =0;
}
}
stop();
}
void scanline_run_straight_enc(int max_speed,int enc_numb)
{
int enc=0;
char temp,i;
unsigned int V;
LED =3344;
temp=enc_numb/100;
for(i=1;i<=temp;i++)
{
begin_get_encoder();
while(enc <100)
{
if(V>=max_speed) V=max_speed;
V+=1;
scan_line(V);
enc =(abs(left_data) + abs(right_data))>>1;
};
LED=(enc*i)/10;
enc =0;
}
stop();
}
void curve(int VL,int VR,unsigned int enc_numb,char curve_position)
{
int enc;
unsigned int i,temp;//important here for running in long distance
char dem_so_line=0;
temp =enc_numb/100;
switch(curve_position)
{
/*********************
RED FIELD
*********************/
//tinh huong chay 1
case 0x01: //ham re phai theo y GA' Danh
Vleft=VL;
Vright=VR;
for(i=1;i<=temp;i++)
{
begin_get_encoder();
while(enc <100)
{
enc =(abs(left_data) + abs(right_data))>>1;
};
LED=(enc*i)/10;
enc =0;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -