|
楼主 |
发表于 2015-1-12 16:57:55
|
显示全部楼层
#include "motor.h"
#include "uart.h"
#include "timer.h"
bit Cruising_Flag =0;
uchar Robots_Run_Status;
bit Pre_Cruising_Flag = 0;
/**电机初始化**/
void Motor_Init(void)
{
MOTOR_A_EN=1;
MOTOR_B_EN=1;
MOTOR_GO_STOP;
}
void Cruising_Mod(void)
{
if(Pre_Cruising_Flag != Cruising_Flag)//自动跟踪模式和非自动跟踪模式切换
{
if(Pre_Cruising_Flag != 0)
{
MOTOR_GO_STOP;
}
Pre_Cruising_Flag = Cruising_Flag;
}
// Cruising_Flag=1; //for test
if(1 == Cruising_Flag)
{
switch(Robots_Run_Status)
{
case 0x01:MOTOR_GO_RIGHT; break; //状态偏左
case 0x02:MOTOR_GO_LEFT; break; //状态偏右
case 0x03:MOTOR_GO_FORWARD; break; //直行状态
case 0x04:MOTOR_GO_STOP; break; //停止状态
}
if(Input_Detect1 == 1) //当人在限制距离之外
{
//人在车子正前方
if((Input_Detect0 == 0)&& (Input_Detect2 == 0))
{
Robots_Run_Status=0x03;
}
//人在车子右边
if((Input_Detect0 == 0)&& (Input_Detect2 == 1))
{
Robots_Run_Status=0x02;
}
//人在车子左边
if((Input_Detect0 == 1)&& (Input_Detect2 == 0))
{
Robots_Run_Status=0x01;
}
//目标消失
if((Input_Detect0 == 1)&& (Input_Detect2 == 1))
{
Robots_Run_Status=0x04;
}
}
else
{
Robots_Run_Status=0x04;
}
}
}
@liuviking |
|