代码解析
find.c
#include "find.h"
#include "Moto.h"
extern TIM_HandleTypeDef htim3;
/*
函数功能:调节小车左右电机PWM
Left:左电机PWM
Right:右电机PWM
*/
void Moto_speed_set(int Left,int Right)
{
__HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_3, Right);
__HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_4, Left);
}
/*
函数功能:循迹
*/
void Find(void)
{
//全是白线前进
if((IO1_read()==0)&&(IO2_read()==0)&&(IO3_read()==0)&&(IO4_read()==0))
{
Moto_speed_set(800,800);
car_move(0);
}
//右边有黑线小车向左即左轮加速右轮减速
else if((IO1_read()==0)&&(IO2_read()==1)&&(IO3_read()==0)&&(IO4_read()==0))
{
Moto_speed_set(800,0);
car_move(0);
}
//右边有黑线小车向左即左轮加速右轮减速
else if((IO1_read()==1)&&(IO2_read()==1)&&(IO3_read()==0)&&(IO4_read()==0))
{
Moto_speed_set(800,0);
car_move(0);
}
//右边有黑线小车向左即左轮加速右轮减速
else if((IO1_read()==1)&&(IO2_read()==0)&&(IO3_read()==0)&&(IO4_read()==0))
{
Moto_speed_set(800,0);
car_move(0);
}
//左边有黑线小车向右即右轮加速左轮减速
else if((IO1_read()==0)&&(IO2_read()==0)&&(IO3_read()==1)&&(IO4_read()==0))
{
Moto_speed_set(0,800);
car_move(0);
}
//左边有黑线小车向右即右轮加速左轮减速
else if((IO1_read()==0)&&(IO2_read()==0)&&(IO3_read()==1)&&(IO4_read()==1))
{
Moto_speed_set(0,800);
car_move(0);
}
//左边有黑线小车向右即右轮加速左轮减速
else if((IO1_read()==0)&&(IO2_read()==0)&&(IO3_read()==0)&&(IO4_read()==1))
{
Moto_speed_set(0,800);
car_move(0);
}
//全是黑线停车
if((IO1_read()==1)&&(IO2_read()==1)&&(IO3_read()==1)&&(IO4_read()==1))
{
Moto_speed_set(0,0);
car_move(2);
}
}
|