void Judge_Black_Line_Status(void)
{
u8 i;
u8 numb=0;
u8 position[8];
for(i=0;i<8;i++)
{
if(track_data[i]>track_data_range*0.3) black_line_status[i]=0;
else black_line_status[i]=1;
}
for(i=0;i<8;i++)
{
if(black_line_status[i])
{
position[numb]=i;
numb++;
}
}
if(numb>3)
{
black_line_valid=0;
black_horizontal_line_flag=1;
}
else black_horizontal_line_flag=0;
if(numb==0)
{
lost_black_line_flag=1;
}
else lost_black_line_flag=0;
if(numb==1 || \
(numb==2 && position[0]+1==position[1]) || \
(numb==3 && position[0]+1==position[1] && position[1]+1==position[2]))
{
black_line_valid=1;
}
else black_line_valid=0;
}
void Track_Data_Normalization(void)
{
u8 i;
for(i=0;i<8;i++)
{
if(adc_data_fliter[i]>track_data_max[i]) track_data[i]=100;
else if(adc_data_fliter[i]<track_data_min[i]) track_data[i]=0;
else track_data[i]=(adc_data_fliter[i]-track_data_min[i])*track_data_range/(track_data_max[i]-track_data_min[i]);
}
}
float Difference_Divide_Sum(void)
{
float difference,sum;
difference=4*track_data[0]+3*track_data[1]+2*track_data[2]+track_data[3] \
-track_data[4]-2*track_data[5]-3*track_data[6]-4*track_data[7];
sum=track_data[0]+track_data[1]+track_data[2]+track_data[3] \
+track_data[4]+track_data[5]+track_data[6]+track_data[7];
if(sum) difference=100*difference/sum;
else difference=0;
if(difference>100) difference=100;
else if(difference<-100) difference=-100;
return (difference);
}
float Half_Black_Line_Error(void)
{
u8 i;
for(i=0;i<4;i++)
{
if(black_line_status[i]) break;
}
return ((4-i)-1)*9;
}