|
回復 24# yao412030
另外一種可能就是因為斜面折射的關係,
所以比較遠的那一顆接受到近的那顆的訊號, 而且比較多,
所以,以後每次在車子轉動時你就反過來寫,
大概如下:
}else if(right && left <= 30 && right>left){ //偵測到左右方障礙物且左方距離障礙物較遠減速轉向左方
analogWrite(g_nMotor_2_Pin_B,255);
analogWrite( g_nMotor_1_Pin_A, 0);
analogWrite( g_nMotor_1_Pin_B , 120);
l = 1;
}else if (right >= 30 && right > left){ //偵測結束回復速度
analogWrite( g_nMotor_1_Pin_A, 0);
analogWrite( g_nMotor_1_Pin_B , 180);
}else if(right && left <= 30 && right<left){ //偵測到左右方障礙物且右方距離障礙物較遠減速轉向右方
analogWrite(g_nMotor_2_Pin_A,255);
analogWrite( g_nMotor_1_Pin_A, 0);
analogWrite( g_nMotor_1_Pin_B , 120);
}else if (left >= 30 && right < left){ //偵測結束回復速度
analogWrite( g_nMotor_1_Pin_A, 0);
analogWrite( g_nMotor_1_Pin_B , 180);
r = 1; |
|