stm32f103c8t6电磁循迹智能四轮车组程序代码

所用到的硬件:
stm32f103c8t6,舵机,电机,L298N驱动模块,OLED,电磁杆,干簧管,基础四轮车模。

所用到软件:
PID算法,ADC多路采集配置DMA,OLED驱动程序,环岛处理,普通GPIO口

部分核心控制代码如下:

if (sum >= 2800 && a == 1 && L_value_shuzhi < R_vlaue_shuzhi)
	{
		TIM1->CCR3 = 180;
		HAL_Delay(800);
		a = 2;
	}
	if(sum >= 3600 && a == 2 && z == 1)
	{
		TIM1->CCR3 = 115;
		HAL_Delay(500);
		TIM1->CCR3 = 143;
		HAL_Delay(700);
		a = 0;
	}
	if(EP_H <= 1500 && EP_H >= 600 && sum >= 4500 && a == 0)
	{
		return PWM = 0;
		HAL_Delay(2500);
		if(EP_H <= 1600 && EP_H >= 1250 && sum <= 6200 && sum >= 5400)
		{
			return PWM = 99;
		  HAL_Delay(1800);
			a = 1;
		}
	}
	if(EP_H <= 1500 && EP_H >= 600 && sum >= 4500 && a == 1)
	{
		return PWM = 0;
		HAL_Delay(1000);//	if(L_value_shuzhi >= 900 && L_value <= 1800)      
		{
			return PWM = 180;
			HAL_Delay(800);
			a = 0;
		}
	}
	if(EP_H >= -1500 && EP_H <= -600 && sum >= 4500 && k == 0)
	{
		return PWM = 0;
		HAL_Delay(2500);
		if(EP_H >= -1600 && EP_H <= -1250 && sum <= 6200 && sum >= 5400)
		{
			return PWM = 99;
			HAL_Delay(1800);
			k = 1;
		}
	}
	if(EP_H >= -1500 && EP_H <= -600 && sum >= 4500 && k == 1)
	{
		return PWM = 0;
		HAL_Delay(1000);
		if(R_vlaue_shuzhi >= 900 && R_value <= 1800)
		{
			return PWM = 180;
			HAL_Delay(800);
			k = 0;
		}
	}
	#endif
	
	return PWM;
}

uint16_t ad(uint16_t i)//封装ADC采集值
{
	HAL_ADCEx_Calibration_Start(&hadc1 );
	HAL_ADC_Start_DMA (&hadc1 ,(uint32_t *)adcbuf,5);	
	return adcbuf[i];
}
uint16_t adc(uint16_t j)   //采集值进行简单滤波
{
	uint16_t last_value,value,err;
	
	value = ad(j);
	if ( ( last_value - value > A ) || ( value - last_value > A ))
	{
		err = last_value;
	}
	else
	{
		err = value;
	}
	last_value = value;

	return err;
}

uint16_t AD(uint16_t k)  //算数平均滤波
{
	char count = 0;
	float sum = 0,x;
	
	for (count=0;count

stm32f103c8t6电磁循迹智能四轮车组程序代码_第1张图片

 stm32f103c8t6电磁循迹智能四轮车组程序代码_第2张图片

 

https://download.csdn.net/download/weixin_60445475/85094527icon-default.png?t=M276https://download.csdn.net/download/weixin_60445475/85094527

你可能感兴趣的:(stm32,人工智能,单片机)