; //累加
}
DL = CJ_temp1 * 100 / 400; //取4个数据取平均
for (i = 1; i < 5; i++)
{
CJ_temp2 += B; //累加
}
DR = CJ_temp2 * 100 / 400; //取4个数据取平均
}
//中断函数(如何外部中断函数中实现类似delay的功能?)
void bizhang()
{
noInterrupts();
stoprun();
right_bizhang();//小车右转
delay(1000);//转弯持续1秒
lfet_bizhang();//小车左转回复原来行驶方向
delay(1000);//同样持续1秒
stoprun();
interrupts();
}
void setup()
{
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(INA, OUTPUT);
pinMode(INB, OUTPUT);
pinMode(INC, OUTPUT);
pinMode(IND, OUTPUT);
pinMode(IN1, INPUT);
pinMode(IN2, INPUT);
attachInterrupt(0, bizhang, LOW);
}
void loop() {
//小车跟随人移动,发生中断时执行中断函数
Serial.print("gensui");
Serial.print("rn");
juliget();//一下三句用来获得车与人之间距离,利用三角定位跟踪
paixu();
JL();
while ((DL >= 0.0 && DL < 250.0 ) || (DL >= 0.0 && DL < 250.0 ))
{
juliget();
paixu();
JL();
Serial.print("************rn");
Serial.print("cm_L:");
Serial.print(DL);
Serial.print("cm ");
Serial.print("cm_R:");
Serial.print(DR);
Serial.print("cm");
Serial.println();
if (abs(DL - 50.0) < 3.5 && abs(DR - 50.0) < 3.5)
{
stoprun();
}
if ((abs(DL - DR) < 3.5) && DL > 150.0)
{
gogo();
delay(300);
//stoprun();
}
if ((abs(DL - DR ) < 3.5) && DL > 50.0 && DL < 150.0)
{
go();
delay(300);
//stoprun();
}
if ((abs(DL - DR) < 3.5) && DL < 50.0)
{
stoprun();
}
if ((DL - DR) > 3.5)
{
if (DL < 50.0 || DR < 50.0 && DR != 0)
{
stoprun();;
}
if (DR == 0 && DL > 50.0)
{
left();
delay(200);
stoprun();
}
if (DL > 50.0 && DR > 50.0)
{
right();
delay(200);
stoprun();
}
}
if ((DR - DL) > 3.5)
{
if (DL < 50.0 || (DR < 50.0 && DL != 0))
{
stoprun();
}
if (DL == 0 && DR > 50.0)
{
right();
delay(200);
stoprun();
}
if (DL > 50.0 && DR > 50.0)
{
left();
delay(200);
stoprun();
}
}
}
stoprun();
// goto ss;
}[/kenrobot_code]
最后
以上就是阳光小虾米最近收集整理的关于matlab中类似于delay功能的模块,求助,如何外部中断函数中实现类似delay的功能?...的全部内容,更多相关matlab中类似于delay功能内容请搜索靠谱客的其他文章。
发表评论 取消回复