黑白间隔点巡线思路

写在前面

2020年的电赛赛题要求我们巡一个黑白间隔的导航线
黑白间隔点巡线思路

void Detect()
{
	if(stop_flag == 0)
	{
    left_sensor = GPIO_ReadBit(P6,1);
		right_sensor = GPIO_ReadBit(P6,0);
    left_behind_sensor = GPIO_ReadBit(P1,6);
    right_behind_sensor = 0;
    
    if(right_special == 2){  //打最大角度
        encoder_integral = 1;
        if(encoder_sum > standard[theta][run_time]){  //积分值大于设定值,认为转弯结束
            encoder_sum = 0;
            encoder_integral = 2;
            right_special = 1;
        }
    }else if(right_special == 1){//开始查询前面2个灯是不是看到了黑点,看到了就正常循迹
      if(left_sensor == SBLACK || right_sensor == SBLACK){
        right_special = 0;  //正常巡线标志位
      }
    }else if(right_special == 0){
        if ( left_behind_sensor == SBLACK && !once_right_special)
        {
          right_special = 2;  //打死角
          once_right_special = 1;//只有一次最大打角
        }
        else//后半段
        {
          if((left_sensor == SBLACK || right_sensor == SBLACK) && encoder_integral == 2){
            encoder_integral = 3;
            right_special = 0;
          }    
            //&& encoder_integral == 2
          if(left_behind_sensor == SBLACK){
            if(track_line_flag == 1){
              track_line_flag = 0;
              switch_stopflag = 1;
              stop_flag = 1;   //停车
            }
          }
          if (left_sensor == SWHITE && right_sensor == SWHITE)
          {
            turn_flag = 0;  //回正
            start_turning_flag = 0; //停止转向
          }
          else if (left_sensor == SBLACK && right_sensor == SBLACK) 
          {
            turn_flag = 0;  //回正
            start_turning_flag = 0; //停止转向
          }
          if (left_sensor == SBLACK && right_sensor == SWHITE)
          {
            start_turning_flag = 1; //开始转向
            turn_flag = 1;  //左打角
          }
          else if (left_sensor == SWHITE && right_sensor == SBLACK)
          {
            start_turning_flag = 1; //开始转向
            turn_flag = 2;  //右打角
          }
        }
    }
  }
  else{
        right_special = 0;
        turn_flag = 0;  //回正
        start_turning_flag = 0; //停止转向
    
  }
}
上一篇:指静脉采集模组之获取静脉图像


下一篇:android 陀螺仪的使用