使用STM32F1系列芯片,尋仙模塊采用光電對管,使用PID算法調節占空比,輸出不同的PWM波,差速尋線
單片機源程序如下:
- # include "stm32f10x.h"
- # include "public.h"
- volatile uint32_t time = 0; // ms 計時變量
- int Shut = 3 ; //停車判斷
- int k = 30000 ;
- int Ultrasonic_Sing = 1 ;
- int main(void)
- {
- Period = 1600 ; //給定占空比,調節初始速度
- trackingCarInitialization() ; //初始化函數
- PID_Set(&PID_Tracking_The_Car,45,280,10);//PID參數設置
- Ultrasonic_Star() ; //超聲波啟動
- while(k--)
- {
- Motor_PID_Control() ;
- }
- k = 30000 ;
- while(1)
- {
- if(time>=300) /*********超聲波定時測距 300*(1ms)=0.3s ***********/
- {
- Ultrasonic_Length=Hcsr04GetLength();
- time = 0 ;
- }
- Motor_PID_Control() ; // PID調節控制小車轉速
- if(ShutDown<2)
- {
- Shut-- ;
- if(Shut==0)
- {
- goto ShutDown_The_Car ;
- }
- while(k--)
- {
- Motor_PID_Control() ;
- }
- }
- k=30000;
-
- Trans_Isand_Runing() ;//環島
- gotoAquare_Bent() ; //過直角彎道
- }
- ShutDown_The_Car:
- TIM_SetCompare2(TIMx,0);//左側控制
- TIM_SetCompare1(TIMx,0);//右側控制
- return 0;
- }
-
復制代碼
所有資料51hei提供下載:
Tracking The Car.rar
(286.56 KB, 下載次數: 129)
2018-10-22 21:45 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|