|
发表于 2011-11-29 23:20:22
|
显示全部楼层
#define NEAR 20 // 预设距离为20cm
//右后退
void goBackRight()
{
OnRev(OUT_B,100);
Wait(800);
Off(OUT_B);
}
//左后退
void goBackLeft()
{
OnRev(OUT_C,100);
Wait(800);
Off(OUT_C);
}
//向后
void goBack()
{
//OnRev(OUT_BC,100);
OnRevReg(OUT_BC,100,OUT_REGMODE_SPEED);
Wait(800);
Off(OUT_BC);
}
//自动往一个方向转弯
void autoTrunOff(){
SetSensorLowspeed(IN_1); //超声波A
SetSensorLowspeed(IN_2); //超声波B
while(true){
OnFwd(OUT_BC, 60);
while(SensorUS(IN_1) > NEAR && SensorUS(IN_2) > NEAR);
Off(OUT_BC);
int r = 0;
if(SensorUS(IN_1) <= NEAR && SensorUS(IN_2) > NEAR) {
goBackRight(); //向右后方
}else if(SensorUS(IN_1) > NEAR && SensorUS(IN_2) <= NEAR){
goBackLeft(); //向左后方
} else{
goBack(); //向后
}
Wait(500);
}
}
task main()
{
autoTrunOff() ;
}
基本就是这个样子我没调试接线按照8547的纸质教程上的接 |
|